2016-08-18 4 views
3

나는 그것에 관해 몇 가지 질문을 보았다.에스프레소 2 - 여러 활동을 테스트하는 방법?

예 : Android Espresso testing app flow

그러나 위의 anwser 여기 에스프레소 2에서 작동하지 않는 다중 활동 테스트 한 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

클릭을 수행 한 후 홈 _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

내가있어 같은 문제를 시연했다. Espresso는 공회전을하더라도 새로운 활동이 시작될 때까지 기다리지 않습니다. 따라서 새로운 활동에 대한 의견을 확인하기 전에 지연을 설정해야합니다.

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))); 
관련 문제