【问题标题】:UiScrollable not working in UiAutomatorUiScrollable 在 UiAutomator 中不起作用
【发布时间】:2016-01-25 15:58:51
【问题描述】:

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

 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

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

【问题讨论】:

  • 你能显示第 58 行是什么吗?
  • 其:UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Settings"); settingsApp.clickAndWaitForNewWindow();

标签: android automated-tests android-uiautomator


【解决方案1】:

我认为“应用程序”选项卡中没有可滚动的视图。因此,您只需像这样启动设置菜单。

    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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多