2

We are currently implementing Open Id Connect in our Xamarin App. Therefore we also want to adjust the UI-Tests to do the login inside of a browser with Xamarin.UITest.

But when we try to query the username and password input fields with the c => c.CSS(".css-selector") selector like described here no results are returned. This is happening inside of ASWebAuthenticationSession on iOS and as well on ChromeCustomTabs on Android.

Here the code for selecting the elements:

            App.EnterText(c => c.Css("input[type=\"email\"]"), "username");
            App.EnterText(c => c.Css("input[type=\"password\"]"), "password");
            App.DismissKeyboard(); // On smaller screen the login button might be hidden below the keyboard otherwise
            App.Tap(c => c.Css("button[type=\"submit\"]"));

I also tried to use another selector like "div" or "body" but nothing is returned.

The error looks like this Unable to enter text. Query for Css("input[type="email"]") gave no results.

In the end is for iOS a SFSafariView rendered as here in the tree output.

[CalabashRootView > UIWindow]                                                                        
  [UITransitionView > UIDropShadowView]
    [UIView > UIScrollView]
      [UIView]
        [UIImageView] id: "login_logo.png"
        [UIView]
          [UIImageView] id: "loading_spinner.png"
      [_UIScrollViewScrollIndicator > UIView] label: "Vertical scroll bar, 1 page",  text: "0%" (center not on screen)
      [_UIScrollViewScrollIndicator > UIView] label: "Horizontal scroll bar, 1 page",  text: "0%" (center not on screen)
    [UIDimmingView]
  [UITransitionView]
    [UIDimmingView]
    [UIDropShadowView > ... > SFSafariView]
      [SFSafariLaunchPlaceholderView]
        [UINavigationBar]
          [_UIBarBackground]
            [_UIBarBackgroundShadowView > _UIBarBackgroundShadowContentImageView]
            [UIVisualEffectView > _UIVisualEffectBackdropView]
          [_UINavigationBarContentView]
        [UIToolbar > _UIBarBackground] id: "Toolbar"
          [_UIBarBackgroundShadowView > _UIBarBackgroundShadowContentImageView]
          [UIVisualEffectView > _UIVisualEffectBackdropView]
      [_UISizeTrackingView]
        [_UIRemoteView] id: "RemoteViewBridge"

Am I missing a step or is there another way to test those scenarios?

Oliver
  • 437
  • 6
  • 18
  • Can you also share the tree for Android? UITest for web views haven’t been the most successful. I would suggest placing a check so that it skips the open id authentication during UITests – Saamer Dec 16 '19 at 14:29
  • I opened a ticket at Microsoft: https://github.com/MicrosoftDocs/appcenter-docs/issues/859 however I don't think they know if it works themselves. – Oliver Jul 06 '20 at 07:19
  • I am having the same issue. i want to write a uitest for an oauth process inside a chrome custom tab, but i have no means of accessing it with app.query(). Is there anything new on this topic? i could not find any solution in the web so far. – Maverick1st Jun 10 '21 at 13:54
  • I think it's not possible and should actually not be possible to access those save browsers. Anyway, we implemented a backdoor to inject a webkit WebView as the browser for authentication. See: https://learn.microsoft.com/en-us/appcenter/test-cloud/frameworks/uitest/features/backdoors – Oliver Jun 10 '21 at 17:04
  • If you access the page in a desktop browser you can see the html classes. you can access using the .Class() and .CSS() methods – shookdiesel Apr 29 '22 at 14:00
  • @shookdiesel - this is exactly this is not working inside of the safe web views. Which actually makes sense. – Oliver Jun 07 '22 at 12:00

1 Answers1

0

It's not possible to read out safe web views. These web views were created so that users could log in inside a safe environment to which the App itself has no access. So it's a good thing the queries do not work.

Either use a backdoor to inject an unsafe web view for the UI tests or use the Client Credentials flow if you need a token to communicate with your API. The production apps should use PKCE, though.

Oliver
  • 437
  • 6
  • 18