线上班第六期_Appium 高级进阶_20180623

Toast



public class TestToast {

    private static AndroidDriver<AndroidElement> driver;

    @BeforeClass
    public static void beforeApi() throws MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName", "iPhone 6");
        capabilities.setCapability("appPackage", "io.appium.android.apis");
        capabilities.setCapability("appActivity", ".ApiDemos");
        capabilities.setCapability("automationName", "uiautomator2");
        //capabilities.setCapability("recreateChromeDriverSessions", "true");
        capabilities.setCapability("noReset", true);
        capabilities.setCapability("fullReset", false);
        capabilities.setCapability("showChromedriverLog", true);
        //capabilities.setCapability("dontStopAppOnReset", true);
        driver=new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }


    @Test
    public void pageSource() throws InterruptedException {
        driver.findElementByAccessibilityId("Views").click();
        driver.findElementByAndroidUIAutomator(
                "new UiScrollable(new UiSelector()).scrollIntoView("
                + "new UiSelector().text(\\"Popup Menu\\"));").click();
        driver.findElementByAccessibilityId("Make a Popup!").click();
        driver.findElementByXPath("//android.widget.TextView[@text='Add']").click();
        for(int i=0;i<5;i++){
            System.out.println(driver.getPageSource());
            System.out.println("toast");
            System.out.println(driver.findElementByXPath("//*[@class='android.widget.Toast']").getText());
        }


    }
}