Example #1
0
  @When("^I start the program$")
  public void I_start_the_program() throws InterruptedException {
    programWaitLock = new Semaphore(programWaitLockPermits);
    addScriptEndCallbacks();

    Solo solo = (Solo) Cucumber.get(Cucumber.KEY_SOLO);
    assertEquals(
        "I am in the wrong Activity.",
        MainMenuActivity.class,
        solo.getCurrentActivity().getClass());
    solo.clickOnView(solo.getView(org.catrobat.catroid.R.id.main_menu_button_continue));
    solo.waitForActivity(ProjectActivity.class.getSimpleName(), 3000);
    assertEquals(
        "I am in the wrong Activity.", ProjectActivity.class, solo.getCurrentActivity().getClass());
    solo.clickOnView(solo.getView(org.catrobat.catroid.R.id.button_play));
    solo.waitForActivity(StageActivity.class.getSimpleName(), 3000);
    assertEquals(
        "I am in the wrong Activity.", StageActivity.class, solo.getCurrentActivity().getClass());

    synchronized (programStartWaitLock) {
      if (!programHasStarted) {
        programStartWaitLock.wait(10000);
      }
    }
  }
Example #2
0
  public void testRestartButtonActivityChain() throws NameNotFoundException, IOException {
    createAndSaveTestProject(testProject);
    solo.clickOnButton(getActivity().getString(R.string.my_projects));
    solo.waitForActivity(MyProjectsActivity.class.getSimpleName());
    solo.waitForFragmentById(R.id.fr_projects_list);
    assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject));
    solo.waitForActivity(ProjectActivity.class.getSimpleName());

    Activity currentActivity = solo.getCurrentActivity();

    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.goBack();
    solo.sleep(100);
    solo.clickOnButton(getActivity().getString(R.string.restart_current_project));
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.assertCurrentActivity("Program is not in stage activity", StageActivity.class);

    solo.sleep(500);
    solo.goBack();
    solo.sleep(100);
    solo.clickOnButton(getActivity().getString(R.string.back));
    solo.waitForActivity(ProjectActivity.class.getSimpleName());
    assertEquals("Returned to wrong Activity", currentActivity, solo.getCurrentActivity());
  }
  public void testBrowseHouseTest() {
    try {
      Report.setTCNameLog(testName);
      // 如果打开应用后弹出“是否打开定位功能”的提示,选择“取消”
      if (solo.searchText("提示")) {
        solo.clickOnButton(1);
      }
      if (solo.searchText("刷新")) {
        solo.clickOnText("刷新");
      }

      //			Action.wait(solo, R.id.view_list_item_tv_title, count, "等待详细房源类表加载成功");
      //			Report.writeHTMLLog("安居客浏览房源用例", "附近页房源列表显示完全",Report.DONE,"");

      // 如果当前城市不是上海,就切换至上海
      Action.switchCity(solo, "上海");
      solo.clickOnText("搜索");
      Action.scroolUpPage(solo, "浏览房源");
      solo.clickOnText(bureau);
      solo.clickOnText(area);
      Report.writeHTMLLog("安居客浏览房源用例", "选中区域".concat(bureau).concat(area), Report.DONE, "");

      Action.wait(solo, R.id.view_list_item_tv_title, count, "等待房源列表信息显示成功");
      solo.clickOnView(solo.getView(R.id.view_list_item_tv_title));
      solo.waitForText("收藏");
      String houseTitle =
          (String) ((TextView) solo.getCurrentActivity().findViewById(R.id.prop_title)).getText();
      Report.writeHTMLLog(
          "安居客浏览房源用例", "房源列表第一套房源标题为:" + houseTitle, "Done", Action.screenShot(solo));

      // 点击返回按钮
      Action.clickById(solo, R.id.detail_back_button, "点击返回按钮");

      // 点击”更多"tab
      solo.clickOnText("我的");
      solo.clickOnText("浏览记录");
      solo.waitForText("清空");
      solo.clickOnView(solo.getView(R.id.view_for_house_history_item_tv_title));
      Report.writeHTMLLog("安居客浏览房源用例", "选中最近浏览的第一套房源", Report.DONE, "");
      String browseHouseTitle =
          (String) ((TextView) solo.getCurrentActivity().findViewById(R.id.prop_title)).getText();
      Report.writeHTMLLog("安居客浏览房源用例", "最近浏览的第一套房源标题为:" + browseHouseTitle, Report.DONE, "");
      Boolean flag = Action.assertString(solo, "比较收藏房源标题是否匹配", houseTitle, browseHouseTitle);
      if (flag) {
        Report.writeHTMLLog("安居客浏览房源用例", "匹配成功", Report.PASS, "");
      } else {
        Report.writeHTMLLog("安居客浏览房源用例", "匹配不成功用例失败", Report.FAIL, Action.screenShot(solo));
      }
      //			Report.seleniumReport();
    } catch (Exception e) {
      String ps = Action.screenShot(solo);
      Report.writeHTMLLog("出现异常:" + e.getMessage(), "脚本停止", Report.FAIL, ps);
      //			Report.seleniumReport();
    }
  }
 public void enterEnquirerDetails(List<String> enquirerDetails) {
   TextField textField =
       (TextField) solo.getCurrentActivity().findViewById("enquirer_name".hashCode());
   EditText nameField = (EditText) textField.findViewById(R.id.value);
   solo.enterText(nameField, "");
   solo.enterText(nameField, enquirerDetails.get(0).toString());
 }
Example #5
0
  public void test02_SetTest() {
    Activity testActivity = mSolo.getCurrentActivity();
    mSolo.assertCurrentActivity("Not SspDebugModeActivity Class", SspDebugModeActivity.class);

    mSolo.sleep(EmOperate.TIME_LONG);
    if (!mSolo.isCheckBoxChecked(0)) {
      mSolo.clickOnCheckBox(0);
      mSolo.sleep(EmOperate.TIME_LONG);
      mSolo.clickOnButton(0);

      mSolo.sleep(EmOperate.TIME_SUPER_LONG);

      BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
      // BluetoothAdapterEx adapterEx = BluetoothAdapterEx.getDefaultAdapterEx();
      // adapterEx.setSSPDebugMode(false);
      mSolo.sleep(EmOperate.TIME_SUPER_LONG);
      mSolo.sleep(EmOperate.TIME_SUPER_LONG);
      mSolo.sleep(EmOperate.TIME_SUPER_LONG);
      if (BluetoothAdapter.STATE_OFF != adapter.getState()) {
        adapter.disable();
        int jumpCount = 0;
        while ((BluetoothAdapter.STATE_OFF != adapter.getState()) && (jumpCount++ < 15)) {
          EmOperate.waitSomeTime(EmOperate.TIME_SUPER_LONG);
        }
      }
    } else {

      mSolo.sleep(EmOperate.TIME_SUPER_LONG);
      mSolo.clickOnCheckBox(0);
      mSolo.sleep(EmOperate.TIME_LONG);

      mSolo.goBack();
    }
  }
 protected boolean waitForActivity(String activityName, long timeout) {
   long now = System.currentTimeMillis();
   long endTime;
   for (endTime = now + timeout;
       !solo.getCurrentActivity().getClass().getName().equals(activityName) && now < endTime;
       now = System.currentTimeMillis()) ;
   return now < endTime;
 }
  /**
   * The first walkthrough. Documented on the wiki. Starts on the login, ends up navigating to a
   * lesson after logging in.
   */
  @Test
  public void testWalkthroughLoginToDashboardToCoursesToCourseToLesson() {
    // Login first
    EditText user = solo.getEditText(0);
    EditText pass = solo.getEditText(1);
    solo.typeText(user, "*****@*****.**");
    solo.typeText(pass, "password");
    solo.clickOnButton(solo.getString(com.huskysoft.eduki.R.string.login));
    // Need to sleep to allow the activity to finish
    solo.sleep(8000);
    solo.assertCurrentActivity("Wrong activity", MainActivity.class);

    // Click on the all courses button
    solo.clickOnActionBarItem(com.huskysoft.eduki.R.id.action_courses);
    solo.sleep(1000);
    solo.assertCurrentActivity("Did not start the Course list Activity", CoursesListActivity.class);

    // Wait for the courses list to appear
    solo.waitForView(solo.getView(com.huskysoft.eduki.R.id.courseListView));
    solo.sleep(1000);
    List<Course> courseList = ((CoursesListActivity) solo.getCurrentActivity()).getCourseList();
    assertNotSame(courseList.size(), 0);
    solo.clickOnText("INTRODUCTION");
    solo.assertCurrentActivity("Wrong activity", CourseActivity.class);

    // Wait for the course page to appear
    solo.waitForView(solo.getView(com.huskysoft.eduki.R.id.course_activity));
    solo.sleep(1000);

    // Click a lesson, wait for it to appear
    List<Lesson> lessonList = ((CourseActivity) solo.getCurrentActivity()).getLessonList();
    assertNotSame(lessonList.size(), 0);
    solo.clickOnText(lessonList.get(0).toString());

    solo.waitForView(solo.getView(com.huskysoft.eduki.R.id.lessonViewLayoutText));
    solo.sleep(1000);
    String content =
        ((TextView)
                solo.getCurrentActivity()
                    .findViewById(com.huskysoft.eduki.R.id.lessonViewLayoutText))
            .getText()
            .toString();
    assertFalse(content.equals(""));
  }
Example #8
0
 public void restart() {
   if (FORCE_RESTART) {
     ContextWrapper main = new ContextWrapper(solo.getCurrentActivity());
     Intent i =
         main.getBaseContext()
             .getPackageManager()
             .getLaunchIntentForPackage(main.getBaseContext().getPackageName());
     i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
     main.startActivity(i);
   }
 }
  protected boolean waitForNuxeoActivity(String activityName) throws Exception {
    Thread.sleep(300);
    boolean result = waitForActivity(activityName, ACTIVITY_WAIT_MILLIS);

    if (!result) {
      String currentActivityName = solo.getCurrentActivity().getClass().getName();
      throw new AssertionError(
          "Unable to find activity "
              + activityName
              + " ( current name is "
              + currentActivityName
              + ")");
    }

    Activity currentActivity = solo.getCurrentActivity();

    Method method = null;

    try {
      method = currentActivity.getClass().getMethod("isReady");
    } catch (NoSuchMethodException e) {

    }

    if (method == null) {
      if (!currentActivity.getClass().getSimpleName().equals("HomeSampleActivity")) {
        throw new RuntimeException("Unable to find isReady method");
      }
      return result;
    }

    boolean ready = (Boolean) method.invoke(currentActivity);
    int nbTry = NUMBER_OF_TRIES;
    while (!ready && nbTry > 0) {
      Thread.sleep(300);
      ready = (Boolean) method.invoke(currentActivity);
      nbTry -= 1;
    }
    return ready;
  }
Example #10
0
  /**
   * The second test, documented on the wiki. Starts on login. Does not login, instead navigates to
   * a course list and ends up at a quiz.
   */
  @Test
  public void testWalkthroughLoginToCoursesListToCourseToQuiz() {
    // Need to sleep to allow the activity to finish
    solo.clickOnActionBarItem(com.huskysoft.eduki.R.id.action_courses);
    solo.sleep(1000);
    solo.assertCurrentActivity("Did not start the Course list Activity", CoursesListActivity.class);

    // Wait for the courses list to appear
    solo.waitForView(solo.getView(com.huskysoft.eduki.R.id.courseListView));
    solo.sleep(1000);
    List<Course> courseList = ((CoursesListActivity) solo.getCurrentActivity()).getCourseList();
    assertNotSame(courseList.size(), 0);
    solo.clickOnText("INTRODUCTION");
    solo.assertCurrentActivity("Wrong activity", CourseActivity.class);

    // Wait for the course page to appear
    solo.waitForView(solo.getView(com.huskysoft.eduki.R.id.course_activity));
    solo.sleep(1000);

    // Click a quiz, wait for it to appear
    List<Quiz> quizList = ((CourseActivity) solo.getCurrentActivity()).getQuizList();
    assertNotSame(quizList.size(), 0);
    solo.clickOnText(quizList.get(0).toString());

    solo.waitForView(solo.getView(com.huskysoft.eduki.R.id.quizScrollView));
    solo.sleep(2000); // Sleep to wait for the answers to populate
    List<RadioGroup> answersGroupList =
        ((QuizzesViewActivity) solo.getCurrentActivity()).getAnswerGroup();
    for (int i = 0; i < answersGroupList.size(); i++) {
      RadioGroup current_rg = answersGroupList.get(i);
      List<RadioButton> list_rb = getRadioButtons(current_rg);
      assertTrue(list_rb.size() != 0);
      solo.clickOnView(list_rb.get(0)); // Answer "A" for everything
      solo.sleep(500);
    }
    solo.sleep(1000);
    solo.clickOnButton("SUBMIT");
    solo.waitForActivity(QuizzesResultsActivity.class);
    solo.assertCurrentActivity("Wrong activity", QuizzesResultsActivity.class);
  }
  @SuppressLint("DefaultLocale")
  public void testXidioLoginErrorMessagePos() {

    assertTrue(solo.waitForActivity(TestConstants.FIRST_RUN));
    solo.sleep(TestConstants.SLEEP_TIME_1000);
    if (!Build.MODEL.toLowerCase(Locale.US).contains("comcast")) {

      solo.enterText(
          (EditText)
              solo.getCurrentActivity().findViewById(com.xfinity.xidio.R.id.first_run_username),
          TestConstants.WRONG_USERNAME);
      solo.enterText(
          (EditText)
              solo.getCurrentActivity().findViewById(com.xfinity.xidio.R.id.first_run_password),
          TestConstants.PASSWORD);
      solo.sleep(TestConstants.SLEEP_TIME_500);
      solo.sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
      solo.sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
      solo.sendKey(KeyEvent.KEYCODE_DPAD_CENTER);
      solo.sleep(TestConstants.SLEEP_TIME_2000);
      assertFalse(solo.searchText("Error, check username/password and try again"));
      solo.sleep(TestConstants.SLEEP_TIME_1000);
    }
  }
 protected View findViewByTag(/* Class<? extends Activity> activityClass, */ String tag) {
   // final List<View> views = solo.getViews();
   // for (View view : views)
   // {
   // if (tag.equals(view.getTag()) == true)
   // {
   // return view;
   // }
   // }
   // return null;
   // return
   // solo.getCurrentActivity().findViewById(android.R.id.content).findViewWithTag(tag);
   // final List<Activity> activities = solo.getAllOpenedActivities();
   // for (Activity activity : activities)
   // {
   // if (activityClass == activity.getClass())
   // {
   // return activity.getWindow().getDecorView().findViewWithTag(tag);
   // }
   // }
   return solo.getCurrentActivity().getWindow().getDecorView().findViewWithTag(tag);
 }
  // return true if the the title expected is found
  protected boolean waitForDocumentTitle(int position, String expectedTitle) throws Exception {
    String title = getDocumentTitle(position);
    int nbTry = NUMBER_OF_TRIES;
    while (!(expectedTitle.equals(title)) && nbTry > 0) {
      Thread.sleep(300);
      title = getDocumentTitle(position);
      nbTry -= 1;
    }

    if (nbTry == 0) {
      String activityName = solo.getCurrentActivity().getClass().getSimpleName();
      throw new AssertionError(
          "Unable to find title "
              + expectedTitle
              + "; actual title is "
              + title
              + " on activity "
              + activityName);
    }

    return nbTry > 0;
  }
 /**
  * Sometimes, we need to hide the soft keyboard, because the virtual keyboard process seems to
  * intercept the touch event.
  *
  * <p>See http://code.google.com/p/robotium/issues/detail?can=1&q=133&colspec=ID
  * %20Type%20Stars%20Status%20Priority%20Milestone%20Owner%20Summary&id=133 for the discussion
  * thread.
  *
  * @param editText
  */
 protected void hideSoftKeyboard(final View editText) {
   final InputMethodManager inputMethodManager =
       (InputMethodManager)
           solo.getCurrentActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
   inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
 }
Example #15
0
 public void assertPresenceOfValidationMessage() {
   TextField textField =
       (TextField) solo.getCurrentActivity().findViewById("enquirer_name".hashCode());
   EditText nameField = (EditText) textField.findViewById(R.id.value);
   assertEquals("Enquirer name is required", nameField.getError().toString());
 }
  @Smoke
  public void testNXTMotorActionBrick() {
    ScriptTabActivity activity = (ScriptTabActivity) solo.getCurrentActivity();
    ScriptFragment fragment =
        (ScriptFragment) activity.getTabFragment(ScriptTabActivity.INDEX_TAB_SCRIPTS);
    BrickAdapter adapter = fragment.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals(
        "Incorrect number of bricks.",
        2 + 1,
        solo.getCurrentListViews().get(0).getChildCount()); // don't forget the footer
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.",
        solo.getText(getActivity().getString(R.string.brick_motor_action)));
    assertNotNull(
        "TextView does not exist.", solo.getText(getActivity().getString(R.string.motor_speed)));

    String buttonOkText = solo.getString(R.string.ok);
    solo.clickOnEditText(0);
    solo.waitForText(buttonOkText);
    solo.clearEditText(0);
    solo.enterText(0, SET_SPEED + "");
    solo.clickOnButton(buttonOkText);

    int speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", SET_SPEED, speed);
    assertEquals(
        "Value in Brick is not updated.", SET_SPEED + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        SET_SPEED + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(
        0,
        SET_SPEED_INITIALLY
            + 100); // robotium doesnt go through proper function onProgressChanged() to change
                    // value on progress bar!
    solo.sleep(200);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", SET_SPEED_INITIALLY, speed);
    assertEquals(
        "Value in Brick is not updated.",
        SET_SPEED_INITIALLY + "",
        solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        SET_SPEED_INITIALLY + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.clickOnButton(0);
    int speedCounter = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speedCounter, speed - 1);
    assertEquals(
        "Value in Brick is not updated.", speed - 1 + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed - 1 + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.clickOnButton(1);
    speedCounter = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speedCounter, speed);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(0, 1);
    solo.clickOnButton(0);
    solo.clickOnButton(0);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speed, MIN_SPEED);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(0, MAX_SPEED + 100);
    solo.clickOnButton(1);
    solo.clickOnButton(1);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speed, MAX_SPEED);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    String[] motors = getActivity().getResources().getStringArray(R.array.nxt_motor_chooser);
    assertTrue("Spinner items list too short!", motors.length == 4);

    Spinner currentSpinner = solo.getCurrentSpinners().get(0);
    solo.pressSpinnerItem(0, 0);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem());
  }
Example #17
0
  public void testMaximizeStretch() throws NameNotFoundException, IOException {
    Project project = createTestProject(testProject);
    project.virtualScreenWidth = 480;
    project.virtualScreenHeight = 700;
    project.setDeviceData(getActivity());
    storageHandler.saveProject(project);
    solo.clickOnButton(getActivity().getString(R.string.my_projects));
    solo.waitForActivity(MyProjectsActivity.class.getSimpleName());
    solo.waitForFragmentById(R.id.fr_projects_list);
    assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject));
    solo.waitForActivity(ProjectActivity.class.getSimpleName());

    Utils.updateScreenWidthAndHeight(getActivity());
    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    assertTrue(
        "Stage not resizeable.", ((StageActivity) solo.getCurrentActivity()).getResizePossible());
    byte[] whitePixel = {(byte) 255, (byte) 255, (byte) 255, (byte) 255};
    byte[] screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel =
        StageActivity.stageListener.getPixels(
            Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    solo.goBack();
    solo.clickOnButton(getActivity().getString(R.string.stagemenu_screen_size));
    solo.clickOnButton(getActivity().getString(R.string.resume_current_project));
    solo.sleep(100);
    byte[] blackPixel = {0, 0, 0, (byte) 255};
    screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);
    screenPixel =
        StageActivity.stageListener.getPixels(
            Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);

    screenPixel =
        StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH, Values.SCREEN_HEIGHT, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);

    solo.goBack();
    solo.clickOnButton(getActivity().getString(R.string.stagemenu_screen_size));
    solo.clickOnButton(getActivity().getString(R.string.resume_current_project));
    solo.sleep(100);
    screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel =
        StageActivity.stageListener.getPixels(
            Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
  }
  public void testLoginValidation() throws TestException {

    try {
      Log.i(TAG, "------It is testLoginValidation()-----------");

      activityName = soloLoginValid.getCurrentActivity().getClass().getSimpleName();

      if (activityName.equalsIgnoreCase("MainActivity")) {
        Log.i(TAG, "------It is MainActivity-----------" + activityName);
        soloLoginValid.waitForActivity("HomeActivity", 2000);

        for (int i = 0; i < 40; i++) {
          activityName = soloLoginValid.getCurrentActivity().getClass().getSimpleName();
          if (activityName.equalsIgnoreCase("HomeActivity")) {

            Log.i(TAG, "------for()-- loop-----");
            break;
          }

          soloLoginValid.waitForActivity("HomeActivity", 2000);
        }

      } else {
        Log.i(TAG, "------ testLoginValidation failed-----------");
        throw new TestException(
            "Current Activity Failed----"
                + soloLoginValid.getCurrentActivity().getClass().getSimpleName()
                + "failed");
      }

      if (activityName.equalsIgnoreCase("HomeActivity")) {
        Log.i(TAG, "------HomeActivity-----------");
        System.out.println(" Activity name ---->" + soloLoginValid.getCurrentActivity());
        ArrayList<View> al = soloLoginValid.getViews();
        Iterator<View> it = al.iterator();
        while (it.hasNext()) {
          String viewName = it.next().getClass().getSimpleName();
          if (viewName.equalsIgnoreCase("ImageView")) {
            Log.i(TAG, "------ImageView found-----------");
            break;
          }
          continue;
        }

      } else {
        Log.i(TAG, "------HomeActivity not  found-----------");
        throw new TestException(
            TAG + soloLoginValid.getCurrentActivity().getClass().getSimpleName() + "failed");
      }
      // click on Loginbutton
      soloLoginValid.waitForActivity("MainActivity", 5000);
      // get the login button view with id i.e home_login_btn
      ImageView loginButton = (ImageView) soloLoginValid.getView(R.id.home_login_btn);
      // click on login button with view id
      soloLoginValid.clickOnView(loginButton);
      // control waits for 2 seconds to activate the screen
      soloLoginValid.waitForActivity("SplashActivity", 2000);
      // clears the text at first Editfield
      EditText emailField = (EditText) soloLoginValid.getView(R.id.txt_email);
      soloLoginValid.clearEditText(emailField);
      // it will type the text at first field which i gave in method
      soloLoginValid.enterText(emailField, "android@");
      // clear the text at second Editfield
      EditText passwordField = (EditText) soloLoginValid.getView(R.id.txt_password);
      soloLoginValid.clearEditText(passwordField);
      // finding the password field view
      // click the password field based on EditText view object
      soloLoginValid.clickOnView(passwordField);
      soloLoginValid.waitForActivity("MainActivity", 1000);
      soloLoginValid.enterText(passwordField, "*****");
      soloLoginValid.waitForActivity("MainActivity", 1000);
      // click on Login button
      ImageView clickLogin = (ImageView) soloLoginValid.getView(R.id.login_btn);
      soloLoginValid.clickOnView(clickLogin);
      // soloSplash.clickOnImageButton(1);
      soloLoginValid.waitForActivity("LoginActivity");
      soloLoginValid.clickOnView(emailField);
      soloLoginValid.waitForActivity("LoginActivity", 1000);
      boolean valid = soloLoginValid.searchText("Invalid Email address!");
      if (valid) {
        assertTrue("Invalid Email address!", valid);
      } else {
        throw new TestException("Testcase failed");
      }
      soloLoginValid.waitForActivity("LoginActivity", 1000);
      // Get the view location of cancel button.
      clickCancel = (ImageView) soloLoginValid.getView(R.id.cancel_btn);
      soloLoginValid.waitForActivity("MainActivity", 1000);
      // click on cancel button
      soloLoginValid.clickOnView(clickCancel);
      soloLoginValid.waitForActivity("LoginActivity", 1000);

    } catch (TestException e) {
      e.printStackTrace();
    }
  }
Example #19
0
 private void refreshCurrentActivity() {
   this.theActivity = solo.getCurrentActivity();
   Log.i("nofatclips", "Current activity is " + getActivity().getLocalClassName());
 }