Skip to content

Conversation

@tiagomar
Copy link
Contributor

@tiagomar tiagomar commented Jul 20, 2023

Description

The objective of this PR is to make disableAutoFillPasswords() run only once before all the whole suite as the change is persisted in the simulators and doesn't need to run before each test. It was done by adding a TestObserver and running disableAutoFillPasswords()
within testBundleWillStart(_:). h/t to @mokagio for the tip!
I also added some waiting for the elements because, even though it will run only once per simulator, it's still navigating through UI and still can be impacted by eventual CI slowness.

Testing

Ci should be 🟢

@tiagomar tiagomar added the Testing Unit and UI Tests and Tooling label Jul 20, 2023
@tiagomar tiagomar added this to the Someday milestone Jul 20, 2023
@tiagomar tiagomar requested a review from mokagio July 20, 2023 04:51
Comment on lines +14 to +20
func executeWithRetries(_ operation: () -> Bool) {
var retryCount = 3

while !operation() && retryCount > 0 {
retryCount -= 1
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retrying to be on the safer side as all the tests would fail in case this is not disabled. I have seen it happening a couple times in a week.
I tried to make it reusable as we might need to change other setting in the future.

Comment on lines 29 to 33
guard passwordsMenuItem.waitForIsHittable() else {
XCTFail("SetUp Failed: Passwords menu item was not hittable in Settings.")
return false
}
settings.staticTexts["Passwords"].tap()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few guards like this which I'd like to DRY it but I couldn't use waitAndTap( _ element: XCUIElement, maxRetries: Int = 10, timeout: TimeInterval = 10) from Globals.swift. It worked when I added JetpackUITests Target Membership to Globals.swift, but It broke a dozen of other things. 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe we can add it as a private func in the same class to call in this method, it won't be reusable elsewhere but at least it's reusable here. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I started doing it and then I noticed I was almost duplicating waitForIsHittable(), struggling with the Boolean returns to control the retry flow, and all of that because of the XCTFail(String) messages that would only help debugging locally. Since the local logs are enough to debug a possible issue, I decided to make it simple and rely on waitForIsHittable().
Changed in 798de02.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 20, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21148-fb8d77d
Version22.8
Bundle IDcom.jetpack.alpha
Commitfb8d77d
App Center Buildjetpack-installable-builds #5505
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 20, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21148-fb8d77d
Version22.8
Bundle IDorg.wordpress.alpha
Commitfb8d77d
App Center BuildWPiOS - One-Offs #6475
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.


let passwordOptions = settings.staticTexts["Password Options"]
guard passwordOptions.waitForIsHittable() else {
XCTFail("SetUp Failed: Password Options was not hittable in Passwords.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added these XCTFail(String) mostly for local debugging as it doesn't actually make the tests fail because it runs before the test bundle even start.

Copy link
Contributor

@jostnes jostnes left a comment

Choose a reason for hiding this comment

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

👋 @tiagomar, thanks for improving the implementation! just looking at the bonus time savings is already satisfying 💯

image

i added some comments, nothing blocking. and also an additional question about removeTestObserver(_:) (also TIL about TestObserver) since it is added at the start of the test run, do we need to remove it at the end of the test run?

Comment on lines 3464 to 3466
EA85B7AB2A686C7A0096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
EA85B7AF2A688AB00096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
EA85B7B02A688B1C0096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
Copy link
Contributor

Choose a reason for hiding this comment

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

are these expected, or are leftovers from adding/removing the file multiple times?

(if it's the latter, which always happens to me, i usually discard all changes in the ./project.pbxproj before submitting the changes and rebuild the project so the references will be added to the right place in the file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!! 👏
I did remove one of them in 937cae8, the other two are related to JetpackUI Tests and WordPressUITests build phase references.


func disableAutoFillPasswords() -> Bool {
let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settings.terminate()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this .terminate() here? If this will be run once at the start of the test run, is this necessary? I'm thinking there's nothing to terminate at that point but I could be missing something.

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 needed in a retry case if something goes wrong in the first execution and also to make our lives easier when running multiple times locally. =]

I added a comment in 798de02.

Comment on lines 29 to 33
guard passwordsMenuItem.waitForIsHittable() else {
XCTFail("SetUp Failed: Passwords menu item was not hittable in Settings.")
return false
}
settings.staticTexts["Passwords"].tap()
Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe we can add it as a private func in the same class to call in this method, it won't be reusable elsewhere but at least it's reusable here. wdyt?

@tiagomar tiagomar marked this pull request as ready for review July 20, 2023 18:10
@tiagomar tiagomar requested a review from a team as a code owner July 20, 2023 18:10
@tiagomar tiagomar requested a review from jostnes July 20, 2023 21:16
Copy link
Contributor

@jostnes jostnes left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments, the changes look good! :shipit:

@tiagomar tiagomar merged commit e531eac into trunk Jul 21, 2023
@tiagomar tiagomar deleted the ui-tests-before-all branch July 21, 2023 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing Unit and UI Tests and Tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants