How do you interact with OS specific pop-ups in UI testing?

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?

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @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

    [CalabashRootView > UIWindow]                                                   
        [UIView > ... > Xamarin_Forms_Platform_iOS_LabelRenderer]
            [UILabel] label: "Welcome to Xamarin Forms!",  text: "Welcome to Xamarin Forms!"
        [UITransitionView]
            [UIView]
            [UIView]
            [_UIAlertControllerView > ... > _UIAlertControllerInterfaceActionGroupView] label: "Title"
                [_UIDimmingKnockoutBackdropView]
                    [UIView]
                    [UIVisualEffectView]
                        [_UIVisualEffectBackdropView]
                        [_UIVisualEffectFilterView]
                [UIView]
                    [_UIInterfaceActionGroupHeaderScrollView > UIView]
                        [UILabel] label: "Title",  text: "Title"
                        [UILabel] label: "Message",  text: "Message"
                        [UIView]
                        [UIView]
                    [_UIInterfaceActionItemSeparatorView_iOS > UIView]
                    [_UIInterfaceActionRepresentationsSequenceView > ... > _UIInterfaceActionCustomViewRepresentationView]
                        [_UIAlertControllerActionView > UIView] label: "OK"
                            [UILabel] label: "OK",  text: "OK"
    

    Android Tree

    [[object CalabashRootView]]
        [PhoneWindow$DecorView > ... > FrameLayout]
            [FitWindowsFrameLayout] id: "action_bar_root"
                [ContentFrameLayout] id: "content"
                    [AlertDialogLayout] id: "parentPanel"
                        [LinearLayout] id: "topPanel"
                            [LinearLayout] id: "title_template"
                                [DialogTitle] id: "alertTitle" text: "Title"
                            [Space] id: "titleDividerNoCustom"
                        [FrameLayout] id: "contentPanel"
                            [NestedScrollView > LinearLayout] id: "scrollView"
                                [AppCompatTextView] id: "message" text: "Message"
                        [ScrollView > ButtonBarLayout] id: "buttonPanel"
                            [AppCompatButton] id: "button2" text: "OK"
    [PhoneWindow$DecorView]
        [LinearLayout > FrameLayout]
            [FitWindowsFrameLayout] id: "action_bar_root"
                [ContentFrameLayout > RelativeLayout] id: "content"
                    [View]
                    [PlatformRenderer]
                        [NavigationPageRenderer] id: "NoResourceEntry-1"
                            [PageContainer > ... > LabelRenderer]
                                [FormsTextView] text: "Welcome to Xamarin Forms!"
                            [Toolbar] id: "toolbar"
                                [AppCompatTextView] text: "DisplayAlertUITest"
        [View] id: "navigationBarBackground"
    
  • hkiddhkidd Member ✭✭

    @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.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    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

  • hkiddhkidd Member ✭✭

    @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!

Sign In or Register to comment.