java - 安卓 : External file in uiautomator

标签 java android-testing android-uiautomator

我使用 uiautomator 在 java 中为 Android 开发了移动自动化项目

我已遵循以下所有步骤:-

  1. 创建 jar
  2. 将 jar 推送到设备
  3. 最后运行测试用例

我需要使用用户名密码自动执行登录功能。我创建了用于读取用户名和密码的 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/

相关文章:

java - 通过 spring 初始化一个集合

java - 在 AndroidJunit 测试项目中运行 UiAutomatorTestcase

android - Espresso 如何搜索文本,如果显示文本,请单击它,否则继续测试

android - 移动应用性能测试工具

android - 在 UiAutomator 测试中检测或抑制键盘

android - 如何在 UI Automator 中长按时检查 UI 对象

java - 链表清除方法

java - 使用 Gson 显示枚举及其属性的映射

java - 使用alternatedocroot时无法通过glassfish访问外部资源

安卓 Espresso : Testing Preferences (multiple ListViews)