Skip to content

Don't explicitly fail the tests during init if the screen is not loaded#8

Merged
mokagio merged 6 commits intotrunkfrom
remove-test-failure
Aug 31, 2021
Merged

Don't explicitly fail the tests during init if the screen is not loaded#8
mokagio merged 6 commits intotrunkfrom
remove-test-failure

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented Aug 26, 2021

Because this logic now lives in a library, we cannot ruthlessly fail the tests anymore and need instead of be more flexible, delegating to the consumer the responsibility to decide whether a test should fail because the ScreenObject instance is not yet loaded.


I based this against add/buildkite because I wanted CI to run on it, but it should be merged only after #6 that one goes into trunk:

@mokagio mokagio force-pushed the remove-test-failure branch from 1e0f3cc to 9e86072 Compare August 26, 2021 05:21
This removes a layer of abstraction.

I haven't inlined the entire function yet just because I can see us
using that flexible wait method in the future.
@mokagio mokagio force-pushed the remove-test-failure branch from 9e86072 to 650e4a7 Compare August 26, 2021 05:26
Comment on lines -39 to +48
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 }
Copy link
Contributor Author

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 throw an error.

This allows consumers to catch the error if needed to continue the test execution.

Comment on lines +53 to 67
private func waitFor(
element: XCUIElement,
predicate: String,
timeout: TimeInterval
) -> XCTWaiter.Result {
XCTWaiter.wait(
for: [
XCTNSPredicateExpectation(
predicate: NSPredicate(format: predicate),
object: element
)
],
timeout: timeout
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 XCTWaiter wait(for:, timeout:) XCTWaiter.Result value instead of doing the check for it to be == .completed to make the consumer code clearer.

I didn't just inline this code in the consumer function because I can see us using this more in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to return the XCTWaiter wait(for:, timeout:) XCTWaiter.Result value instead of doing the check for it to be == .completed to make the consumer code clearer.

This is a nice change!

@mokagio mokagio requested a review from pachlava August 26, 2021 05:26
Base automatically changed from add/buildkite to trunk August 26, 2021 13:51
Copy link
Contributor

@pachlava pachlava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a pleasure to review this PR, thank you for doing this, Gio!
Tested by running two tests included into package - they pass.

Since the PR has no auto-merge enabled, I hope my approval will not spoil the workflow as happened with #6 which should be merged first.

Comment on lines +53 to 67
private func waitFor(
element: XCUIElement,
predicate: String,
timeout: TimeInterval
) -> XCTWaiter.Result {
XCTWaiter.wait(
for: [
XCTNSPredicateExpectation(
predicate: NSPredicate(format: predicate),
object: element
)
],
timeout: timeout
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to return the XCTWaiter wait(for:, timeout:) XCTWaiter.Result value instead of doing the check for it to be == .completed to make the consumer code clearer.

This is a nice change!

@mokagio
Copy link
Contributor Author

mokagio commented Aug 31, 2021

Thanks @pachlava 🙌

@mokagio mokagio merged commit eec3d9a into trunk Aug 31, 2021
@mokagio mokagio deleted the remove-test-failure branch August 31, 2021 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants