Reputation: 15340
I have an app that uses the Android CheckBox
control.
How do I create a UITest that detects whether the CheckBox
is checked?
Upvotes: 0
Views: 591
Reputation: 15340
bool IsCheckBoxChecked(string textBoxContentDescription)
{
return (bool)app.Query(x => x.Marked(textBoxContentDescription).Invoke("isChecked"))?.FirstOrDefault();
}
Here is a sample app that I've put together to demostrate how to do this: https://github.com/brminnick/AndroidCheckBoxSampleApp
To interact with an Android CheckBox from a UITest, you must use the Invoke method to access the methods in the native Java Android API. In our Invoke
statements, we can take advantage of performClick()
to toggle the CheckBox, setChecked(boolean checked)
to set the value of the CheckBox, and isChecked()
to return a bool that is true
when the CheckBox is checked and false
when it is unchecked.
In the UITest project, I created a ToggleCheckBox method to toggle an individual CheckBox, a IsCheckBoxChecked method to return the CheckBox current status, and a SetCheckBox method to set the CheckBox status.
All tests were validated via Xamarin Test Cloud. The test report is viewable here.
Upvotes: 1