I am trying to UI Test a cross-platform application that gets permission to the device's camera. To do so, it pulls up a pop-up box where the user must "ALLOW" or "DENY" access to the camera. How can I interact with this pop-up in my UI tests?
Answer from @MatthewRegul from this post. NOt everyone can access that forum so copying answer below:
This should help you get started...
Query for the Alert Control
iOS :: app.Query(c=>c.ClassFull("_UIAlertControllerView"))
Android :: app.Query(c => c.Class("AlertDialogLayout"))
Query for the OK button on the Alert Control
iOS :: app.Query(c=>c.Marked("OK").Parent().ClassFull("_UIAlertControllerView"))
Android :: app.Query(c=>c.Marked("OK").Parent().Class("AlertDialogLayout"))
Disclaimer: This only works with application-contained dialog alerts. It does NOT work with OS-generated popups, such as those produced when asking permission to the camera, etc.
0
JGoldbergerUSMember, Forum Administrator, Xamarin Team, UniversityXamurai
@JGoldberger No worries! Thanks for your help. Yeah - they are currently not auto-accepted, but I am developing in a cross-platform app using .NET 2.0 Standard so that could be part of the issue. Thanks again!
Answers
@hkidd
Answer from @MatthewRegul from this post. NOt everyone can access that forum so copying answer below:
This should help you get started...
Query for the Alert Control
iOS ::
app.Query(c=>c.ClassFull("_UIAlertControllerView"))
Android ::
app.Query(c => c.Class("AlertDialogLayout"))
Query for the OK button on the Alert Control
iOS ::
app.Query(c=>c.Marked("OK").Parent().ClassFull("_UIAlertControllerView"))
Android ::
app.Query(c=>c.Marked("OK").Parent().Class("AlertDialogLayout"))
Code Sample - https://gist.github.com/mattregul/993b7e3e719a9b636b6cc74c5dce2253#file-displayalertuitest-cs-L32
Additional Resources:
1. Working with Repl - https://developer.xamarin.com/guides/testcloud/uitest/working-with/repl/
2. Test Recorder - https://www.xamarin.com/test-cloud/recorder
3. (more) Test Recorder - https://developer.xamarin.com/guides/testcloud/testrecorder/
4. Query Child Walk-up - https://forums.xamarin.com/discussion/27242/app-query-syntax-documentation-e-g-get-the-immediate-parent-of-an-element
iOS Tree
Android Tree
@JGoldberger Thank you!
Disclaimer: This only works with application-contained dialog alerts. It does NOT work with OS-generated popups, such as those produced when asking permission to the camera, etc.
Ah, sorry.
According to this thread, those should be auto accepted: https://forums.xamarin.com/discussion/79899/how-to-ignore-system-dialogs-for-ios-platforms-when-running-tests-in-test-cloud
You may want to reach out to App Center support if they are not: https://docs.microsoft.com/en-us/appcenter/general/support-center
@JGoldberger No worries! Thanks for your help. Yeah - they are currently not auto-accepted, but I am developing in a cross-platform app using .NET 2.0 Standard so that could be part of the issue. Thanks again!