2016-08-18 3 views
3

私はそれについていくつかの質問を見ました。エスプレッソ2 - 複数の活動をテストするには?

例えば、 Android Espresso testing app flow

しかし、上記のanwserはここでエスプレッソ2で動作していないが、マルチ活動テストは1 TESTFILEに許可されていない場合は、どのように複数のアクティビティをテストするための流れを作るために私のスニペット

@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())); 
} 

のですか?

+0

発信者と呼び出し先のアクティビティのスクリーンショットを共有できますか? –

+0

clickを実行した後で、home_btnが表示されていることを確認する前に、いくつかのスリープを追加しようとしましたか? – jeprubio

+0

@ 2BAB、ねえ、仲間。あなたはその問題を解決しましたか?私は同じことに直面している。 – AQU

答えて

1

はい、可能です。彼らはhttps://github.com/googlesamples/android-testing/blob/master/ui/espresso/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ChangeTextBehaviorTest.java

@Test 
public void changeText_newActivity() { 
// Type text and then press the button. 


onView(withId(R.id.editTextUserInput)).perform (typeText(STRING_TO_BE_TYPED), 
     closeSoftKeyboard()); 
onView(withId(R.id.activityChangeTextBtn)).perform(click()); 

// This view is in a different Activity, no need to tell Espresso. 
onView(withId(R.id.show_text_view)).check(matches(withText(STRING_TO_BE_TYPED))); 
} 
1

ここにこれをデモしているサンプルの一つで、私は、同じ悩みを持っています。エスプレッソは、私がアイドリングをした時でさえ、新しい活動が走るのを待つことはありません。そのため、新しいアクティビティのビューを確認する前に遅延を設定する必要がありました。

onView(withId(R.id.activityChangeTextBtn)).perform(click()); 

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

// This view is in a different Activity, no need to tell Espresso. 
onView(withId(R.id.show_text_view)).check(matches(withText(STRING_TO_BE_TYPED))); 
関連する問題