Issue
I am using ActivityScenarioRule
for Espresso UI Testing and I wanted to get access to the method getStringArray()
, calling which requires the Activity
. So, is there any way to retrieve the Activity
by the ActivityScenarioRule
, maybe something similar to getActivity
in ActivityTestRule
.
@Rule
public ActivityScenarioRule activityScenarioRule = new ActivityScenarioRule<>(MainActivity.class);
I am not using ActivityTestRule
, because it is deprecated!
Solution
Since it appears you're using Java, here's how you'd do it:
@Rule
ActivityScenarioRule<MainActivity> activityScenarioRule = new ActivityScenarioRule<>(MainActivity.class);
@Test
public void test() {
activityScenarioRule.getScenario().onActivity(activity -> {
// use 'activity'.
});
}
Please read the documentation for more info on these new ways of interacting with the activity under test.
Answered By - gosr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.