Java Code Examples for android.support.test.espresso.web.webdriver.DriverAtoms

The following are top voted examples for showing how to use android.support.test.espresso.web.webdriver.DriverAtoms. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Android-BlogExample   File: MainFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void testWebToAndroidScriptCall() throws Exception {
    String go = MainFragment.DEFAULT_URL;

    onView(withId(R.id.et_url)).perform(clearText());
    onView(withId(R.id.et_url)).perform(typeText(go)).perform(ViewActions.pressImeActionButton());

    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "search_keyword"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys(ANDROID_SCRIPT_CALL))
            // Value check. script getValue 'search_keyword'
            .check(webMatches(script("return document.getElementById('search_keyword').value", castOrDie(String.class)), containsString(ANDROID_SCRIPT_CALL)))
            // Find the submit button
            .withElement(findElement(Locator.ID, "updateKeywordBtn"))
            // Simulate a click via javascript
            .perform(webClick());

    onView(withId(R.id.et_keyword)).check(matches(withText(ANDROID_SCRIPT_CALL)));
}
 
Example 2
Project: Android-BlogExample   File: MainFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void testChangeWebViewTest() throws Exception {
    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "url"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys("http://google.com/"))
            // Find the submit button
            .withElement(findElement(Locator.ID, "changeWebView"))
            // Simulate a click via javascript
            .perform(webClick());

    onWebView()
            .withNoTimeout()
            .check(webMatches(getCurrentUrl(), containsString("https://www.google")));
}
 
Example 3
Project: Android-BlogExample   File: MainFragmentTest.java   View source code 5 votes vote down vote up
@Test
public void testCallWebJavascript() throws Throwable {
    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "search_keyword"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys(ANDROID_SCRIPT_CALL))
            .perform(script("updateKeyword();"));

    onView(withId(R.id.et_keyword)).check(matches(withText(ANDROID_SCRIPT_CALL)));
}
 
Example 4
Project: android-java-snippets-sample   File: SignInActivityTests.java   View source code 4 votes vote down vote up
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();
}