sách gpt4 ai đã đi

swift - 如何等待字符数大于零的标 checkout 现 UI 测试

In lại 作者:行者123 更新时间:2023-11-30 13:39:55 27 4
mua khóa gpt4 Nike

实际上,在 api 调用之前,只有 Label 可见且为空文本。获得响应后标签字符计数大于零。但是这里如何等待字符数大于零的标 checkout 现并执行某些操作。

这是我使用的代码,但我收到谓词错误

捕获“NSUnknownKeyException”,“[<_NSCFString 0xjel990> valueForUndefinedKey:]:这不是关键字符的键值编码兼容

func testForWishListCountIsReflecting() {

let app = XCUIApplication()
app.decide()
cellTap()
app.navigationBars["MMRecoPageView"].buttons["MenuButton"].tap()

let wishListLable = app.staticTexts["WishListLabel"]
wishListLable.label.characters

let exists = NSPredicate(format: "label.characters.count > 0")

expectationForPredicate(exists, evaluatedWithObject:wishListLable, handler: nil)

waitForExpectationsWithTimeout(30, handler: nil)


let expectedValue:String = app.staticTexts["WishListLabel"].value as! String
app.buttons["Wishlist"].tap()

XCTAssertTrue(app.tables.cells.count == UInt(expectedValue))

}

1 Câu trả lời

您的问题在错误消息中。 characters() 选择器不能在 NSPredicate 中使用,因为它不适用于 KVO。

this is not key value coding-compliant for the key characters

我建议采取稍微不同的方法。您知道实际的文本应该是什么吗?如果是这样,您可以更改谓词以与其完全匹配。您可以删除手动设置“WishListLabel”辅助功能并让内容自动设置。

func testForWishListCountIsReflecting() {
// ...setup...
let wishListLabel = app.staticTexts["contents of label"]
waitForElementToAppear(wishListLabel)
}

private func waitForElementToAppear(element: XCUIElement, file: String = __FILE__, line: UInt = __LINE__) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate, evaluatedWithObject: element, handler: nil)

waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
self.recordFailureWithDescription(message, inFile: file, atLine: line, expected: true)
}
}
}

关于swift - 如何等待字符数大于零的标 checkout 现 UI 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35694370/

27 4 0
Bài viết được đề xuất: C# Form 在处理信息时卡住
Bài viết được đề xuất: javascript - 在 Google Web Optimizer 页面部分中使用 Javascript
Bài viết được đề xuất: c# - 正确舍入财务数据
Bài viết được đề xuất: javascript - 缩写的正则表达式
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com