我使用 uiautomator 在 java 中为 Android 开发了移动自动化项目
。
我已遵循以下所有步骤:-
- 创建 jar
- 将 jar 推送到设备
- 最后运行测试用例
我需要使用用户名
和密码
自动执行登录功能。我创建了用于读取用户名和密码的 Excel 文件,例如 selenium
。
但是当我访问这个 Excel 文件时,它给出了 File Not Found 异常。
adb shell uiautomator runtest /sdcard/myApp.jar -c com.example.LoginTest
有没有办法访问 uiautomator 中的其他文件?
最佳答案
UIAutomator
作为进程在shell
内部运行,因此我们无法访问在PC上运行的excel文件
但是,有两种方法可以使其自动化:
1.编写一个脚本来解析Excel工作表并将其设置为虚拟系统属性,使用UIAutomator读取相同的内容
//set android dummy property using script
adb shell setprop dummy value
//Read Value of property in UIAutomator
getProperty("dummy");
//Subroutine for Reading Property from Android
public String getProperty(String propName) {
String propValue = null;
try {
propValue = (String) Class.forName("android.os.SystemProperties").getMethod("get", new Class[] { String.class }).invoke(null, propName);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return propValue;
}
2.将值写入文本文件并在 UIAutomator 类中用 Java 解析它
关于java - 安卓 : External file in uiautomator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27182337/