robotframework-appiumlibrary icon indicating copy to clipboard operation
robotframework-appiumlibrary copied to clipboard

How to handling iOS system alerts with Appiumlibrary

Open shen4549 opened this issue 7 years ago • 12 comments

[XCUITest] The capabilities 'autoAcceptAlerts' and 'autoDismissAlerts' do not work for XCUITest-based tests. Please adjust your alert handling accordingly.

'autoAcceptAlerts' does not useful. Is there any where to handle the alerts by appiumlibrary?

I try to use the keyword "wait until page content element" for waiting the button of alerts by accessibility_id but it doesn't find element.(it show the alerts on phone)

tsk for any help

shen4549 avatar Nov 06 '17 10:11 shen4549

Asking permission for getting location warning I can get the element and can click to confirm. which type of alarm can not be confirmed ?

lalamini avatar Nov 08 '17 02:11 lalamini

I can get the element of button Allow by inspector, but the keyword click element by accessibility_id can't. 2017-11-09 4 29 01

shen4549 avatar Nov 09 '17 08:11 shen4549

alarm:“Bilibili” Would Like to Send You Notifications" Notifications may include alerts, sounds, and icon badges. These can be configured in Settings.

I used the iphone7 , iOS 10.3.2. the version of appium 1.7.1 XCUITestDriver (v2.51.1)

when i am using the appium inspector ,i can get the element accessibility id=Allow,but inspector also show the massage "error Could not find element. Try refreshing page ". I could't find out the reason. 2017-11-09 4 41 00

shen4549 avatar Nov 09 '17 08:11 shen4549

I've been struggling with this for the past week too. I can see the elements from iOS alerts in the source but they can't be clicked on. This is preventing me from running tests on recent versions of iOS.

From what I've read, in Appium, the solution is to call driver.switch_to.alert and interact with the returned object. However, AppiumLibrary does not expose any alert-related keywords.

I believe what should be implemented here is a Handle Alert keyword similar to the one in SeleniumLibrary, and possibly other alert-related keywords.

SmashManiac avatar Nov 09 '17 19:11 SmashManiac

You must clear that what's problem you met. The inspector of appium or the test case in your test suit. The inspector I alse met the problem which made me so crazy, but it never fails my test case. For some weird and unknown problem , accessibility_id won't work well , so , please ask for xpath. if neither xpath nor accessibility_id can work well, then please try iOSNsPredicateString. If none of them can work. Click point can work after all. HaHa~

lalamini avatar Nov 10 '17 05:11 lalamini

Neither accessibility_id and xpath locator strategies work to interact with system alerts, at least on a real device. I assume it's the same for iOSNsPredicateString but I did not verify this because that locator strategy is not currently supported by AppiumLibrary anyway.

As the UI is controlled by the system, X/Y coordinates is not good enough either as they would change depending of the device, iOS version and potentially other system settings. I cannot rely on such a workaround.

@lalamini I'm not sure why your tests pass as your comments are vague and your English is really hard to understand. I suspect you're still using the default UIAutomation framework that has been retired by Apple instead of the XCUITest framework. If not, I would appreciate if you could prove me wrong with a working example.

SmashManiac avatar Nov 14 '17 20:11 SmashManiac

@SmashManiac Sorry for making you hard understand me. then I use automationName=XCUITest to start my application and I use iOSNsPredicateString to catch the alarm message about getting location warning.

lalamini avatar Nov 16 '17 03:11 lalamini

How are you using iOSNsPredicateString in the first place? As I mentioned earlier, according to the AppiumLIbrary documentation, this locator strategy is not supported.

SmashManiac avatar Nov 22 '17 17:11 SmashManiac

Hi, has anyone found a work around for this issue?

teddybearzero avatar Apr 05 '18 15:04 teddybearzero

Hi, I got this problem too, did anyone find a solution for this?

chiahsien avatar Mar 07 '19 10:03 chiahsien

@chiahsien update to version 1.5 and above, use this line of keyword

Click Element       nsp=name=="Allow"

It will trigger a call for this Calling AppiumDriver.findElements() with args: ["-ios predicate string","name==\"Allow\"","8a0cd588-cfac-4356-a6a9-2f10c3fc08ff"]

And the alert will be dismissed.

thepoppingone avatar Mar 15 '19 08:03 thepoppingone

@thepoppingone's solution worked for me, BUT be careful to type 2 whitespaces after Click Element, otherwise Robot thinks that the whole sentence is 1 keyword, resulting in runtime error...

So:

Click Element  nsp=name=="Allow"

and

Click Element  nsp=name=="Don’t Allow"

balazs630 avatar Aug 24 '19 21:08 balazs630

Closing due to inactivity

serhatbolsu avatar Oct 27 '22 08:10 serhatbolsu