Android 用の Google Espresso を使用して UI テストを書いていますが、コンテンツが Web サービスから非同期に読み込まれる TextView テキストをアサートする方法に行き詰まっています。私の現在のコードは次のとおりです。
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) で、Web サービスから要素をロードするようアクティビティに通知します。(2) では、ビューがコンテンツをアサートするのを待っています。これは、Web サービスがアプリに応答する前に実行されるため、テストが失敗する部分です。
特定のデータが画面に表示されるのを待つよう Espresso に指示するにはどうすればよいですか? または、そのようなテストを書くために別の方法で考えるべきですか?