我在UI测试中有一个按钮,可以登录到一个应用中。需要自动化的用户流程是这样的。
我的UI测试代码对于功能测试来说非常简单。
let loginButton = app.buttons["LOG IN"]
let welcomeText = app.staticTexts["Welcome!"]
loginButton.tap()
XCTAssertTrue(welcomeText.waitForExistence(10))
然而,它并没有验证按钮是否是 状态变为 "处理...".
如果我试图在这样的代码中放入一个检查,它就无法工作,因为当UI测试走过屏幕寻找文本的时候,它可能已经消失了。
let loginButton = app.buttons["LOG IN"]
let loginButtonProcessingText = app.buttons.staticTexts["Processing..."]
let welcomeText = app.staticTexts["Welcome!"]
loginButton.tap()
XCTAssertTrue(loginButtonProcessingText.exists)
XCTAssertTrue(welcomeText.waitForExistence(10))
所以我的想法是,我需要以某种方式启动处理测试的检查。同时 与按钮的点击,或者在它之前的一秒钟。
有没有办法在XCUI测试中异步地旋转出这样的检查?
你可以使用 期待 来测试异步任务。但首先如果你像下面这样分开步骤,就可以更清楚了。
let loginButton = app.buttons["LOG IN"]
loginButton.tap()
let loginButtonProcessingText = app.buttons.staticTexts["Processing..."]
XCTAssertTrue(loginButtonProcessingText.exists)
let welcomeText = app.staticTexts["Welcome!"]
XCTAssertTrue(welcomeText.waitForExistence(10))