Java 类android.support.test.espresso.web.webdriver.DriverAtoms 实例源码

项目:Android-BlogExample    文件:MainFragmentTest.java   
@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)));
}
项目:Android-BlogExample    文件:MainFragmentTest.java   
@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")));
}
项目:Android-BlogExample    文件:MainFragmentTest.java   
@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)));
}
项目:android-java-snippets-sample    文件:SignInActivityTests.java   
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();
}