2016-09-15 2 views
0

Also, ich habe einen Test, der meine ganze Anwendung durchläuft. Jetzt möchte ich ein Bild von allem machen. Da es 2 Aktivitäten und zahlreiche Fragmente enthält, kann ich es nicht schaffen, da es nur das erste Fragment jeder Aktivität benötigt.Löffel und Espressotest

Wie kann ich erreichen, dass ich ein Bild von jedem Fragment mache? Zum einen

@RunWith(AndroidJUnit4.class) 
@FixMethodOrder(MethodSorters.NAME_ASCENDING) 
public class HearthBeatUITest { 

    private final int MILISECONDS_TIMEOUT = 700; 

    @Rule 
    public ActivityTestRule<IntroActivity> mActivityRule = new ActivityTestRule<>(IntroActivity.class); 
    @Rule 
    public ActivityTestRule<LoginActivity> mLoginActivityRule = new ActivityTestRule<>(LoginActivity.class); 

    @Test 
    /** 
    * Testing all the screens on the application if they are actually there 
    */ 
    public void startTest() { 
     Session.clear(); 
     Spoon.screenshot(mActivityRule.getActivity(), "initial_state"); 
     threadSleep(MILISECONDS_TIMEOUT); 
     onView(withId(R.id.button_register)).check(matches(isDisplayed())).perform(click()); 
     threadSleep(MILISECONDS_TIMEOUT); 
     Spoon.screenshot(mLoginActivityRule.getActivity(), "register_intro"); 
     onView(withId(R.id.register_with_email)).check(matches(isDisplayed())).perform(click()); 
     threadSleep(MILISECONDS_TIMEOUT); 
     Spoon.screenshot(mLoginActivityRule.getActivity(), "register_detailed"); 
     onView(withId(R.id.image_left_button)).check(matches(isDisplayed())).perform(click()); 
     threadSleep(MILISECONDS_TIMEOUT); 
     Spoon.screenshot(mLoginActivityRule.getActivity(), "register_intro"); 
     onView(withId(R.id.image_left_button)).check(matches(isDisplayed())).perform(click()); 
     threadSleep(MILISECONDS_TIMEOUT); 
     Spoon.screenshot(mActivityRule.getActivity(), "initial_state"); 
     onView(withId(R.id.button_signin)).check(matches(isDisplayed())).perform(click()); 
     threadSleep(MILISECONDS_TIMEOUT); 
     Spoon.screenshot(mLoginActivityRule.getActivity(), "login_intro"); 
     onView(withId(R.id.sign_in_emal)).check(matches(isDisplayed())).perform(click()); 
     threadSleep(MILISECONDS_TIMEOUT); 
     Spoon.screenshot(mLoginActivityRule.getActivity(), "login_detailed"); 
    } 

} 
+0

Haben Ihre Fragmente Animationen? Entfernen Sie Animationen und deaktivieren Sie Animationen in den Dev-Einstellungen. – WenChao

Antwort

0

, müssen Sie nur eine Regel:

@RunWith(AndroidJUnit4.class) 
@FixMethodOrder(MethodSorters.NAME_ASCENDING) 
public class HearthBeatUITest { 

    private final int MILISECONDS_TIMEOUT = 300; 
    @Rule 
    public IntentsTestRule<IntroActivity> mActivityRule = new IntentsTestRule<>(IntroActivity.class); 
    private Activity currentActivity; 
} 

jetzt, wenn Sie Kontext für die Erstellung von Screenshots benötigen, rufen Sie diese Methode:

private Activity getActivityInstance() { 
     getInstrumentation().runOnMainSync(new Runnable() { 
      public void run() { 
       Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED); 
       if (resumedActivities.iterator().hasNext()) { 
        currentActivity = (Activity) resumedActivities.iterator().next(); 
       } 
      } 
     }); 

     return currentActivity; 
    } 

Es Sie erhalten aktuelle Aktivität und Sie können Screenshots machen. Nur fyi, Sie können keinen Screenshot von Dialogen machen.

Verwandte Themen