Java Code Examples for android.support.test.rule.ActivityTestRule.launchActivity()

The following are Jave code examples for showing how to use launchActivity() of the android.support.test.rule.ActivityTestRule class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: orgzly-android   File: MiscTest.java   View Source Code Vote up 6 votes
@Test
public void testReposActivityFragments() {
    ActivityTestRule rule = new ActivityTestRule<>(ReposActivity.class, true, false);

    shelfTestUtils.setupBook("book-one", "Preface\n\n* Note");
    shelfTestUtils.setupRepo("file:/");
    shelfTestUtils.setupRepo("dropbox:/orgzly");
    rule.launchActivity(null);

    // List of repos
    fragmentTest(rule, false, withId(R.id.fragment_repos_flipper));

    // Directory repo
    onListItem(1).perform(click());
    fragmentTest(rule, false, withId(R.id.fragment_repo_directory_container));
    pressBack();

    // Dropbox repo
    onListItem(0).perform(click());
    fragmentTest(rule, false, withId(R.id.fragment_repo_dropbox_container));
}
 
Example 2
Project: android-java-snippets-sample   File: SnippetListActivityTests.java   View Source Code Vote up 6 votes
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();
}
 
Example 3
Project: android-java-snippets-sample   File: SnippetListActivityTests.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: delern   File: WaitView.java   View Source Code Vote up 5 votes
/**
 * Brings activity to foreground, if it is already launched, or launches it.
 *
 * @param rule activity rule for the activity to operate on.
 * @param <T>  activity class.
 */
public static <T extends Activity> void bringToFront(final ActivityTestRule<T> rule) {
    final T runningActivity = rule.getActivity();
    if (runningActivity == null) {
        rule.launchActivity(null);
    } else {
        // TODO(dotdoom): launch using runningActivity.getIntent()? E.g. to preserve username
        //                and save roundtrip to login window.
        final Intent intent = new Intent(runningActivity, runningActivity.getClass());
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        runningActivity.startActivity(intent);
    }
}
 
Example 5
Project: Android-DatePicker-Sample   File: DatePickerTest.java   View Source Code Vote up 5 votes
private void launchDatePickerInFragmentActivity(List<ActivityTheme> activityThemeList, final Class<DatePickerInFragmentActivity> clazz){
    for(DatePickerMode datePickerMode : DatePickerMode.values()){
        for(int i = 0; i < 2; i++){
            boolean isCalendarViewShown = i == 0;
            for(int j = 0; j < 2; j++){
                boolean isSpinnersShown = j == 0;
                for(ActivityTheme activityTheme : activityThemeList){
                    if(datePickerMode == DatePickerMode.Calendar && activityTheme == ActivityTheme.Theme_Black){
                        continue;
                    }
                    final Intent intent = MainActivity.createIntent(activityTestRule.getActivity(),
                        clazz,
                        datePickerMode.layout,
                        isCalendarViewShown,
                        isSpinnersShown,
                        activityTheme.theme);
                    ActivityTestRule<DatePickerInFragmentActivity> rule = new ActivityTestRule<>(clazz, false);
                    String fileName = String.format("%s_%s_%s_%s_%s_%s_%s.png",
                        clazz.getSimpleName(),
                        datePickerMode.name(),
                        "isCalendarViewShown",
                        isCalendarViewShown,
                        "isSpinnersShown",
                        isSpinnersShown,
                        activityTheme.name());
                    Log.d(clazz.getSimpleName(), fileName);
                    rule.launchActivity(intent);
                    takeScreenshot(rule.getActivity(), fileName);
                }
            }
        }
    }
}
 
Example 6
Project: Android-DatePicker-Sample   File: DatePickerTest.java   View Source Code Vote up 5 votes
private void launchDatePickerInAppCompatActivity(List<ActivityTheme> activityThemeList, final Class<DatePickerInAppCompatActivity> clazz){
    for(DatePickerMode datePickerMode : DatePickerMode.values()){
        for(int i = 0; i < 2; i++){
            boolean isCalendarViewShown = i == 0;
            for(int j = 0; j < 2; j++){
                boolean isSpinnersShown = j == 0;
                for(ActivityTheme activityTheme : activityThemeList){
                    if(datePickerMode == DatePickerMode.Calendar && activityTheme == ActivityTheme.Theme_Black){
                        continue;
                    }
                    final Intent intent = MainActivity.createIntent(activityTestRule.getActivity(),
                        clazz,
                        datePickerMode.layout,
                        isCalendarViewShown,
                        isSpinnersShown,
                        activityTheme.theme);
                    ActivityTestRule<DatePickerInAppCompatActivity> rule = new ActivityTestRule<>(clazz, false);
                    String fileName = String.format("%s_%s_%s_%s_%s_%s_%s.png",
                        clazz.getSimpleName(),
                        datePickerMode.name(),
                        "isCalendarViewShown",
                        isCalendarViewShown,
                        "isSpinnersShown",
                        isSpinnersShown,
                        activityTheme.name());
                    Log.d(clazz.getSimpleName(), fileName);
                    rule.launchActivity(intent);
                    takeScreenshot(rule.getActivity(), fileName);
                }
            }
        }
    }
}
 
Example 7
Project: sample-code-posts   File: GeneralEspressoTestHelper.java   View Source Code Vote up 4 votes
protected void launchActivity(final ActivityTestRule activityTestRule, final Bundle extras) {
    final Intent intent = new Intent();
    intent.putExtras(extras);
    activityTestRule.launchActivity(intent);
}
 
Example 8
Project: android-java-snippets-sample   File: SignInActivityTests.java   View Source Code Vote up 4 votes
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();
}
 
Example 9
Project: Movies   File: PopularMoviesRobot.java   View Source Code Vote up 4 votes
public PopularMoviesRobot launchPopularMovies(ActivityTestRule<PopularMoviesActivity> rule) {
    rule.launchActivity(null);
    return this;
}
 
Example 10
Project: Movies   File: PosterDetailsRobot.java   View Source Code Vote up 4 votes
public PosterDetailsRobot launchDetailsScreen(long movieId, ActivityTestRule<MovieDetailsActivity> testRule) {
    testRule.launchActivity(MovieDetailsActivity.createIntentFor(movieId, InstrumentationRegistry.getInstrumentation()
            .getTargetContext()
            .getApplicationContext()));
    return new PosterDetailsRobot();
}
 
Example 11
Project: android-java-snippets-sample   File: SnippetListActivityTests.java   View Source Code Vote up 3 votes
private int getItemsCount(ActivityTestRule<SnippetListActivity> snippetListActivityRule){
    SnippetListActivity snippetListActivity = snippetListActivityRule.launchActivity(null);

    ListAdapter listAdapter = getListAdapter(snippetListActivity);
    int numItems = listAdapter.getCount();

    snippetListActivity.finish();

    return numItems;
}