문제

저는 Android 용 Google 에스프레소가있는 UI 테스트를 작성하고 웹 서비스에서 비동기 적으로로드 된 텍스트보기 텍스트를 주장하는 방법에 대해 멈추고 있습니다.내 현재 코드는 다음과 같습니다.

public class MyTest extends BaseTestCase<MyActivity>{
    public void setUp() throws Exception {
        // (1) Tell the activity to load 'element-to-be-loaded' from webservice
        this.setActivityIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("data://data/element-to-be-loaded")));
        getActivity();

        super.setUp();
    }

    public void testClickOnReviews(){
        // (2) Check the element is loaded and its name is displayed
        Espresso
            .onView(ViewMatchers.withId(R.id.element_name))
            .check(ViewAssertions.matches(ViewMatchers.withText("My Name")));

        // (3) Click on the details box
        Espresso
            .onView(ViewMatchers.withId(R.id.details_box))
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
            .perform(ViewActions.click());

        // (4) Wait for the details screen to open
        Espresso
            .onView(ViewMatchers.withId(R.id.review_box));

        // Go back to element screen
        Espresso.pressBack();
    }
}
.

켜짐 (1), 웹 서비스에서 요소를로드하도록 내 활동을 알려줍니다.(2)에서는 그 견해를 주장하는 것을 기다리고 있습니다.이것은 WebService가 앱에 응답하기 전에 테스트가 실패하는 부분입니다.

어떻게 에스프레소가 특정 데이터를 화면에 나타나게 할 때까지 기다릴 수 있습니까?또는 그러한 시험을 쓰는 다른 방법으로 생각해야합니까?

도움이 되었습니까?

해결책

웹 서비스에 대한 IdlingResource를 Espresso로 등록 하여이 사례를 처리 할 수 있습니다.이 쓰기를 살펴보십시오. https://developer.android.com / 훈련 / 테스트 / 에스프레소 / idling-resource.html

countingIdlingResource (뭔가가 유휴 상태 일 때 트랙을 사용하는 간단한 카운터를 사용합니다).이 샘플 테스트 이 작업을 수행 할 수있는 방법을 보여줍니다.

다른 팁

에스프레소가있는 Uiatomator를 사용하여 괴롭히지 않으면 4 단계 에서이 작업을 수행 할 수 있습니다.

UiObject object = mDevice.findObject(new UiSelector().resourceId(packageName + ":id/" + "review_box"));
object.waitForExists(5000);
.

https : // 개발자.android.com/reference/android/support/test/uiautomator/uiobject.html#waitforexists(long)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top