Esempio n. 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);
      }
    }
  }
 private void deleteAllCourses() {
   for (int i = 0; i < 4; i++) {
     solo.clickOnCheckBox(i);
   }
   solo.clickOnView(getActivity().findViewById(R.id.delete));
   for (int i = 0; i < 5; i++) {
     solo.clickOnCheckBox(i);
   }
   solo.clickOnView(getActivity().findViewById(R.id.delete));
 }
  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();
    }
  }
Esempio n. 4
0
 public void addTab() {
   mSolo.clickOnView(mSolo.getView(R.id.tabs));
   // wait for addTab to appear (this is usually immediate)
   boolean success =
       waitForCondition(
           new Condition() {
             @Override
             public boolean isSatisfied() {
               View addTabView = mSolo.getView(R.id.add_tab);
               if (addTabView == null) {
                 return false;
               }
               return true;
             }
           },
           MAX_WAIT_MS);
   mAsserter.ok(success, "waiting for add tab view", "add tab view available");
   mSolo.clickOnView(mSolo.getView(R.id.add_tab));
 }
 public void testEmptyCourseListClick() {
   ListView listView = (ListView) solo.getView(R.id.courses_list);
   View emptyview = listView.getEmptyView();
   assertEquals("EmptyView shoudl not be visible", View.GONE, emptyview.getVisibility());
   deleteAllCourses();
   assertEquals(0, listView.getCount());
   assertEquals("Empty view should be visible", View.VISIBLE, emptyview.getVisibility());
   solo.clickOnView(emptyview);
   solo.assertCurrentActivity(
       "Current activity shoudl Be the AddCourse Activity", AddCourseActivity.class);
   solo.goBack();
 }
  public void testAddCourse() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      PreferenceManager.getDefaultSharedPreferences(getActivity())
          .edit()
          .putBoolean("pref_use_android_calendar", true)
          .putString("pref_android_calendar_to_use", "1")
          .commit();
    }
    UpdateService.setCrawlerToUse(SimpleMockCrawler.class);
    solo.clickOnView(getActivity().findViewById(R.id.add));
    int oldsize = CourseContainer.instance().size();
    solo.clickOnEditText(0);
    solo.enterText(0, "Course");
    solo.clickOnEditText(0);
    solo.sendKey(Solo.ENTER);
    solo.waitForText("THE COURSE #2", 1, 5);
    solo.clickOnText("THE COURSE #2");
    solo.waitForText("Courses", 1, 5);
    assertEquals(oldsize + 1, CourseContainer.instance().size());
    assertTrue(solo.searchText("THE COURSE #2", 1, true));
    Exam exam = CourseContainer.instance().get(CourseContainer.instance().size() - 1).exams.first();
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      assertFalse("Exam of added course should have a created event", exam.event_id == -1);
    }

    oldsize = CourseContainer.instance().size();
    solo.clickOnView(getActivity().findViewById(R.id.add));
    solo.enterText(0, "Course");
    solo.clickOnEditText(0);
    solo.sendKey(Solo.ENTER);
    solo.waitForText("THE COURSE #2", 1, 5);
    solo.clickOnText("THE COURSE #2");
    assertEquals(
        "You should not be able to add the same course twice",
        oldsize,
        CourseContainer.instance().size());

    solo.goBack();
    solo.goBack();
  }
 public void testAddCourseCrawlerError() {
   UpdateService.setCrawlerToUse(NullCrawler.class);
   solo.clickOnView(getActivity().findViewById(R.id.add));
   solo.enterText(0, "Course");
   solo.clickOnEditText(0);
   solo.sendKey(Solo.ENTER);
   assertTrue("Error dialog not shown", solo.searchText(solo.getString(R.string.error)));
   assertTrue("Error message not shown", solo.searchText(solo.getString(R.string.search_error)));
   solo.clickOnButton(0);
   assertFalse(
       "Error shows even after clicking ok", solo.searchText(solo.getString(R.string.error)));
   solo.goBack();
   solo.goBack();
 }
 public void testDeleteCourses() {
   solo.clickOnCheckBox(1);
   solo.clickOnCheckBox(3);
   solo.clickOnCheckBox(5);
   solo.clickOnCheckBox(7);
   solo.clickOnView(getActivity().findViewById(R.id.delete));
   ListView listView = (ListView) solo.getView(R.id.courses_list);
   assertEquals("Listview should only contain 6 courses", 5, listView.getCount());
   for (int i = 0; i < 9; i++) {
     if (i % 2 == 0) {
       assertTrue(solo.searchText("Course #" + i));
     }
   }
 }
Esempio n. 9
0
 public void selectFormSection(String formSectionName) {
   solo.waitForText("Save");
   solo.clickOnView(solo.getCurrentViews(Spinner.class).get(0));
   solo.waitForText(formSectionName);
   ListAdapter adapter = solo.getCurrentViews(ListView.class).get(0).getAdapter();
   for (int i = 0; i < adapter.getCount(); i++) {
     if (adapter.getItem(i).toString().equalsIgnoreCase(formSectionName)) {
       formPosition = i;
       break;
     }
   }
   solo.clickOnText(adapter.getItem(formPosition).toString());
   solo.waitForText(formSectionName);
   solo.sleep(3);
 }
Esempio n. 10
0
  public void testSpinnerUpdatesRename() {
    String newName = "nameRenamed";
    String spinnerNothingText = solo.getString(R.string.broadcast_nothing_selected);

    solo.clickOnText(spinnerNothingText);
    assertTrue(costumeName + " is not in Spinner", solo.searchText(costumeName));
    assertTrue(costumeName2 + " is not in Spinner", solo.searchText(costumeName2));
    solo.goBack();
    solo.clickOnText(getActivity().getString(R.string.backgrounds));
    solo.clickOnView(solo.getView(R.id.costume_name));
    solo.clearEditText(0);
    solo.enterText(0, newName);
    solo.clickOnButton(getActivity().getString(R.string.ok));
    solo.sleep(500);
    solo.clickOnText(getActivity().getString(R.string.scripts));
    solo.clickOnText(spinnerNothingText);
    assertTrue(newName + " is not in Spinner", solo.searchText(newName));
    assertTrue(costumeName2 + " is not in Spinner", solo.searchText(costumeName2));
  }
 public void testAddCourseScreenOriantationChange() {
   ListView listView;
   solo.clickOnView(getActivity().findViewById(R.id.add));
   solo.enterText(0, "Course");
   solo.clickOnEditText(0);
   solo.sendKey(Solo.ENTER);
   solo.waitForText("THE COURSE #2", 1, 5);
   listView = (ListView) solo.getView(android.R.id.list);
   assertEquals("List view should contain 2 items before doing anything", 2, listView.getCount());
   solo.setActivityOrientation(Solo.LANDSCAPE);
   solo.sleep(500);
   listView = (ListView) solo.getView(android.R.id.list);
   solo.sleep(3000);
   assertEquals("List view should't change size after oriantation change", 2, listView.getCount());
   assertEquals(
       "SearchView should not reset.", "Course", solo.getEditText(0).getText().toString());
   solo.goBack();
   solo.goBack();
 }
Esempio n. 12
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);
  }
Esempio n. 13
0
  /** Click on the URL bar to focus it and enter editing mode. */
  protected final void focusUrlBar() {
    // Click on the browser toolbar to enter editing mode
    final View toolbarView = mSolo.getView(R.id.browser_toolbar);
    mSolo.clickOnView(toolbarView);

    // Wait for highlighed text to gain focus
    boolean success =
        waitForCondition(
            new Condition() {
              @Override
              public boolean isSatisfied() {
                EditText urlEditText = mSolo.getEditText(0);
                if (urlEditText.isInputMethodTarget()) {
                  return true;
                } else {
                  mSolo.clickOnEditText(0);
                  return false;
                }
              }
            },
            MAX_WAIT_ENABLED_TEXT_MS);

    mAsserter.ok(success, "waiting for urlbar text to gain focus", "urlbar text gained focus");
  }
  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();
    }
  }
Esempio n. 15
0
  /**
   * Closes the tab at the specified index.
   *
   * @param index Index of tab to close
   */
  public void closeTabAt(final int index) {
    View closeButton = getTabViewAt(index).findViewById(R.id.close);

    mSolo.clickOnView(closeButton);
  }
Esempio n. 16
0
 /**
  * Selects the tab at the specified index.
  *
  * @param index Index of tab to select
  */
 public void selectTabAt(final int index) {
   mSolo.clickOnView(getTabViewAt(index));
 }
Esempio n. 17
0
 protected void click(View v) {
   // TouchUtils.clickView(this, v);
   solo.clickOnView(v);
 }