Created
May 15, 2019 23:33
-
-
Save quangDecember/37e2902e4d74855349921eefc96f13ab to your computer and use it in GitHub Desktop.
wait for existence in UI testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
class BaseTestCase: XCTestCase { | |
let app = XCUIApplication() | |
// ... | |
func waitforExistence(element: XCUIElement, file: String = #file, line: UInt = #line) { | |
let exists = NSPredicate(format: "exists == true") | |
expectation(for: exists, evaluatedWith: element, handler: nil) | |
waitForExpectations(timeout: 30) {(error) -> Void in | |
if (error != nil) { | |
let message = "Failed to find \(element) after 30 seconds." | |
self.recordFailure(withDescription: message, | |
inFile: file, atLine: Int(line), expected: true) | |
} | |
} | |
} | |
} |
how is this better than waitForExistence? is it faster?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice helper function. I turn it into a protocol to make it reusable for what it's worth: