Xamarin.UITests - testing on a real device - iOS application permissions pop-ups

I have an iOS app that needs some privileges (GPS, Push notifications). When the application is launched for the first time, iOS asks the user if they support these permissions for the application. I have written several UITests and want to automate their launch on a locally connected iPhone.

The problem is that I cannot override issues with permissions, and my tests failed. I found out that the application deployed by the IDE (Xamarin Studio) will request permissions, but the application deployed through UITests will not. So I tried with .AppBundle(path_to_app) , but it says that this is only valid for deployment in Simulator.

SetUp: System.Exception: This application package is not valid for running the simulator. To resolve this issue, make sure your target device is a simulator. DTPlatformName is "iphoneos" and not "iphonesimulator" in Info.plist applications.

Like an attempt to deploy the iPhone app for Simulator. But Target in Xamarin Studio is configured on a real device. I tried to add .DeviceIdentifier . When used with .InstalledApp it starts (still asking for permission). But when I used DeviceIdentifier and AppBundle , the error described above occurred.

My tests work fine on a test cloud. They work great on Simulator. They work great when I manually deploy the device, run the application and approve permissions, and then run the user interface tests.

What I cannot achieve is to force UITests to redefine rights issues on a real device. Has anyone done this job?

The last thing I found is in the documentation for the AppBundle method "Will make it work on the simulator" https://developer.xamarin.com/api/member/Xamarin.UITest.Configuration.iOSAppConfigurator.AppBundle/p/System.String/

So, I can be doomed to the task, but maybe someone knows a workaround?

+7
ios iphone ui-testing xamarin.uitest
source share
2 answers

You can cancel system dialogs using UITest using InvokeUIA. The following test works by clicking the OK button of the iOS system alert:

 [Test] public void AppLaunches () { app.Screenshot ("First screen."); app.InvokeUia ("uia.query('[:view {:marked \"OK\"}]')"); app.InvokeUia ("uia.tapMark(\"OK\")"); } 

A working sample application and UITest are also here: https://github.com/King-of-Spades/InvokeUia-for-System-Dialogs

Warning about system dialogs in the test cloud

The reason you don't see this problem in the test cloud is because Test Cloud automatically rejects system alerts; so usually you don’t need to worry about it. However, if your warning is triggered too soon; so that it appears before the automation has fully launched your application, then it will not be able to detect and reject the warning and cause the test to fail.

Thus, you want to make sure that when you run the application in the test cloud, the delay in the permission request is delayed, or you can even turn them off if they are clearly not needed for a particular test. More information can be found in this Calabash manual: https://github.com/calabash/calabash-ios/wiki/Managing-Privacy-Alerts%3A--Location-Services%2C-APNS%2C-Contacts

(Although this is Calabash, you can use the same strategy in UITest, albeit with C # syntax.)

Update for Xcode 8 / iOS 10

Xcode 8 / iOS 10 removed UIAutomation, so the InvokeUIA workaround will only continue if you use Xcode 7 and iOS 7-9. References:

+5
source share

For real devices, you do not need any of them.

  { app = ConfigureApp .iOSAppBundle .StartApp(); } 

This piece of code is good enough if you are connecting a real device to the system, then select this before starting.

0
source share

All Articles