Vla*_*nev 2 xctest swift xctestexpectation xcode-ui-testing
寻找一种等待直到页面上不再存在指定元素的帮助编写方法。SWIFT 2.2,XC测试。据您所知,我在这里和编程领域都是新手,感谢您的帮助。
我为此编写了一个超级简单的waitForNonExistence(timeout:)
扩展函数XCUIElement
,它反映了现有的XCUIElement.waitForExistence(timeout:)函数,如下所示:
extension XCUIElement {\n\n /**\n * Waits the specified amount of time for the element\xe2\x80\x99s `exists` property to become `false`.\n *\n * - Parameter timeout: The amount of time to wait.\n * - Returns: `false` if the timeout expires without the element coming out of existence.\n */\n func waitForNonExistence(timeout: TimeInterval) -> Bool {\n \n let timeStart = Date().timeIntervalSince1970\n \n while (Date().timeIntervalSince1970 <= (timeStart + timeout)) {\n if !exists { return true }\n }\n \n return false\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n
您将必须针对要测试的条件设置谓词:
let doesNotExistPredicate = NSPredicate(format: "exists == FALSE")
Run Code Online (Sandbox Code Playgroud)
然后在测试用例中为谓词和UI元素创建期望:
self.expectationForPredicate(doesNotExistPredicate, evaluatedWithObject: element, handler: nil)
Run Code Online (Sandbox Code Playgroud)
然后等待您的期望(指定超时,如果未达到期望,在此之后测试将失败,这里我使用5秒钟):
self.waitForExpectationsWithTimeout(5.0, handler: nil)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2066 次 |
最近记录: |