Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tap OK button in permission dialog that required to access to photos on iOS using Xamarin.UITest?

Tags:

ios

xamarin

I am using Xamarin.UITest to execute automation on iOS app.

The problem is that: while accessing gallery to upload a photo, there is a permission dialog and i need to tap "OK" button to dismiss it.

The following ways that i tried, but they didn't work:

  • Using tree command does not show hierarchy of that dialog, so that i can not locate UI element to automate

  • Using iOSApp.InvokeUia("UIATarget.localTarget().frontMostApp().alert().buttons()[\"OK\"].tap()"); This shown error: UIATarget.localTarget().frontMostApp().alert().buttons()["OK"] could not be tapped because the element is not visible tap@[native code]

  • Using app.TapCoordinate, it seems that it is able to work, but have to know the correct coordinate depends on different screens and when dialog appears.

Are there any solution to work on this problem? Thanks.

like image 711
Phuc Thai Avatar asked May 19 '15 04:05

Phuc Thai


2 Answers

System dialogs for permissions are outside the scope of the app and won't show up in tree or any other query that you can do through UITest. Instead, these are typically handled automatically by calabash. The "automatic" behavior is to accept any permission dialog that appears.

Is your dialog in a different language where "OK" might be displayed in a non-english language? If so, we may need to file an issue for that specific locale so it can be implemented.

Also, make sure you have the latest UITest version. Take a look at the changes for iOS 10 and InvokeUia here.

like image 176
therealjohn Avatar answered Nov 02 '22 20:11

therealjohn


try this: target.frontMostApp().mainWindow().elements()[0].elements()[2].elements()[1].tap()

like image 30
woof Avatar answered Nov 02 '22 21:11

woof