gpt4 book ai didi

ios - XCUIElement tap() 不工作

转载 作者:IT王子 更新时间:2023-10-29 05:41:17 27 4
gpt4 key购买 nike

我有一个非常简单的 XCTestCase 实现,它测试按钮上的点击并期望出现 Alert Controller 。问题是 tap() 方法不起作用。在关联按钮的 IBAction 中放置一个断点,我意识到逻辑甚至没有被调用。

class uitestsampleUITests: XCTestCase {

var app: XCUIApplication!

override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}

func testButton() {
let button = app.buttons["Button"]
button.tap()

expectationForPredicate(NSPredicate(format: "exists == 1"), evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5.0, handler: nil)
}
}

此外,复制 button.tap() 指令使测试通过,如下所示:

    func testButton() {
let button = app.buttons["Button"]
button.tap()
button.tap()

expectationForPredicate(NSPredicate(format: "exists == 1"), evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5.0, handler: nil)
}

我在 Xcode 7.3.1 中遇到了这个问题,我错过了什么吗?是错误吗?

最佳答案

所以一位 Apple 工程师回应了我的错误报告说:

The second possibility is that you are running into a problem that sometimes occurs where the application finishes launching but the splash screen doesn't immediately disappear and events dispatched to the app are not handled properly.

To try to work around that issue, consider placing a small delay at the beginning of your test (sleep(1) should be enough).

所以我做到了,现在可以了:

override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
sleep(1)
}

关于ios - XCUIElement tap() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37276597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com