iOS UI Automation: assertion's error of text field (highlighted in red color) via CTAssertTrue

93 Views Asked by At

During the automation of the email's changing case, there was a problem with the assertion of the element " text field highlighted in red ". Can you please give some advices to assert this element?

How did we try to solve the problem:

  • via function "waitForText":
func waitForText(name: String) {
        waitForElementToAppear(app.staticTexts[name])
    }

"waitForText" function is short case of "waitForElementToAppear"'s implementation:

func waitForElementToAppear(_ element: XCUIElement) -> Bool{
    let predicate = NSPredicate(format: "exists == true")
    let expectat = expectation(for: predicate, evaluatedWith: element, handler: nil)
    let result = XCTWaiter().wait(for: [expectat], timeout: 20)
    return result == .completed
} 
  • via function "waitForTextShort":
func waitForTextShort(name: String) {
        waitForElementToAppearShort(app.staticTexts[name])
    }

"waitForTextShort" function is short case of "waitForElementToAppearShort"'s implementation:

func waitForElementToAppearShort(_ element: XCUIElement) -> Bool{
        let predicate = NSPredicate(format: "exists == true")
        let expectat = expectation(for: predicate, evaluatedWith: element, handler: nil)
        let result = XCTWaiter().wait(for: [expectat], timeout: 5)
        return result == .completed
    }
  • via CTAssertTrue:
CTAssertTrue (app.staticTexts.element (match: .any, id: "Enter your email address"). exists)

Finding items with a UI tests recorder only displays the input field, but not required field.

Unloading elements via po app.staticTexts in test's runtime also does not give the desired results:

 StaticText, {{16.0, 130.0}, {288.0, 16.5}}, tag: "Enter your email address"

Used locators:

app.tables/*@START_MENU_TOKEN@*/.staticTexts["Enter your email address"]/*[[".cells.staticTexts[\"Enter your email address\"]",".staticTexts[\"Enter your email address\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
1

There are 1 best solutions below

0
seaSponge On

Solved: just ask your developer to add some identifier to the required element - and assert it easily :)