androidx.test.espresso.web.webdriver.Locator Java Examples
The following examples show how to use
androidx.test.espresso.web.webdriver.Locator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebViewActivityTest.java From android-test with Apache License 2.0 | 6 votes |
@Test public void typeTextInInput_clickButton_SubmitsForm() { Log.i(TAG, "About to click on WebViewActivity..."); onData(withItemContent(containsString("WebViewActivity"))).perform(click()); // Selects the WebView in your layout. If you have multiple WebViews you can also use a // matcher to select a given WebView, onWebView(withId(R.id.web_view)). onWebView() // Find the input element by ID .withElement(findElement(Locator.ID, "text_input")) // Clear previous input .perform(clearElement()) // Enter text into the input element .perform(DriverAtoms.webKeys(MACCHIATO)) // Find the submit button .withElement(findElement(Locator.ID, "submitBtn")) // Simulate a click via javascript .perform(webClick()) // Find the response element by ID .withElement(findElement(Locator.ID, "response")) // Verify that the response page contains the entered text .check(webMatches(getText(), containsString(MACCHIATO))) // Verify that the response page contains the entered text with webContents by id .check(webContent(elementById("response", withTextContent(containsString(MACCHIATO))))); }
Example #2
Source File: WebViewActivityTest.java From android-test with Apache License 2.0 | 6 votes |
@Test public void typeTextInInput_clickButton_ChangesText() { Log.i(TAG, "About to click on WebViewActivity..."); onData(withItemContent(containsString("WebViewActivity"))).perform(click()); // Selects the WebView in your layout. If you have multiple WebViews you can also use a // matcher to select a given WebView, onWebView(withId(R.id.web_view)). onWebView() // Find the input element by ID .withElement(findElement(Locator.ID, "text_input")) // Clear previous input .perform(clearElement()) // Enter text into the input element .perform(DriverAtoms.webKeys(DOPPIO)) // Find the change text button. .withElement(findElement(Locator.ID, "changeTextBtn")) // Click on it. .perform(webClick()) // Find the message element by ID .withElement(findElement(Locator.ID, "message")) // Verify that the text is displayed .check(webMatches(getText(), containsString(DOPPIO))) // Verify that the response page contains the entered text with webContents by id .check(webContent(elementById("message", withTextContent(containsString(DOPPIO))))); }
Example #3
Source File: WebViewActivityTest.java From testing-samples with Apache License 2.0 | 6 votes |
@Test public void typeTextInInput_clickButton_SubmitsForm() { // Lazily launch the Activity with a custom start Intent per test mActivityRule.launchActivity(withWebFormIntent()); // Selects the WebView in your layout. If you have multiple WebViews you can also use a // matcher to select a given WebView, onWebView(withId(R.id.web_view)). onWebView() // Find the input element by ID .withElement(findElement(Locator.ID, "text_input")) // Clear previous input .perform(clearElement()) // Enter text into the input element .perform(DriverAtoms.webKeys(MACCHIATO)) // Find the submit button .withElement(findElement(Locator.ID, "submitBtn")) // Simulate a click via javascript .perform(webClick()) // Find the response element by ID .withElement(findElement(Locator.ID, "response")) // Verify that the response page contains the entered text .check(webMatches(getText(), containsString(MACCHIATO))); }
Example #4
Source File: WebViewActivityTest.java From testing-samples with Apache License 2.0 | 6 votes |
@Test public void typeTextInInput_clickButton_ChangesText() { // Lazily launch the Activity with a custom start Intent per test mActivityRule.launchActivity(withWebFormIntent()); // Selects the WebView in your layout. If you have multiple WebViews you can also use a // matcher to select a given WebView, onWebView(withId(R.id.web_view)). onWebView() // Find the input element by ID .withElement(findElement(Locator.ID, "text_input")) // Clear previous input .perform(clearElement()) // Enter text into the input element .perform(DriverAtoms.webKeys(DOPPIO)) // Find the change text button. .withElement(findElement(Locator.ID, "changeTextBtn")) // Click on it. .perform(webClick()) // Find the message element by ID .withElement(findElement(Locator.ID, "message")) // Verify that the text is displayed .check(webMatches(getText(), containsString(DOPPIO))); }
Example #5
Source File: PageLoadTest.java From firefox-echo-show with Mozilla Public License 2.0 | 5 votes |
@Test public void PageLoadTest() throws InterruptedException, UiObjectNotFoundException { // onView(ViewMatchers.withId(R.id.tileContainer)) // .perform(RecyclerViewActions.actionOnItemAtPosition(TILE_POSITION, click())); onView(ViewMatchers.withId(R.id.webview)) .check(matches(isDisplayed())); onWebView() .withElement(findElement(Locator.ID, TILE_WEBSITE_ELEMENT)); mDevice.pressMenu(); // onView(ViewMatchers.withId(R.id.navUrlInput)) // .check(matches(isDisplayed())) // .check(matches(withText(containsString("google")))); // onView(ViewMatchers.withId(R.id.navButtonHome)) // .check(matches(isDisplayed())) // .perform(click()); // onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus())) // .perform(typeTextIntoFocusedView(MOZILLA_URL)) // .perform(pressImeActionButton()); onView(ViewMatchers.withId(R.id.webview)) .check(matches(isDisplayed())); onWebView() .withElement(findElement(Locator.CSS_SELECTOR, MOZILLA_PAGE_ELEMENT)); mDevice.pressMenu(); // onView(ViewMatchers.withId(R.id.navUrlInput)) // .check(matches(isDisplayed())) // .check(matches(withText(containsString("mozilla")))); }
Example #6
Source File: ErrorPagesScreenshots.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void takeScreenshotsOfErrorPages() { for (ErrorTypes error: ErrorTypes.values()) { onView(withId(R.id.urlView)) .check(matches(isDisplayed())) .check(matches(hasFocus())) .perform(click(), replaceText("error:" + error.value), pressImeActionButton()); assertTrue(TestHelper.webView.waitForExists(waitingTime)); assertTrue(TestHelper.progressBar.waitUntilGone(waitingTime)); // Android O has an issue with using Locator.ID if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { UiObject tryAgainBtn = device.findObject(new UiSelector() .resourceId("errorTryAgain") .clickable(true)); assertTrue(tryAgainBtn.waitForExists(waitingTime)); } else { onWebView() .withElement(findElement(Locator.ID, "errorTitle")) .perform(webClick()); onWebView() .withElement(findElement(Locator.ID, "errorTryAgain")) .perform(webScrollIntoView()); } Screengrab.screenshot(error.name()); onView(withId(R.id.display_url)) .check(matches(isDisplayed())) .perform(click()); } }
Example #7
Source File: MultitaskingTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private void longPressLink(String id, String label, String path) { onWebView() .withElement(findElement(Locator.ID, id)) .check(webMatches(getText(), equalTo(label))); simulateLinkLongPress(path); }
Example #8
Source File: PullDownToRefreshTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Test public void pullDownToRefreshTest() { onView(withId(R.id.urlView)) .check(matches(isDisplayed())) .check(matches(hasFocus())) .perform(click(), replaceText(webServer.url("/").toString()), pressImeActionButton()); onView(withId(R.id.display_url)) .check(matches(isDisplayed())) .check(matches(withText(containsString(webServer.getHostName())))); onWebView() .withElement(findElement(Locator.ID, COUNTER)) .check(webMatches(getText(), containsString(FIRST_TIME))); onView(withId(R.id.swipe_refresh)) .check(matches(isDisplayed())); // Swipe down to refresh, spinner is shown (2nd child) and progress bar is shown onView(withId(R.id.swipe_refresh)) .perform(withCustomConstraints(swipeDown(), isDisplayingAtLeast(85))) .check(matches(hasChildCount(2))); onWebView() .withElement(findElement(Locator.ID, COUNTER)) .check(webMatches(getText(), containsString(SECOND_TIME))); }
Example #9
Source File: MultitaskingTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
private void checkTabIsLoaded(String title) { onWebView() .withElement(findElement(Locator.ID, "content")) .check(webMatches(getText(), equalTo(title))); }
Example #10
Source File: CustomTabTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void testCustomTabUI() { try { startWebServer(); // Launch activity with custom tabs intent activityTestRule.launchActivity(createCustomTabIntent()); // Wait for website to load Context appContext = InstrumentationRegistry.getInstrumentation() .getTargetContext() .getApplicationContext(); if (!AppConstants.INSTANCE.isGeckoBuild()) { onWebView() .withElement(findElement(Locator.ID, TEST_PAGE_HEADER_ID)) .check(webMatches(getText(), equalTo(TEST_PAGE_HEADER_TEXT))); } // Verify action button is visible onView(withContentDescription(ACTION_BUTTON_DESCRIPTION)) .check(matches(isDisplayed())); // Open menu onView(withId(R.id.menuView)) .perform(click()); // Verify share action is visible onView(withId(R.id.share)) .check(matches(isDisplayed())); // Verify custom menu item is visible onView(withText(MENU_ITEM_LABEL)) .check(matches(isDisplayed())); // Close the menu again Espresso.pressBack(); // Verify close button is visible - Click it to close custom tab. onView(withId(R.id.customtab_close)) .check(matches(isDisplayed())) .perform(click()); } finally { stopWebServer(); } }