I saw that robotium has a function like that, but I wanted to have the same for espresso.
Denys in his post show a simple function to active this http://qathread.blogspot.com.br/2014/09/discovering-espresso-for-android-how-to.html , I will replicate it here:
public Activity getActivityInstance(){
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
for (Activity act: resumedActivities){
Log.d("Your current activity: ", act.getClass().getName());
currentActivity = act;
break;
}
}
});
return currentActivity;
}
So now I can use
Spoon.screenshot(getActivityInstance(), "screenshot_name");
Nice =).
Also, if I want to see how the screen looks in landscape, I can do:
getActivityInstance().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
And rotate it back if needed. Cool.
!
No comments:
Post a Comment