Reputation: 3
I have this popup. How can I press on QUIT button ?
I use string like this:
onView(withId(android.R.id.button1)).perform((click()));
Upvotes: 0
Views: 1543
Reputation: 613
If you use the UI-Automator with AndroidX, you can find the dialog and buttons.
It is a gradle dependency code.
dependencies {
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
You can reach the QUIT
button with this code.
It is Kotlin code.
val button = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.findObject(
UiSelector().text(
activityTestRule
.activity
.getString(R.string.quit_button)
.toUpperCase()
)
)
if (button.exists() && button.isEnabled) {
button.click()
}
Upvotes: 0
Reputation: 18032
Try:
onView(withText("QUIT"))
.inRoot(isDialog())
.check(matches(isDisplayed()))
.perform(click());
Upvotes: 6