是否可以使用android espresso框架在多个活动中编写测试?
我已经看到了一些问题。
但是上面的答案在espresso 2中不起作用。这是我的摘录
@Rule
public ActivityTestRule<SplashActivity> mActivityTestRule = new ActivityTestRule<>(SplashActivity.class);
@Test
public void splashActivityTest() {
onView(withId(R.id.splash_container)).perform(swipeLeft());
onView(withId(R.id.splash_container)).perform(swipeLeft());
// launch the main activity
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.introduction_goto_btn), withText("goToMainActivity"), isDisplayed()));
appCompatButton.perform(click());
// the hierarchy can't find HomeBtn , it still hold the Splash's View, so the code below will fail
onView(withId(R.id.home_btn)).check(ViewAssertions.matches(isDisplayed()));
}
Run Code Online (Sandbox Code Playgroud)
如果在一个TestFile中不允许进行多活动测试,那么如何进行测试多个活动的流程?
我正在进行一项测试,让我参加另一项活动.当我到达那里时,我需要等待对话消失.
public class StressTest extends ActivityInstrumentationTestCase2<DashboardActivity> {
DashboardActivity activity;
ConsoleActivity consoleActivity;
public StressTest() {
super(DashboardActivity.class);
}
public void setUp() throws Exception {
super.setUp();
activity = getActivity();
}
public void testRun() throws InterruptedException {
schedule();
quickstart();
IP.enterIP();
<-----------FAILS HERE FROM A NPE------------------->
while (consoleActivity.getConnectDialog() != null && consoleActivity.getConnectDialog().isShown()){
Thread.sleep(
}
}
Run Code Online (Sandbox Code Playgroud)
如你所见,我正在开始DashboardActivity.然后进入ConsoleActivity,我需要检查ConnectDialog.如果没有获得NPE,我怎么能这样做?
public void testRun() throws InterruptedException {
schedule();
quickstart();
IP.enterIP();
Thread.sleep(500);
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED); …Run Code Online (Sandbox Code Playgroud)