Exemplo n.º 1
0
  public static void main(String[] args) throws MalformedURLException {
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability("platformName", "android");
    cap.setCapability("app", "e:/example.apk");
    cap.setCapability("unicodeKeyboard", "true");
    cap.setCapability("resetKeyboard", "true");
    //        cap.setCapability("deviceName", "huawei-plk_ul00-W8R0215813002079");
    cap.setCapability("deviceName", "192.168.120.91:5555");

    AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    driver.findElementByAndroidUIAutomator("new UiSelector().text(\"排行榜\")").click();

    //        根据父元素获取同级元素
    driver
        .findElementByAndroidUIAutomator(
            "new UiSelector().text(\"排行榜\")." + "fromParent(new UiSelector().text(\"应用\"))")
        .click();

    //        获取子元素
    driver
        .findElementByAndroidUIAutomator(
            "new UiSelector().resourceId(\"com.wandoujia.phoenix2:id/tab_host\")"
                + ".childSelector(new UiSelector().className(\"android.widget.TextView\").text(\"游戏\"))")
        .click();

    driver
        .findElementByAndroidUIAutomator(
            "new UiSelector().resourceId(\"com.wandoujia.phoenix2:id/search_image\")")
        .click();

    driver.navigate().back();

    driver
        .findElementByAndroidUIAutomator(
            "new UiSelector().resourceId(\"com.wandoujia.phoenix2:id/search_box_close\")")
        .click();
    driver
        .findElementByAndroidUIAutomator(
            "new UiSelector().resourceId(\"com.wandoujia.phoenix2:id/search_box_edit\")")
        .sendKeys("腾讯新闻");
    driver
        .findElementByAndroidUIAutomator(
            "new UiSelector().resourceId(\"com.wandoujia.phoenix2:id/search_button\")")
        .click();
    WebElement ele =
        (WebElement)
            driver
                .findElementsByAndroidUIAutomator(
                    "new UiSelector()" + ".className(\"android.widget.TextView\").text(\"安装\")")
                .get(0);
    ele.click();
    driver.openNotifications();
    driver.quit();
  }
  @Test
  public void G_sharing() {
    // driver.findElement(By.name("Gallery")).click();
    // List<WebElement> editBox=driver.findElements(By.className("android.widget.TextView"));
    // editBox.get(3).click();
    List<WebElement> collection1 =
        driver.findElements(By.className("android.view.View")); // Taping on Collection folder
    collection1.get(5).click();
    driver.findElement(By.xpath("//*[@class='android.view.View' and @index='2']")).click();

    // TouchAction tActionn=new TouchAction(driver); //Tap function
    // tActionn.tap(150,301).release().perform();
    driver.findElementByAccessibilityId("Share").click();
    driver.navigate().back();
    driver.findElement(By.id("com.mimedia.gallery:id/gallery_action_bar_nav_icon")).click();
  }
  @Test
  public void D_camera() {

    // driver.findElement(By.name("Gallery")).click();

    driver.findElementByAccessibilityId("Camera").click();
    WebDriver augmentedDriver = new Augmenter().augment(driver); // Landscape orientation
    ((Rotatable) augmentedDriver).rotate(ScreenOrientation.LANDSCAPE); // Landscape orientation

    driver.findElement(By.id("com.android.camera2:id/second_shutter_button")).click();

    driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click();
    driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click();

    WebDriver augmentedDriver1 = new Augmenter().augment(driver); // Landscape orientation
    ((Rotatable) augmentedDriver1).rotate(ScreenOrientation.PORTRAIT);
    {
      driver.findElement(By.id("com.android.camera2:id/second_shutter_button")).click();
    }
    driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click();
    driver.findElement(By.id("com.android.camera2:id/third_shutter_button")).click();
    driver.navigate().back();
  }