Skip to content Skip to sidebar Skip to footer

Robotium & System Dialogs

When I try to pair with Bluetooth device, system confirmation dialog with PIN appears. There are buttons 'Cancel' and 'OK'. But I can't click them with Robotium. How can I work wit

Solution 1:

This works for me:

solo.clickOnView(solo.getView(android.R.id.button1)); 

where the 'Positive' button is android.R.id.button1, the 'Negative' button is android.R.id.button2 and 'Neutral' is android.R.id.button3.

Solution 2:

It is not possible to write a test case that spans over 2 applications. But, if it is part of same application then you can use solo.clickOnText("Cancel"). Same way you can click on other buttons by clicking on their texts.

Solution 3:

Robotium can be difficult when it comes to Android system dialog box buttons however there is a solution.

Found the answer on this post on stack

// Set this dependency in your app's gradle file
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

and use this code snippet in your test project:

// Initialize UiDevice instanceUiDeviceuiDevice= UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

// Search for correct button in the dialog.UiObjectbutton= uiDevice.findObject(newUiSelector().text("ButtonTest"));

if (button.waitForExists(5000)) {
    button.click();
}

Solution 4:

As @kamal_prd said, you cannot because the dialog is not part of the same application. May be you could use

clickOnScreen(float x, float y) //Clicks the specified coordinates

I know it is hard to manage with different screen resolution/size, but it is what I'm also using to test my app.

Solution 5:

you can use solo.clickOnView(solo.getView(buttonId))

Post a Comment for "Robotium & System Dialogs"