-
Notifications
You must be signed in to change notification settings - Fork 1
Don't explicitly fail the tests during init if the screen is not loaded
#8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d5c95e2
ece1e7e
4547368
58b4805
93fc87c
650e4a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ import XCTest | |
| // and those are obviously specific to each screen, hence should be added by each subclass. | ||
| open class ScreenObject { | ||
|
|
||
| public enum WaitForScreenError: Equatable, Error { | ||
| case timedOut | ||
| } | ||
|
|
||
| /// The `XCUIApplication` instance this screen is part of. This is the value passed at | ||
| /// initialization time. | ||
| public let app: XCUIApplication | ||
|
|
@@ -34,17 +38,31 @@ open class ScreenObject { | |
|
|
||
| @discardableResult | ||
| func waitForScreen() throws -> Self { | ||
| XCTContext.runActivity(named: "Confirm screen \(self) is loaded") { (activity) in | ||
| let result = waitFor(element: expectedElement, predicate: "isEnabled == true", timeout: 20) | ||
| XCTAssert(result, "Screen \(self) is not loaded.") | ||
| try XCTContext.runActivity(named: "Confirm screen \(self) is loaded") { (activity) in | ||
| let result = waitFor( | ||
| element: expectedElement, | ||
| predicate: "isEnabled == true", | ||
| timeout: self.waitTimeout | ||
| ) | ||
|
|
||
| guard result == .completed else { throw WaitForScreenError.timedOut } | ||
| } | ||
| return self | ||
| } | ||
|
|
||
| private func waitFor(element: XCUIElement, predicate: String, timeout: Int = 5) -> Bool { | ||
| let elementPredicate = XCTNSPredicateExpectation(predicate: NSPredicate(format: predicate), object: element) | ||
| let result = XCTWaiter.wait(for: [elementPredicate], timeout: TimeInterval(timeout)) | ||
|
|
||
| return result == .completed | ||
| private func waitFor( | ||
| element: XCUIElement, | ||
| predicate: String, | ||
| timeout: TimeInterval | ||
| ) -> XCTWaiter.Result { | ||
| XCTWaiter.wait( | ||
| for: [ | ||
| XCTNSPredicateExpectation( | ||
| predicate: NSPredicate(format: predicate), | ||
| object: element | ||
| ) | ||
| ], | ||
| timeout: timeout | ||
| ) | ||
| } | ||
|
Comment on lines
+53
to
67
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a minor line length and style change. I decided to return the I didn't just inline this code in the consumer function because I can see us using this more in the future.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a nice change! |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of failing the tests in here, simply
throwan error.This allows consumers to
catchthe error if needed to continue the test execution.