2

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.

user2028928
  • 91
  • 1
  • 3

5 Answers5

2

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.

mlchen850622
  • 668
  • 6
  • 7
1

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.

kamal_prd
  • 543
  • 4
  • 16
1

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();
}
Community
  • 1
  • 1
Ray
  • 501
  • 4
  • 9
0

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.

Onivas
  • 161
  • 1
  • 8
-2

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

Basil
  • 845
  • 9
  • 24