Amjad Husseini
Amjad Husseini

Reputation: 495

XCTest is not giving me accurate results each time (Sometimes it fails, sometimes it passes)

I am using XCode 8.2.1 (Swift) with XCode UI tests to test my app in terms of UI, so my problem with this tool is it doesn't give me accurate results some tests are passed and at the next time they fail.

My question might be generic but is this problem related to me or is it common one? i believe this happened after migrating to XCode 7+

Do you guys recommend using anther tool for UI tests other than this one? as am looking for faster, accurate and ability to integrate with a CI server.

Upvotes: 0

Views: 428

Answers (1)

lpd
lpd

Reputation: 175

private func waitForElementToAppear(element: XCUIElement,
                                    file: String = #file, line: UInt = #line) {
    let existsPredicate = NSPredicate(format: "exists == true")
    expectation(for: existsPredicate,
                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: line, expected: true)
        }
    }
}

invoke this method and avoid test fails because sometimes our UI takes more time to getting result from Server.

Upvotes: 1

Related Questions