Does anybody have a working example of waiting for a MessageView to appear and validating its content in a UI Test?
I'm now waiting for the string to show up in app.staticTexts but that is not working.
Can you post your test function?
I have:
func testLogin_Failed() {
launchApp(.stub(.loginFailed))
playLogin("meh", password: "no")
// let expected = localizedString("Login.EnteredEmailOrPasswordWasWrong")
let expected = "Please try again."
XCTAssert(waitForElementToAppear(app.staticTexts[expected]))
}
and
func waitForElementToAppear(_ element: XCUIElement) -> Bool {
let predicate = NSPredicate(format: "exists == true")
let exp = expectation(for: predicate, evaluatedWith: element, handler: nil)
let result = XCTWaiter().wait(for: [exp], timeout: 10.0)
return result == .completed
}
I haven't had time to look at this and I'm not a UI testing expert. You might have better luck on StackOverflow
Hi @alper,
I could solve it by doing something like this:
let element = app.otherElements[expected].waitForExistence(timeout: 5)
Cheers.
For some reason the string in otherElements has the prefix [Title], so I changed it to:
let expected = "Username or password not valid. Please try again."
let predicate = NSPredicate(format: "label CONTAINS[c] %@", expected)
XCTAssert(waitForElementToAppear(app.otherElements.containing(predicate).firstMatch))
and that seems to work.
Unfortunately waitForElementToAppear is too slow for SwifMessages that automatically disappear after 1 second.
Does anybody know how to solve this for UI testing?
Most helpful comment
Hi @alper,
I could solve it by doing something like this:
Cheers.