How to access items on an external website using Espresso

Using espresso, click on the โ€œLoginโ€ button, which launches an external website (Chrome Custom tab), where you can log in and then redirect back to our Android application.

Is there a way in Espresso:
1) Make sure that the correct URL is running
2) Access to items on the website so that I can enter login details and continue logging in

enter image description here

When I try to view it in the Espresso Launch Navigator, nothing is displayed on the page, and if I try to record, it will not pick me up when I enter something on the page.

This is what I still have (this is in Kotlin (not Java)): enter image description here

And here the error is displayed: enter image description here

He launches my application, selects the login button, opens a website, but then he cannot access the elements.

I also tried:

enter image description here

Update. This is using Chrome custom tabs (not a web view), so Espresso Web does not work.

+5
source share
2 answers

I was able to solve this problem using both Espresso and UI Automator. You can combine these two. Selecting the login button I used Espresso (and the rest of the application, I will use Espresso). To work with the Chrome Custom tab for login, I used UIAutomator:

enter image description here

+1
source

Update:

You cannot use Espresso to test custom Chrome tabs. Espresso works when testing your own application.

You can use the Automator UI to test Chrome tabs, but you probably don't want to.

1) Make sure that the correct URL is running

A unit test will suffice. You just need to make sure the URL passed to the Chrome custom tab library is correct. You will make sure your code is working fine. What happens next is processed by the library, and tests are present there.

2) Access to items on the website so that I can enter login information and continue logging in

Here you test a simple web page. Why do you need extra overhead when starting the emulator? Perhaps Selenium or something cool for the Internet will work here (and not a web developer)?

You can use espresso web

Here is a test example:

@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 WebView objects, // 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 using 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))); } 
+2
source

Source: https://habr.com/ru/post/1270336/


All Articles