0
从这个website窃取帮助,我已经实现此修复程序来运行一个小的等待函数,所以我可以确保我等待元素/页面/等等。在继续测试之前加载。修复工程应该直接在测试中使用代码,但是当我将它放在另一个类的Utility Method中时,它不会返回正确的通过/失败结果。用户界面测试断言作为实用工具方法不会返回失败(Xcode 8,Swift 3)
的问题是运行下面的代码时:
func testCreateGame() {
let app = LauncherUtilityMethods.startApp()
AllStageUtilityMethods().waitForElement(app.buttons["THISDOESNOTEXIST"])
此元素不存在,但我还是会看到一个测试通过。 这里是实用方法:
func waitForElement(_ element: XCUIElement, file: String = #file, line: UInt = #line) {
let exists = NSPredicate(format: "exists == true")
expectation(for: exists, evaluatedWith: element, handler: nil)
waitForExpectations(timeout: 5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
self.recordFailure(withDescription: message, inFile: file, atLine: line, expected: true)
XCTFail()
}
}
之后我插入直接XCTFail()if语句,测试将随后失败/据此通过。有没有更好的方法来处理这种情况?有效地使我的测试失败两次似乎是多余的,但只有一次才能真正表现为失败。
我想我可能只是在XCTFail添加说明,但是这是一个不太雅致的方法,因为实际.recordFailure选项。 感谢您的帮助!
调用工作的梦想。谢谢!我还没有测试waitForElementToDisappear代码,但我做了一小段代码和我的代码组合,以获得我首选的错误消息(在测试本身上) –
很高兴帮助:) – Shahid