zalando / SwiftMonkey

A framework for doing randomised UI testing of iOS apps
MIT License
1.95k stars 175 forks source link

Function Does Not Work for Location Services Popup #61

Closed singh88 closed 4 years ago

singh88 commented 6 years ago

https://github.com/zalando/SwiftMonkey/blob/d5cf6447288646a39471303172394b7ad4d83e89/SwiftMonkey/MonkeyXCTest.swift#L30

This function works fine for all other alerts such as alerts generated by application under test but it does not tap on the location services pop up. When I debugged the issue I found that alert.count is returning 0 when location pop up appears that caused the skipping of this function. If we can find a way to identify location pop-ups, which are not different from any other alert types, then this issue will be resolved.

I tried using the alert description to identify the alert and in that case tap worked just fine but other than that I was not able to identify alerts if I am not using alert description.

This is the pop up I was referring

screen shot 2018-07-06 at 4 59 22 pm
singh88 commented 6 years ago

@wojciechczerski could you please help me with this issue? Since this is a very strange issue which just happens for Keyboard alerts and location alerts.

wojciechczerski commented 6 years ago

@singh88 I've spent some time investigating the issue you've described. Indeed alert.count does not include system alerts. To react on them you need to call addUIInterruptionMonitor(withDescription:handler:) and provide a handler closure to execute when a system alert is shown. The handler is called with with an XCUIElement that represents the top level UI element for the alert. From this point you can just query the buttons collection, pick a random one and tap it. However there is an issue...

The system alerts (or maybe any alert?) are dismissed when you trigger a tap gesture. I've created the CLLocationManager to show the "Location alert" and when it was visible I paused the test and manually executed application.tap(). This caused the alert to be dismissed. Since SwiftMonkey is executing random actions with taps (addDefaultXCTestPrivateActions) even if you register this "interrupt monitor" the alert will dismissed almost immediately and you'r handler won't be called.

Unfortunately I wasn't able to find any solution 😞. I thought that I could prevent SwiftMonkey from tapping if a system alert is visible but I could not find any method that would enable detecting that such an alert is visible.

singh88 commented 6 years ago

@wojciechczerski yeah!! yeah, your right. I have tried addUIInterruptionMonitor(withDescription:handler:) too and as per your description it did not work for the use case.

wojciechczerski commented 4 years ago

Closing due to inactivity. Please reopen the issue if you think it should be addressed.