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

[Screenshots Automation] Fix locales switching #6834

Merged
merged 5 commits into from Jul 1, 2022

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Jun 29, 2022

Part of #6833

Description

This PR fixes locale switching for screenshot generation, it adds the following changes to do so:

Regarding the last point, I asked in the LeakCanary repo about their opinion about integrating the same logic in the library itself, as the heap dumping ana analysis is already disabled by the library during tests, it's just that it attaches the watchers.

Testing instructions

Confirm Locale switching works as expected
  1. Execute the following command: bundle exec fastlane take_screenshots
  2. Confirm the UI tests are executed and the device's language is changed for each iteration.
Confirm LeakCanary is initialized well for debug builds
  1. Launch a debug build of the app.
  2. Check logcat and confirm the presence of line: "Installing LeakCanary"
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-woocommerce
Copy link

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@hichamboushaba hichamboushaba added the category: ui tests Related to UI testing. label Jun 29, 2022
import com.woocommerce.android.util.WooLog
import leakcanary.AppWatcher

internal class LeakCanaryInstaller : ContentProvider() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This follows the same logic as leak-canary's default artifact in using a ContentProvider for the initialization, the change is that we can have custom logic for the initialization now.

@@ -20,7 +20,7 @@ object PackageUtils {
fun isTesting(): Boolean {
if (isTesting == null) {
isTesting = try {
Class.forName("com.woocommerce.android.viewmodel.BaseUnitTest")
Class.forName("org.junit.Test")
Copy link
Member Author

Choose a reason for hiding this comment

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

With this change, this function detects both UI tests and unit tests.

@hichamboushaba hichamboushaba marked this pull request as ready for review June 29, 2022 17:28
@peril-woocommerce
Copy link

Warnings
⚠️ PR is not assigned to a milestone.

Generated by 🚫 dangerJS

@wpmobilebot
Copy link
Collaborator

You can test the changes on this Pull Request by downloading an installable build, or scanning this QR code:

@codecov-commenter
Copy link

codecov-commenter commented Jun 29, 2022

Codecov Report

Merging #6834 (b0b7d01) into trunk (806e2df) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##              trunk    #6834      +/-   ##
============================================
- Coverage     44.38%   44.37%   -0.01%     
  Complexity     2972     2972              
============================================
  Files           535      536       +1     
  Lines         29598    29604       +6     
  Branches       3902     3902              
============================================
  Hits          13137    13137              
- Misses        15243    15249       +6     
  Partials       1218     1218              
Impacted Files Coverage Δ
...lin/com.woocommerce.android/LeakCanaryInstaller.kt 0.00% <0.00%> (ø)
...n/com/woocommerce/android/support/ZendeskHelper.kt 0.00% <0.00%> (ø)
...e/android/ui/moremenu/domain/MoreMenuRepository.kt 0.00% <0.00%> (ø)
...otlin/com/woocommerce/android/util/PackageUtils.kt 5.00% <0.00%> (+1.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 806e2df...b0b7d01. Read the comment docs.

@hichamboushaba hichamboushaba mentioned this pull request Jun 29, 2022
3 tasks
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.

Huge thanks for working on the broken locales switching and the crash, @hichamboushaba!

From my side, I'm providing only the testing review, but not commenting on the code. I followed your suggestions here:

Confirm Locale switching works as expected

  1. Execute the following command: bundle exec fastlane take_screenshots
  2. Confirm the UI tests are executed and the device's language is changed for each iteration.

Confirm LeakCanary is initialized well for debug builds

  1. Launch a debug build of the app.
  2. Check logcat and confirm the presence of line: "Installing LeakCanary"
  • The app no longer crashes while running the screenshots for the second time (for a different theme)
  • Locales are switching:

Screenshot 2022-06-30 at 14 35 12

  • "Installing LeakCanary" is present in Logcat for debug build variant:

Screenshot 2022-06-30 at 14 34 44

So, all these worked as expected 👍

I, however, saw several issues related to the screenshot test running under certain locales (Arabic, Japanese, ...), when the test was interrupted and failed. This is something I need to take a look into, but it has nothing to do with your changes.

@hichamboushaba
Copy link
Member Author

Thanks @pachlava for the review.

I, however, saw several issues related to the screenshot test running under certain locales (Arabic, Japanese, ...), when the test was interrupted and failed. This is something I need to take a look into, but it has nothing to do with your changes.

We need to make changes to the test scenarios, as we are supposed to have different screenshots than the past ones p91TBi-9eM-p2, when I'll get to this step, I'll ask for your help 🙏.

@pachlava
Copy link
Contributor

when I'll get to this step, I'll ask for your help

Got it @hichamboushaba 👍, feel free to ping me when the time comes 🙂

@hichamboushaba
Copy link
Member Author

@0nko can you please check the code before merging this PR? 🙏.

@0nko 0nko self-assigned this Jul 1, 2022
Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

Everything looks good and works as expected 👍 Nice work!

@0nko 0nko merged commit df1fd96 into trunk Jul 1, 2022
@0nko 0nko deleted the screenshots-automation/fix-locales-switching branch July 1, 2022 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: ui tests Related to UI testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants