如何使用Espresso访问外部网站上的元素

问题描述:

使用espresso,我们单击登录"按钮,这将启动一个外部网站(Chrome自定义标签),您可以在该网站上登录,然后将其重定向回我们的android应用程序.

Using espresso, we click a Login button which launches an external website (Chrome Custom Tab) where you can login and then it redirects back to our android application.

Espresso中是否有一种方法可以实现:
1)验证是否启动了正确的URL
2)访问网站上的元素,以便我可以输入登录信息并继续登录

Is there a way in Espresso to:
1) Verify the correct URL is being launched
2) Access the elements on the website so that I can enter the login information and continue to login

当我尝试在Espresso Launch Navigator中查看它时,页面上没有任何显示,并且如果我尝试记录,则在输入页面上的内容时也不会显示.

When I try viewing it in the Espresso Launch Navigator, nothing shows up for the page, and if I try to record, it doesn't pick up on me entering anything on the page.

这是我到目前为止(在Kotlin(不是Java)中):

This is what I have so far (it is in Kotlin (not Java)):

这是显示的错误:

它启动我的应用程序,选择登录按钮,打开网站,但是它无法访问元素.

It launches my application, select the login button, opens the website but then it isn't able to access the elements.

我也尝试过:

更新:这使用的是Chrome自定义标签(不是Web视图),因此Espresso Web无法正常工作.

Update: This is using Chrome Custom Tabs (not a Web View) so Espresso Web is not working.

我能够同时使用Espresso和UI Automator解决此问题.您可以将两者结合起来.我使用Espresso选择登录按钮(其余的应用程序,我将使用Espresso).为了处理Chrome自定义"标签进行登录,我使用了UIAutomator:

I was able to resolve this issue using both Espresso and UI Automator. You are able to combine the two. The selection of the login button I used Espresso (and the rest of the app, I will use Espresso). To handle the Chrome Custom tab for logging in, I used UIAutomator: