1
    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 >runtest LaunchAppByName.jar -c >com.motorola.launchappbyname.LaunchAppByName#testAppByName -e String Clock 我收到错误 it.framework.AssertionFailedError :找不到方法“testAppByName”

4

3 回答 3

6

To pass params to the test case, the uiautomator says:

-e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
    May be repeated.

for example you can do something like this:

adb shell uiautomator runtest UiTest.jar -c package.name.ClassName -e stringKey stringValue

in the code you can use

String stringValue = getParams().getString("stringKey");

the getString('key') will return what ever you wrote as stringValue

于 2014-03-11T15:14:03.880 回答
1

要使用 adb 命令提供的附加功能,请修改您的函数,如下所示,

public void testAppByName() {
  getParams().getString("appName");
}
于 2014-02-28T07:08:56.747 回答
0

为了传递多个参数,您可以使用

adb shell uiautomator runtest UiTest.jar -c package.name.ClassName -e stringKey1 stringValue -e stringKey2 stringValue -e stringKey3 stringValue
于 2014-08-12T18:53:17.060 回答