Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Add XCUIElement helper methods to wait for an NSPredicate#6

Merged
mokagio merged 2 commits intotrunkfrom
wait-for-predicate
Dec 10, 2021
Merged

Add XCUIElement helper methods to wait for an NSPredicate#6
mokagio merged 2 commits intotrunkfrom
wait-for-predicate

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented Dec 9, 2021

Making good on my promise to extract the code originally in WordPress iOS from this comment.

You can see it in action in WordPress iOS here.


public var description: String {
switch self {
case .completed: return "XCTWaiter.Result .completed"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks to this extension when we print an XCTWaiter.Result value, it will print as the text defined here, as opposed to the current default "XCTWaiter.Result".

I bumped into this while debugging a test failure for this work.

I decided not to make this part of the framework to avoid clashing with other CustomStringConvertible conformances that a user of this library might have implemented.

case .interrupted: return "XCTWaiter.Result .interruted"
case .invertedFulfillment: return "XCTWaiter.Result .invertedFulfillment"
case .timedOut: return "XCTWaiter.Result .timedOut"
@unknown default: return "XCTWaiter.Result unknown case – Please file a bug report at https://github.com/Automattic/XCUITestHelpers"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@unknonw default is a Swift that allows enum creators (in this case the Apple team that built XCTWaiter.Result to declare that there might be more cases added in the future and require consumers of the code to handle them somehow.

More details in the Swift feature proposal document.

Comment on lines +14 to +28
XCTAssertEqual(
app.staticTexts["a"].waitFor(
predicate: NSPredicate(format: "isEnabled == true"),
timeout: 2 // Interestingly, on Xcode 13.1, a 1 second timeout results in a failure
),
.completed
)
// Test the opposite scenario must also be true.
XCTAssertEqual(
app.staticTexts["a"].waitFor(
predicate: NSPredicate(format: "isEnabled == false"),
timeout: 2
),
.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.

This approach of adding more assertions (examples) for a single unit of behavior is called triangulation.

One could argue that only having two examples doesn't really triangulate, but 🤷 : another example felt unnecessary.

@pachlava
Copy link

pachlava commented Dec 9, 2021

I think this is a great addition to the framework! I executed the test app tests with no issues. But I can see the fails in related wordpress-mobile/WordPress-iOS/pull/17654, and they seem to happen on iPad only. Since they pass on iPhone, I tend to think that these fails should not be caused by the PR 🤔

@pachlava
Copy link

pachlava commented Dec 9, 2021

One thing I didn't do is running wordpress-mobile/WordPress-iOS/pull/17654 locally. Will try this now.

Copy link

@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.

While the tests from wordpress-mobile/WordPress-iOS/pull/17654 were failing on CI, I still could execute them (made sure that XCUITestHelpers dependency was really using the wait-for-predicate branch) locally on iPhone 13 and iPad (9th Gen) and they passed. Which means the fails are unlikely to be caused by this PR. :shipit:

@mokagio
Copy link
Contributor Author

mokagio commented Dec 10, 2021

Thanks @pachlava . I asked for a review before CI finished, whooops 🙃

The fact that UI tests on iPad failed on both Buildkite and CircleCI is not promising. I'll dig into it...

@mokagio
Copy link
Contributor Author

mokagio commented Dec 10, 2021

The fact that UI tests on iPad failed on both Buildkite and CircleCI is not promising. I'll dig into it...

Those failures were unrelated.

Buildkite showed a weird behavior: It successfully retried a failing tests (via the Xcode Test Plan option), but reported the failure still 🤔

Here's the first failure.

image

And here's the successful retry

image

CircleCI experience a timeout trying to insert some text. I'm not sure what the issue was with that... Clearly yet another flaky test because it passed when I re-run the build 😞

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants