简体   繁体   中英

Google popup Espresso Android studio 2.2

How to handle a click on the button com.google.android.gms:id/cancel (text "None of the above") for a Google dialog as in the screenshot attached with Espresso UI Testing? [ \\登录屏幕截图]

These account chooser dialogs are out of your test application scope. Espresso cannot handle these UI elements.

You can use uiautomator as part of you Espresso tests.

See example below

@RunWith(AndroidJUnit4.class)
public class SocialLoginTest {
private UiDevice mUiDevice;

@Before
public void before() throws Exception {
    mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
}

@Test
public void someTest() throws Exception {
    //Launch activity
    //Simulate a Click on the button in your activity that triggers account chooser dialog.

    UiObject mText = mUiDevice.findObject(new UiSelector().text("NONE OF THE ABOVE"));
    mText.click();
    //Assertions for results handled in your application
}

You can use withText

onView(withText("None of the above")).perform(click());

I made a example in GitHub , If you need more clarification, please tell me.

I'm pretty sure that in that case Espresso may not work properly due this framework limitation. Try to achieve it using Google's typical instrumentation tool called uiautomator . It works great along with Espresso .

Check: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

You can also try to use open-source UI automation tool called Robotium along with Espresso .

Check: https://github.com/codepath/android_guides/wiki/UI-Testing-with-Robotium

Using only Espresso you are allowed to operate only inside your app under test context, so you cannot check notifications, most of popup dialogs or running another app from exisitng and cheking both.

Hope it will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM