问题
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.
回答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.
回答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.
回答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 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();
}
回答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.
回答5:
you can use solo.clickOnView(solo.getView(buttonId))
来源:https://stackoverflow.com/questions/18257104/robotium-system-dialogs