下面列出了android.support.test.rule.ActivityTestRule#launchActivity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void Disconnect(ActivityTestRule<SnippetListActivity> snippetListActivityTestRule) {
SnippetListActivity snippetListActivity = snippetListActivityTestRule.launchActivity(null);
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());
// Espresso can't find menu items by id. We'll use the text property.
onView(withText(R.string.disconnect_menu_item))
.perform(click());
intended(allOf(
hasComponent(hasShortClassName(".SignInActivity")),
toPackage("com.microsoft.graph.snippets")
));
snippetListActivity.finish();
}
public static List<Integer> getSnippetsIndexes(ActivityTestRule<SnippetListActivity> snippetListActivityRule) {
SnippetListActivity snippetListActivity = snippetListActivityRule.launchActivity(null);
ListAdapter listAdapter = getListAdapter(snippetListActivity);
int numItems = listAdapter.getCount();
List<Integer> snippetIndexes = new ArrayList<>();
// Get the index of items in the adapter that
// are actual snippets and not categories, which don't have a Url
for (int i = 0; i < numItems; i++) {
if(((AbstractSnippet)listAdapter.getItem(i)).getUrl() != null) {
snippetIndexes.add(i);
}
}
snippetListActivity.finish();
return snippetIndexes;
}
public static void AzureADSignIn(String username, String password, ActivityTestRule<SignInActivity> signInActivityTestRule) throws InterruptedException {
SignInActivity signInActivity = signInActivityTestRule.launchActivity(null);
onView(withId(R.id.o365_signin)).perform(click());
try {
onWebView()
.withElement(findElement(Locator.ID, USER_ID_TEXT_ELEMENT))
.perform(clearElement())
// Enter text into the input element
.perform(DriverAtoms.webKeys(username))
// Set focus on the username input text
// The form validates the username when this field loses focus
.perform(webClick())
.withElement(findElement(Locator.ID, PASSWORD_TEXT_ELEMENT))
// Now we force focus on this element to make
// the username element to lose focus and validate
.perform(webClick())
.perform(clearElement())
// Enter text into the input element
.perform(DriverAtoms.webKeys(password));
Thread.sleep(2000, 0);
onWebView()
.withElement(findElement(Locator.ID, SIGN_IN_BUTTON_ELEMENT))
.perform(webClick());
} catch (NoMatchingViewException ex) {
// If user is already logged in, the flow will go directly to SnippetListActivity
} finally {
Thread.sleep(2000, 0);
}
// Finally, verify that SnippetListActivity is on top
intended(allOf(
hasComponent(hasShortClassName(".SnippetListActivity")),
toPackage("com.microsoft.graph.snippets")
));
signInActivity.finish();
}
private int getItemsCount(ActivityTestRule<SnippetListActivity> snippetListActivityRule){
SnippetListActivity snippetListActivity = snippetListActivityRule.launchActivity(null);
ListAdapter listAdapter = getListAdapter(snippetListActivity);
int numItems = listAdapter.getCount();
snippetListActivity.finish();
return numItems;
}