Espresso Testing call view button click waiting after call api response data progressDialog dimission

一曲冷凌霜 提交于 2019-12-20 06:40:45

问题


I develop automation testing using via espresso library. Sometime I ever got error message "Could not launch intent Intent" when running test is make long time I call view btn click after api response data progress-dialog dimission. Please help me something ideas for those error who have experience automation testing using via espresso technic Thanks :D


回答1:


This probably happens when there is a progress dialog after test finishes. So your next test can't launch itself when progress dialog is active. You can prevent this by waiting progress dialog to end.

onView(allOf(withId(R.id.btnWorkingDate), withText("OPEN DAY"))).check(matches(isDisplayed())).perform(click(),closeSoftKeyboard());
long timeout = 0L;
while(timeout < YOUR_DESIRED_TIMEOUT) {
try {
    onView(withId(anIdInNextScreenAfterProgressDialog)).check(matches(isDisplayed));
    break;
} catch (Exception e) {
   Thread.sleep(1000L);
   timeout += 1000L
}

This will wait until your progress bar disappears since it waits for something in the next page




回答2:


view button click Waiting for progressdialog dimission using Thread.sleep(4000) sometime is going correct but sometime is still show like the question error "Could not launch intent Intent". I would like to know which ideas better than my answer.

ProgressDialog Utils Class the method

public void showProgressDialog() {
    if (mProgressDialog == null) {
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setMessage("Loading...");
    }

    mProgressDialog.show();
}

public void hideProgressDialog() {
    if (mProgressDialog != null && mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();
    }
}

Testing

@Test
  public void test1() throws InterruptedException {
    //onView(withText("Loading")).check(matches(isDisplayed()));
    //    onView(allOf(isAssignableFrom(ProgressBar.class),withText("Loading..."))).check(matches(isDisplayed()));

    //onView(withId(R.id.btnWorkingDate)).perform(click());
  //  Intents.init();

    // override progress bar infinite animation with a simple image

    //onView(withText("Loading...")).check(matches(isDisplayed()));


  //  onView(withText("Loading...")).check(matches(not((isDisplayed()))));

    //onView(withText("Loading...")).check(matches(isDisplayed()));
   // onView(withText("Loading...")).check(matches(not(isDisplayed())));
   // assertTrue(progressBar().exists());

    try {
        onView(allOf(withId(R.id.btnWorkingDate), withText("OPEN DAY"))).check(matches(isDisplayed())).perform(click(),closeSoftKeyboard());
    }catch (NoMatchingViewException e) {
        // View is not in hierarchy
    }
    Thread.sleep(4000);
 /*   onView(allOf(withId(R.id.btnWorkingTime),withText("START SHIFT"), isDisplayed())).perform(click(),closeSoftKeyboard());

    onView(allOf(withId(R.id.btnWorkingTime),withText("END SHIFT"), isDisplayed())).perform(click(),closeSoftKeyboard());*/
 //   Intents.release();
   // intended(hasComponent(DashboardActivity.class.getName()));
    //assertNotNull(view);
    //onView(withId(R.id.btnWorkingDate)).perform(click());
}


@Test
public void test2() throws InterruptedException {

   // onView(allOf(withId(R.id.btnWorkingTime),withText("START SHIFT"), isDisplayed())).perform(click(),closeSoftKeyboard());

  //  assertTrue(progressBar().exists());

    try {
        onView(allOf(withId(R.id.btnWorkingTime), withText("START SHIFT"))).check(matches(isDisplayed())).perform(click(),closeSoftKeyboard());
    }catch (NoMatchingViewException e) {
        // View is not in hierarchy
    }

    Thread.sleep(4000);
}

@Test
public void test3() throws InterruptedException {

    try {
        onView(allOf(withId(R.id.btnWorkingTime), withText("END SHIFT"))).check(matches(isDisplayed())).perform(click(),closeSoftKeyboard());
    }catch (NoMatchingViewException e) {
        // View is not in hierarchy
    }
    Thread.sleep(5000);
}


来源:https://stackoverflow.com/questions/54320660/espresso-testing-call-view-button-click-waiting-after-call-api-response-data-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!