Skip to content
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

[UI Tests] Minor UI Tests code refactoring. #18349

Merged
merged 6 commits into from
May 8, 2023
Merged

Conversation

pachlava
Copy link
Contributor

@pachlava pachlava commented May 2, 2023

Description

While dealing with recent increase in UI tests fails on FTL, I firstly started looking into the tests code to search for possible improvements. The flakiness was caused by FTL service disruption, however, the changes I made to the code still make sense, IMO.

(This is also an explanation for the misleading branch name).

Each change was made in a separate commit, so it can be reverted, if you find this necessary. I recommend reviewing this PR by looking into commits separately.

Testing

  • CI is green

@pachlava pachlava requested a review from a team as a code owner May 2, 2023 07:38
@pachlava pachlava changed the base branch from trunk to add-domains-card-ui-test May 2, 2023 07:39
@wpmobilebot
Copy link
Contributor

wpmobilebot commented May 2, 2023

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr18349-85ffcbf
Commit85ffcbf
Direct Downloadwordpress-prototype-build-pr18349-85ffcbf.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented May 2, 2023

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr18349-85ffcbf
Commit85ffcbf
Direct Downloadjetpack-prototype-build-pr18349-85ffcbf.apk
Note: Google Login is not supported on these builds.

@pachlava pachlava marked this pull request as draft May 2, 2023 08:52
Comment on lines +23 to +26
// We're not running Stats tests for JP.
// See https://github.com/wordpress-mobile/WordPress-Android/issues/18065
assumeTrue(!BuildConfig.IS_JETPACK_APP)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it was in the original place, the test was skipped for JP, as it should be, but setUp was still executed, which took ~20 seconds. Since there's only one test in this class, keeping it here does not affect any other tests.

Comment on lines -120 to -123
if (isElementDisplayed(R.id.continue_with_wpcom_button) || isElementDisplayed(R.id.login_open_email_client)) {
return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The removed code didn't add much value, IMO, removing it changes nothing in the logic, and it also means two checks less. The method will still logout only if it sees the navbar.

Copy link
Contributor

Choose a reason for hiding this comment

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

can't help but wonder why this was added in the first place, the only reason i could think of is some potential speed improvements (not sure how much though, if any). but looking at it, i would agree with you that it doesn't seem to add much value

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 assume the logic behind this was "firstly, escape the function if we are already in the logged out state". But it turned out that it's faster to check that we are in the logged in state.

Comment on lines -70 to -73
val negativeButton =
Espresso.onView(ViewMatchers.withId(R.id.quick_start_prompt_dialog_button_negative))
WPSupportUtils.waitForElementToBeDisplayed(negativeButton)
WPSupportUtils.clickOn(negativeButton)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clickOn already contains waitForElementToBeDisplayed, so it was redundant here. Also, I went for passing the identifer to the function, instead of the ViewMatcher, to keep it shorter.

@@ -32,7 +32,6 @@ class BlockEditorTests : BaseTest() {
fun e2ePublishSimplePost() {
val title = "publishSimplePost"
MySitesPage()
.go()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After login, the app is already in needed section, no need to go there again.

Comment on lines -62 to -66

@After
fun tearDown() {
logoutIfNecessary()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every setUp method (for all tests) contains logoutIfNecessary, so I saw no value in also having a teardown that does the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

usually the "clean up" happens after the test ends, curious to know your reason for keeping the one in setUp() instead of tearDown()?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd advocate that every test is responsible for setting up the right environment before it starts, and not when it ends. Thus from my experience, it's always more resilient to handle prerequisites in setUp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only LoginTests.kt and SignUpTest.kt contained both setUp and teardDown with logoutIfNecessary, while the remaining five files contain only setUp with logoutIfNecessary. I removed the ones from tearDown because of a smaller footprint.

Copy link
Contributor

Choose a reason for hiding this comment

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

i've personally used both setUp() and tearDown() to "clean up" test states, depending on what it does and what the end states of the tests are. in the case where we are deleting the app (what JPiOS is doing), it would make sense to do it during tearDown() and from your reasoning for this one, this change makes sense to me since it was already in setUp() in the other files 👍

@pachlava pachlava changed the title [UI Tests] Examine flaky tests [UI Tests] Minor UI Tests code refactoring. May 4, 2023
Comment on lines +15 to +18
// We run the class for JP only (so far the class contains
// only a test for Domains card, which in not valid for WP)
assumeTrue(BuildConfig.IS_JETPACK_APP)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All changes in this file is a cherry-pick from #18349

Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean to link to a different PR/commit? currently that link is this PR

Copy link
Contributor Author

@pachlava pachlava May 8, 2023

Choose a reason for hiding this comment

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

Yes, sorry, I meant #18365

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant #18365

Are you sure? That PR wasn't yet merged.

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'm sorry, @ovitrif. I hope third time's a charm 😅: #18345

@pachlava pachlava added the UI Tests Anything related to automated UI Tests. label May 4, 2023
@pachlava pachlava added this to the Future milestone May 4, 2023
@pachlava pachlava marked this pull request as ready for review May 4, 2023 07:17
Base automatically changed from add-domains-card-ui-test to trunk May 4, 2023 11:31
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 making these updates and removing those unnecessary lines @pachlava! since this involves multiple tests, i'm depending on the CI results for this.

the only outstanding question i have is on the position of logoutIfNecessary(), the other changes look good to me!

Comment on lines +15 to +18
// We run the class for JP only (so far the class contains
// only a test for Domains card, which in not valid for WP)
assumeTrue(BuildConfig.IS_JETPACK_APP)

Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean to link to a different PR/commit? currently that link is this PR

Comment on lines -62 to -66

@After
fun tearDown() {
logoutIfNecessary()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

usually the "clean up" happens after the test ends, curious to know your reason for keeping the one in setUp() instead of tearDown()?

Comment on lines -120 to -123
if (isElementDisplayed(R.id.continue_with_wpcom_button) || isElementDisplayed(R.id.login_open_email_client)) {
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can't help but wonder why this was added in the first place, the only reason i could think of is some potential speed improvements (not sure how much though, if any). but looking at it, i would agree with you that it doesn't seem to add much value

@pachlava
Copy link
Contributor Author

pachlava commented May 8, 2023

the only outstanding question i have is on the position of logoutIfNecessary(), the other changes look good to me!

Thank you for the review, @jostnes 🙇 I answered the question, hope it makes sense. Could you please take another look? Thanks!

@pachlava pachlava requested a review from jostnes May 8, 2023 09:40
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.

CI is ✅ :shipit:

@pachlava pachlava merged commit 0c64cb8 into trunk May 8, 2023
18 checks passed
@pachlava pachlava deleted the examine-flaky-tests branch May 8, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI Tests Anything related to automated UI Tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants