UiScrollable在UiAutomator中不起作用

时间:2016-01-25 15:58:52

标签: android automated-tests uiautomator

我是UIautomator的新手,需要从Apps中选择“设置”。 这是演示提供的代码:

 package Test;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class LaunchSettings extends       UiAutomatorTestCase {
public void testDemo() throws     UiObjectNotFoundException {

getUiDevice().pressHome();

UiObject allAppsButton = new UiObject(new       UiSelector().description("Apps"));

UiObject appsTab = new UiObject(new   UiSelector().text("Apps"));
appsTab.click();

UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));

              appViews.setAsHorizontalList();

UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
settingsApp.clickAndWaitForNewWindow();
UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.settings"));
assertTrue("Unable to detect Settings",    settingsValidation.exists());
    }
}

执行此操作时,它进入“App”并且什么都不做,错误代码如下:

Error report image

INSTRUMENTATION_STATUS: test=testDemo
INSTRUMENTATION_STATUS_CODE: -1
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.E
Time: 19.974

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

如果有人能够指出我做错了什么,我将不胜感激,这是我的第一次,非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我认为" Apps"中没有可滚动的视图。标签。因此,您只需启动这样的设置菜单。

    Context context = InstrumentationRegistry.getContext();
    final Intent intent = new Intent(Settings.ACTION_SETTINGS);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

    mDevice.wait(Until.hasObject(By.pkg(Settings.ACTION_SETTINGS).depth(0)), 5000);