IOS UI Test: How to Get a UIAlert Message

My application has a login screen. If the user presses the login button without entering any text in the username or password fields, the application displays a UIAlert message with an error message.

I am trying to model this logic in user interface tests and want to claim that UIAlert is displaying the correct message. However, I cannot find a way to test the user interface to access the Alert message property. Here is the code generated by the test recorder:

func testLoginWithoutPasswort() {
    let app = XCUIApplication()
    let emailTextField = app.textFields["email"]
    emailTextField.tap()
    emailTextField.typeText("xxx@gmail.com")
    app.buttons["Login"].tap()
    app.alerts["Error"].collectionViews.buttons["OK"].tap()
}

Is there anyway I can extract the value of a UIAlert String message, so can I claim to it?

+4
source share
2

. , , ().

, :

Warning called

, " ", :

XCTAssert(app.alerts.element.staticTexts["Final Score: 27 - 25"].exists)

title:

XCTAssertEqual(app.alerts.element.label, "You won!")

, UI Test Cheat Sheet post .

+11

, : alert.elements()[2].name() onAlert callback alert.logElementTree(), AlertView. , , .

0

Source: https://habr.com/ru/post/1615544/


All Articles