david benalal
david benalal

Reputation: 386

Start espresso from a different activity

I have an app that launches splash activity screen when recording a test for espresso. However, I only want to start the espresso from another activity that starts after signing in and everything (NavDrawerActivity). Basically I want to skip signing in and all that. Here is the beginning of my code. Does anyone know how to start the testing from NavDrawerActivity?

@Rule
public ActivityTestRule<SplashScreenActivity> mActivityTestRule =
        new ActivityTestRule<>(SplashScreenActivity.class);

@Test
public void avatarActivityEspressoTest() {
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_skip), withText("SKIP"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            4),
                    isDisplayed()));
    appCompatButton.perform(click());

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
..
..

Upvotes: 1

Views: 543

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

From Docs

ActivityTestRule to reduce the amount of boilerplate code you need to write. By using ActivityTestRule, the testing framework launches the activity under test before each test method annotated with @Test and before any method annotated with @Before

Just change the rule as

@Rule
public ActivityTestRule< NavDrawerActivity> mActivityTestRule =
        new ActivityTestRule<>(NavDrawerActivity.class);

Upvotes: 1

Related Questions