【发布时间】:2020-02-18 12:01:06
【问题描述】:
我将登录。然后,请求显示卡片列表。每次这个请求发生在不同的时间并且使用 sleep() 不是很好。只要页面正在加载,如何让测试等待?最好有示例代码。
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AuthorizationTest {
private IdlingResource mIdlingResource;
@Rule
public ActivityTestRule<AuthorizationActivity> mActivityRule = new ActivityTestRule(AuthorizationActivity.class);
@Before
public void SetUp() throws Exception {
Thread.sleep(4000);
try {
onView(allOf(withId(R.id.tiAuthLogin), (isDisplayed()))).check(matches(isDisplayed()));
} catch (NoMatchingViewException e) {
pressBack();
}
}
@Test
public void checkMoneyBackButton() throws Exception {
onView(withId(R.id.btnAuthLogin)).perform(click());
Thread.sleep(10000);
onView(withId(R.id.etSessionKey1)).perform(typeText("1234"));
closeSoftKeyboard();
onView(isRoot()).perform(waitFor(40000));
ViewInteraction viewInteraction = Espresso.onView(withText("**** 0431"));
viewInteraction.perform(click());
Thread.sleep(3000);
Espresso.onView(ViewMatchers.withId(R.id.vpCard)).perform(ViewActions.swipeUp());
onView(withId(R.id.statementMoneyBack)).check(matches(isDisplayed()));
}
}
【问题讨论】:
-
我知道有这样的事情。但我不知道如何将其应用于我的代码。
code
标签: testing automated-tests android-espresso