I'm trying to create UI tests for my app using EarlGrey 2.0 framework while using Swift language for those tests. However, I can't find a solution for tapping on a system alert, although EG 2.0 should support them. To be more specific, it is the native location iOS permission dialog when the app launches. Has anyone done this already? Any ideas? Thank you.
Asked
Active
Viewed 469 times
0
-
2Use the System Alert Handler? https://github.com/google/EarlGrey/blob/earlgrey2/TestLib/AlertHandling/XCTestCase%2BGREYSystemAlertHandler.h Check this test - https://github.com/google/EarlGrey/blob/earlgrey2/Tests/Functional/Sources/SystemAlertHandlingTest_IOS13OrLater.m – gran_profaci Apr 05 '20 at 23:10
-
Thank you, this helped me a bit. – redearz Apr 06 '20 at 19:43
2 Answers
3
Here's the full code of a test accepting native system alert in Swift
func testExample() {
let app = XCUIApplication()
app.launch()
XCTAssertTrue(grey_wait(forAlertVisibility: true, withTimeout: 2))
XCTAssertTrue(grey_acceptSystemDialogWithError(nil))
XCTAssertTrue(grey_wait(forAlertVisibility: false, withTimeout: 1))
}

redearz
- 135
- 1
- 9
0
Here is an extension I used to check if a system alert is shown, and accept it if it is.
import EarlGrey
extension UITestCase {
public func acceptSystemAlertIfPresent() {
let systemAlertShown = grey_wait(forAlertVisibility: true, withTimeout: 2)
if systemAlertShown {
grey_acceptSystemDialogWithError(nil)
}
}
}

trishcode
- 3,299
- 1
- 18
- 25