public void testAppByName(String appName) throws UiObjectNotFoundException {
screenUnlocker();
// String appName = "Clock";
UiObject allAppsButton = new UiObject(
new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
appsTab.click();
UiScrollable appViews = new UiScrollable(
new UiSelector().scrollable(true));
UiObject appLaunch = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), appName);
appLaunch.clickAndWaitForNewWindow();
}
如何使用uiautomator runtest命令为方法提供值 我尝试执行以下命令adb shell uiautomator&gt; runtest LaunchAppByName.jar -c&gt; com.motorola.launchappbyname.LaunchAppByName#testAppByName -e String Clock我收到错误it.framework.AssertionFailedError:方法“testAppByName”未找到< / p>
答案 0 :(得分:6)
为了将params传递给测试用例,uiautomator说:
-e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
May be repeated.
例如,您可以执行以下操作:
adb shell uiautomator runtest UiTest.jar -c package.name.ClassName -e stringKey stringValue
在您可以使用的代码中
String stringValue = getParams().getString("stringKey");
getString('key')
将返回您写为stringValue
答案 1 :(得分:1)
要使用adb命令提供的额外功能, 修改你的功能如下,
public void testAppByName() {
getParams().getString("appName");
}
答案 2 :(得分:0)
为了传递多个参数,您可以使用
adb shell uiautomator runtest UiTest.jar -c package.name.ClassName -e stringKey1 stringValue -e stringKey2 stringValue -e stringKey3 stringValue