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 with Android OS dialogs in Robotium? Thanks.
-
System dialogs are not part of App's window or view hierarchy. – S.D. Aug 15 '13 at 16:56
5 Answers
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.

- 668
- 6
- 7
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.

- 543
- 4
- 16
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 instance
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Search for correct button in the dialog.
UiObject button = uiDevice.findObject(new UiSelector().text("ButtonTest"));
if (button.waitForExists(5000)) {
button.click();
}
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.

- 161
- 1
- 8
you can use solo.clickOnView(solo.getView(buttonId))

- 845
- 9
- 24
-
It is Android OS dialog, not my custom. Are you sure this can help? – user2028928 Aug 15 '13 at 16:36