@Override
  public Result execute(Map<String, Object> arguments) throws UiObjectNotFoundException {
    super.execute(arguments);
    @SuppressWarnings("unchecked")
    List<String> optionNames = (List<String>) arguments.get("optionNames");
    ;
    UiScrollable optionsMenu =
        new UiScrollable(
            new UiSelector()
                .className("android.widget.ListView")
                .packageName("com.android.settings")
                .focused(false));

    if (!isUiObjectAvailable(optionsMenu, arguments)) {
      return Result.FAILURE;
    }

    for (String optionName : optionNames) {
      UiObject option =
          optionsMenu.getChildByText(
              new UiSelector().className(TextView.class.getName()), optionName);
      if (!isUiObjectAvailable(option, arguments) && !enabled.equals(option.isEnabled())) {
        return Result.FAILURE;
      }
    }
    return Result.OK;
  }
  public void testDemo() throws UiObjectNotFoundException {

    // Simulate a short press on the HOME button.
    getUiDevice().pressHome();

    // We’re now in the home screen. Next, we want to simulate
    // a user bringing up the All Apps screen.
    // If you use the uiautomatorviewer tool to capture a snapshot
    // of the Home screen, notice that the All Apps button’s
    // content-description property has the value “Apps”.  We can
    // use this property to create a UiSelector to find the button.
    UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));

    // Simulate a click to bring up the All Apps screen.
    allAppsButton.clickAndWaitForNewWindow();

    // In the All Apps screen, the Settings app is located in
    // the Apps tab. To simulate the user bringing up the Apps tab,
    // we create a UiSelector to find a tab with the text
    // label “Apps”.
    UiObject appsTab = new UiObject(new UiSelector().text("Apps"));

    // Simulate a click to enter the Apps tab.
    appsTab.click();

    // Next, in the apps tabs, we can simulate a user swiping until
    // they come to the Settings app icon.  Since the container view
    // is scrollable, we can use a UiScrollable object.
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));

    // Set the swiping mode to horizontal (the default is vertical)
    appViews.setAsHorizontalList();

    // Create a UiSelector to find the Settings app and simulate
    // a user click to launch the app.
    UiObject settingsApp =
        appViews.getChildByText(
            new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
    settingsApp.clickAndWaitForNewWindow();

    // Validate that the package name is the expected one
    UiObject settingsValidation =
        new UiObject(new UiSelector().packageName("com.android.settings"));
    assertTrue("Unable to detect Settings", settingsValidation.exists());
  }
Exemplo n.º 3
0
  public void testLogin() throws UiObjectNotFoundException {
    UiObject validation = new UiObject(new UiSelector().packageName("com.jingdong.app.mall"));
    assertTrue(validation.waitForExists(5000));

    UiScrollable pager =
        new UiScrollable(new UiSelector().resourceId("com.jingdong.app.mall:id/viewpager"));
    if (pager.waitForExists(3000)) {
      pager.setAsHorizontalList();
      pager.scrollToEnd(4);

      UiObject startup =
          new UiObject(new UiSelector().resourceId("com.jingdong.app.mall:id/btn_experience"));
      startup.click();
    }

    UiObject my =
        new UiObject(
            new UiSelector()
                .resourceId("com.jingdong.app.mall:id/bottomMenu")
                .childSelector(new UiSelector().className(RadioButton.class).index(4)));
    my.waitForExists(8000);
    my.click();
    my.click();

    UiObject login =
        new UiObject(
            new UiSelector().resourceId("com.jingdong.app.mall:id/personal_click_for_login"));
    login.clickAndWaitForNewWindow();

    UiObject username =
        new UiObject(new UiSelector().resourceId("com.jingdong.app.mall:id/login_input_name"));
    username.setText("18824238317");
    UiObject password =
        new UiObject(new UiSelector().resourceId("com.jingdong.app.mall:id/login_input_password"));
    password.setText("ztemt123");
    UiObject loginbtn =
        new UiObject(new UiSelector().resourceId("com.jingdong.app.mall:id/login_comfirm_button"));
    loginbtn.click();
  }
Exemplo n.º 4
0
  public void testLogin() throws UiObjectNotFoundException {
    UiObject validation = new UiObject(new UiSelector().packageName("com.chaozh.iReader"));
    assertTrue(validation.waitForExists(5000));

    UiObject confirm =
        new UiObject(
            new UiSelector().resourceId("com.chaozh.iReader:id/defualt_compoundButton").text("确定"));
    if (confirm.waitForExists(3000)) {
      confirm.click();
    }

    UiScrollable pager =
        new UiScrollable(new UiSelector().resourceId("com.chaozh.iReader:id/viewpager"));
    if (pager.exists()) {
      pager.setAsHorizontalList();
      pager.scrollToEnd(1);

      UiObject startup =
          new UiObject(new UiSelector().resourceId("com.chaozh.iReader:id/btn_start"));
      startup.click();
    }

    UiObject center =
        new UiObject(new UiSelector().resourceId("com.chaozh.iReader:id/bookShelf_head_Center_ID"));
    center.click();
    center.click();

    UiObject left =
        new UiObject(new UiSelector().resourceId("com.chaozh.iReader:id/bookShelf_head_left_ID"));
    left.click();

    UiObject login =
        new UiObject(new UiSelector().resourceId("com.chaozh.iReader:id/person_longin"));
    login.clickAndWaitForNewWindow();

    UiObject ireader =
        new UiObject(
            new UiSelector()
                .resourceId("com.chaozh.iReader:id/account_main_thirdlogin")
                .childSelector(
                    new UiSelector()
                        .index(0)
                        .childSelector(
                            new UiSelector()
                                .index(1)
                                .childSelector(
                                    new UiSelector()
                                        .index(1)
                                        .childSelector(new UiSelector().index(0))))));
    ireader.clickAndWaitForNewWindow();

    UiObject username =
        new UiObject(
            new UiSelector()
                .resourceId("com.chaozh.iReader:id/account_block_zhangyueid_login_name"));
    username.setText("18824238317");
    UiObject password =
        new UiObject(
            new UiSelector()
                .resourceId("com.chaozh.iReader:id/account_block_zhangyueid_login_password"));
    password.setText("ztemt123");
    UiObject loginbtn =
        new UiObject(
            new UiSelector()
                .resourceId("com.chaozh.iReader:id/account_block_zhangyueid_login_submit"));
    loginbtn.click();
  }
  public void testDemo() throws UiObjectNotFoundException, InterruptedException {

    // Simulate a short press on the HOME button.
    getUiDevice().pressHome();

    // We’re now in the home screen. Next, we want to simulate
    // a user bringing up the All Apps screen.
    // If you use the uiautomatorviewer tool to capture a snapshot
    // of the Home screen, notice that the All Apps button’s
    // content-description property has the value “Apps”. We can
    // use this property to create a UiSelector to find the button.
    UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));

    // Simulate a click to bring up the All Apps screen.
    allAppsButton.clickAndWaitForNewWindow();

    Thread.sleep(2000);

    // In the All Apps screen, the Settings app is located in
    // the Apps tab. To simulate the user bringing up the Apps tab,
    // we create a UiSelector to find a tab with the text
    // label “Apps”.
    UiObject appsTab = new UiObject(new UiSelector().text("Apps"));

    // Simulate a click to enter the Apps tab.
    appsTab.click();
    // SystemClock.sleep(2000);

    // Next, in the apps tabs, we can simulate a user swiping until
    // they come to the Settings app icon. Since the container view
    // is scrollable, we can use a UiScrollable object.
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));

    // Set the swiping mode to horizontal (the default is vertical)
    appViews.setAsHorizontalList();

    // Create a UiSelector to find the Netflix app and simulate
    // a user click to launch the app.
    UiObject netflixApp =
        appViews.getChildByText(
            new UiSelector().className(android.widget.TextView.class.getName()), "Netflix");
    netflixApp.clickAndWaitForNewWindow();
    SystemClock.sleep(3000);

    // create a virtual hand to click
    UiDevice handClick = UiDevice.getInstance();

    // click the menu and "Comedies"
    handClick.click(20, 95);
    SystemClock.sleep(1500);
    handClick.click(300, 650);

    // enter the first movie in this page
    SystemClock.sleep(1000);
    handClick.click(150, 450);
    SystemClock.sleep(3000);
    for (int i = 0; i < 2; i++) { // the loop of we want to play
      // print out which loop now
      int counti = i + 1;
      System.out.println("the number of the loop is " + counti);

      // start play the movie
      handClick.click(400, 350);
      System.out.println("start play the movie 1 " + counti);
      SystemClock.sleep(10000);
      System.out.println("start play the movie 2 " + counti);

      // do some operation

      handClick.click(500, 500);
      SystemClock.sleep(20000);
      handClick.click(500, 500);
      SystemClock.sleep(1000);
      for (int j = 0; j < 10; j++) {
        int countj = j + 1;
        handClick.click(150, 675); // 10 sec seek, 10 times
        SystemClock.sleep(2000);
        System.out.println("sec seek " + countj);
      }
      handClick.click(750, 685); // normal seek
      SystemClock.sleep(2000);
      System.out.println("normal seek 1 " + counti);
      handClick.click(450, 685); // normal seek
      SystemClock.sleep(2000);
      System.out.println("normal seek 2 " + counti);
      handClick.click(590, 685); // normal seek
      SystemClock.sleep(2000);
      System.out.println("normal seek 3 " + counti);
      SystemClock.sleep(7000); // let is play 5000 ms
      System.out.println("playing" + counti);

      // back
      handClick.click(500, 500);
      SystemClock.sleep(100);
      getUiDevice().pressBack();
      SystemClock.sleep(150);

      // add the movie in MyList
      handClick.click(550, 730);
      SystemClock.sleep(1000);

      // drag the menu and enter the next movie
      handClick.drag(16, 1025, 16, 185, 80);
      SystemClock.sleep(200);
      handClick.click(350, 1050);
    }
    // back and over
    // getUiDevice().pressHome();
    handClick.click(20, 95);
    SystemClock.sleep(200);
    getUiDevice().pressBack();
    System.out.println("The test is over");

    // Validate that the package name is the expected one
    UiObject settingsValidation =
        new UiObject(new UiSelector().packageName("com.netflix.mediaclient"));
    assertTrue("Unable to detect Settings", settingsValidation.exists());
  }