Question

I'm running android version 4.1.2 on a Samsung galaxy SII. I've recently started working with the UIAutomator to test my user interface. The problem is that everytime I try to run the test on the phone I get NoSuchMethodError on the method setAsHorizontalList() used on an UIScrollable object. Eclipse does recognize the method and it doesn't give a compile error.

    private void turnOffNetwork() throws UiObjectNotFoundException {
        getUiDevice().pressHome();

        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));
        appViews.setAsHorizontalList();
        UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Instellingen");

        settingsApp.clickAndWaitForNewWindow();

        UiObject switchObject = new UiObject(new UiSelector().className(android.widget.Switch.class.getName()));

        if (switchObject.isChecked()) {
            switchObject.click();
        }
    }
Était-ce utile?

La solution

unfortunately, the setAsHorizontalList() function can only work on 4.2.2 (API 17) device, not on API 16, you can try it on the emulator or a tablet with API 17. I learnt it the hard way a few days ago

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top