Issue
Im trying to use firebase ScreenShotter which takes the form:
ScreenShotter.takeScreenshot("main_screen_2", this /* activity */);
I'm not exactly sure how I'm supposed to get the Activity from within an Espresso test. At the moment my test class looks something like:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class OtherTests {
@Rule
// Replace 'MainActivity' with the value of android:name entry in
// <activity> in AndroidManifest.xml
public ActivityScenarioRule <MainActivity> mActivityRule = new ActivityScenarioRule<>(MainActivity.class);
@Test
public void getDeviceInfo() {
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}
TestHelper.tap("APP_HEADER");
TestHelper.expect("TRUE_HOME_BUTTON",5000);
ScreenShotter.takeScreenshot("main_screen_2", this /* activity */);
}
}
Solution
You have to get the scenario
and then run your code in the callback passed to onActivity
@Test
public void getDeviceInfo() {
...
mActivityRule.getScenario()
.onActivity(activity -> ScreenShotter.takeScreenshot("main_screen_2", activity));
}
Answered By - yogurtearl
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.