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

Add Support for UI Testing the Jetpack app and Compose layouts #17869

Merged
merged 19 commits into from
Feb 3, 2023

Conversation

ovitrif
Copy link
Contributor

@ovitrif ovitrif commented Feb 2, 2023

This PR:

  • Adds support for testing Compose UI
  • Adapts the e2e tests to support running on the Jetpack app
  • Adds support for running the e2e tests on the upcoming redesigned Landing screen of the WordPress app, while still supporting the current landing screen.

To test:

  • Verify the instrumented tests passed CI
  • 1️⃣ Optionally to validate the e2e tests support Jetpack app, you can run the suite locally in Android Studio:
    1. Change active build variant to: jetpackWasabiDebug
    2. Run all tests in WordPress/src/androidTest/java/org/wordpress/android/e2e

      Note If you're seeing the system dialog to enable notifications when the app launches in the emulator you must click one of the buttons manually otherwise the tests fail.

    3. ☑️ Validate the tests get past the landing screen successfully
  • 2️⃣ Optionally to validate the e2e tests support the new landing screen in WordPress app, you can:

Regression Notes

  1. Potential unintended areas of impact
    N/a

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Ran e2e and screenshots UI tests on:

    • Jetpack app
    • Wordpress app
      • with LANDING_SCREEN_REVAMP build config field false
      • with LANDING_SCREEN_REVAMP build config field true
  3. What automated tests I added (or what prevented me from doing so)
    N/a

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

This is a workaround to support interacting with the compose ui from `LoginPrologueRevampedFragment`, which has an infinite animation. By disabling the auto-sync between tests and compose ui, we avoid `ComposeNotIdleException`.
See: https://developer.android.com/jetpack/compose/testing#disable-autosync

The change was added in the setup of `BaseTest` to support login in JP app tests.
I had to add instrumented test files for JP and WP build variants to successfully build ui tests for both apps. The requirement is caused by the string resource unique to the jetpack variant in the `LoginPrologueRevampedFragment`: `R.string.continue_with_wpcom_no_signup`.
See https://developer.android.com/studio/test/advanced-test-setup

This change affects UI tests in:
- BlockEditorTests
- ReaderTests
- StatsTests
- JPScreenshotTest
- WPScreenshotTest
Both legacy login methods are no longer called from outside, so they can be private:
- chooseContinueWithWpCom
- chooseEnterYourSiteAddress
Moved both private methods under the public method which calls them
Support opening the signup magic link in the Jetpack app test by replacing the hard-coded "wordpress" scheme in the intent URI with `BuildConfig.FLAVOR_app`
Remove duplicated code in LoginFlow and SignupFlow by extracting the shared WP.com authentication logic to LandingPage
@ovitrif ovitrif added Jetpack UI Tests Anything related to automated UI Tests. Compose labels Feb 2, 2023
@ovitrif ovitrif added this to the 21.7 milestone Feb 2, 2023
@ovitrif ovitrif requested review from mkevins and ParaskP7 February 2, 2023 17:51
@ovitrif ovitrif requested a review from a team as a code owner February 2, 2023 17:51
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 2, 2023

Jetpack📲 You can test these changes on Jetpack by downloading jetpack-installable-build-pr17869-7a4ba84.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppJetpack
Build FlavorJalapeno
Build TypeDebug
Commit7a4ba84
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 2, 2023

WordPress📲 You can test these changes on WordPress by downloading wordpress-installable-build-pr17869-7a4ba84.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppWordPress
Build FlavorJalapeno
Build TypeDebug
Commit7a4ba84
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@peril-wordpress-mobile
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 4 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

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 adding the support for Compose on the UI tests @ovitrif!

The changes work well with the landing screen for Jetpack when tested locally. And CI WP tests are green 🎉

I did notice a few issues for some of the Jetpack tests when running locally, but I think those are out of the scope of this PR and can be fixed separately, as Jetpack tests are still local only at the moment.

I also have 1 suggestion I believe can improve the test in a separate comment, can you take a look if that is worth updating?

@ovitrif
Copy link
Contributor Author

ovitrif commented Feb 3, 2023

@ParaskP7 I added you as reviewer mostly to validate the new dependencies: 92d5308

I noticed this commit from you: 85d3f05 (part of PR #17620) where you mentioned:

It is generally recommended that transitively used dependencies that should be declared directly.

I'm not sure how to check if there's transitively used dependencies introduced by the newly added ones; and in case there are I'm thinking is best to declare them as well 🙇

Thanks in advance!

@ParaskP7
Copy link
Contributor

ParaskP7 commented Feb 3, 2023

👋 @ovitrif !

@ParaskP7 I added you as reviewer mostly to validate the new dependencies: 92d5308

The dependencies you added looks good to me! 👍

I noticed this commit from you: 85d3f05 (part of PR #17620) where you mentioned:

It is generally recommended that transitively used dependencies that should be declared directly.

I'm not sure how to check if there's transitively used dependencies introduced by the newly added ones; and in case there are I'm thinking is best to declare them as well 🙇

Yes, you're right and thanks for noticing this intricacy with transitively used dependencies! 💯

Unfortunately, there is no quick way to check if there's transitively used dependencies that should be declared directly. If you still want to do that, which to be honest I don't recommend (as it will take you some time), the best way to do that you would be to follow this paqN3M-Iq-p2 P2 post. As such:

  • First, you need to first add the Dependency Analysis Plugin, which to be honest it is very simple to do.
  • Then, I recommend you explicitly disable all variants but one so that you the buildHealth doesn't take forever to complete (last time it took me more than an hour). If you want, you could add a similar configuration to this commit here for that matter. With that, all you would need to add then is the ignored variants within local.properties and this will make running buildHealth much faster.

If you do the above and run the buildHealth task afterwards, you will get a project-health-report.txt file, that will contain a section like the below, which will inform you if there are any transitively used dependencies that should be declared directly:

Transitively used dependencies that should be declared directly as indicated:
  implementation 'androidx.activity:activity-ktx:1.3.1'
  implementation 'androidx.activity:activity:1.3.1'
  implementation 'androidx.appcompat:appcompat-resources:1.3.1'
  ...

Let me know if all the above help and again, thank YOU for looking into that as well! 🥇

PS: At some point I want to add this Dependency Analysis Plugin to our project, but, I'll first want to get a 👍 👎 from WPAndroid engineers on this custom configuration on ignored variants. Then, I'll proceed with it. Hmmm, I am also now seeing that this PR has been merged and as per Tony's comment here, it seems that it is already in 1.18.0 (see custom configuration on ignored variants too, thanks Sergey indeed). So maybe, there is no need to add our custom configuration on ignored variants. I need to test that! 🤔 🎉

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.

Thank you for making this change and for considering using testTag 🙇 It's a ✅ for me from the test side of things!

@ovitrif
Copy link
Contributor Author

ovitrif commented Feb 3, 2023

Let me know if all the above help and again, thank YOU for looking into that as well! 🥇
[...]
Hmmm, I am also now seeing that this PR has been merged and as per Tony's comment here, it seems that it is already in 1.18.0 (see custom configuration on ignored variants too, thanks Sergey indeed). So maybe, there is no need to add our custom configuration on ignored variants. I need to test that! 🤔 🎉

Thank you @ParaskP7 for the great technical insight to help me check by myself the impact on transitive dependencies, you rock a million times 🏆 💯 💯 💯 🥇

I was able to run the Dependency Analysis Plugin, version 1.18.0 and configure it to target only one build variant & flavor mix 👍

After adding the plug-in I added this line to my gradle.properties file:

dependency.analysis.android.ignored.variants=release,jetpack,vanilla,jalapeno

It only took 2m 51s to build 🎉

I don't see anything related to compose & testing in the build-health-report.txt file. Afaik we're all good 🚀

File content
Advice for :WordPress
Unused dependencies which should be removed:
  androidTestImplementation 'androidx.room:room-ktx:2.4.2'
  androidTestImplementation 'androidx.room:room-runtime:2.4.2'
  androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
  androidTestImplementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
  androidTestImplementation 'org.mockito:mockito-android:5.1.1'
  debugImplementation 'androidx.compose.ui:ui-tooling:1.1.1'
  implementation 'androidx.arch.core:core-runtime:2.1.0'
  implementation 'com.google.code.gson:gson:2.8.2'
  implementation 'org.greenrobot:eventbus:3.3.1'
  testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.6.10'

Transitively used dependencies that should be declared directly as indicated:
  androidTestImplementation 'androidx.slidingpanelayout:slidingpanelayout:1.0.0'
  androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.4.0'
  androidTestImplementation 'androidx.test:core:1.5.0'
  androidTestImplementation 'androidx.test:monitor:1.6.0'
  androidTestImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  androidTestImplementation 'com.facebook.stetho:stetho:1.6.0'
  androidTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.10.2'
  androidTestImplementation 'com.github.jknack:handlebars:4.0.7'
  androidTestImplementation 'com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:3.1'
  androidTestImplementation 'com.google.guava:guava:27.1-android'
  androidTestImplementation 'junit:junit:4.13.2'
  androidTestImplementation 'org.hamcrest:hamcrest:2.2'
  androidTestImplementation 'org.mockito:mockito-core:5.1.1'
  implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
  implementation 'androidx.collection:collection:1.1.0'
  implementation 'androidx.compose.animation:animation-core:1.1.1'
  implementation 'androidx.compose.animation:animation:1.1.1'
  implementation 'androidx.compose.material:material-icons-core:1.1.1'
  implementation 'androidx.compose.ui:ui-geometry:1.1.1'
  implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
  implementation 'androidx.cursoradapter:cursoradapter:1.0.0'
  implementation 'androidx.customview:customview:1.1.0'
  implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
  implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
  implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
  implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'androidx.loader:loader:1.0.0'
  implementation 'androidx.paging:paging-common:2.1.2'
  implementation 'androidx.paging:paging-runtime:2.1.2'
  implementation 'androidx.transition:transition:1.4.1'
  implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
  implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
  implementation 'androidx.viewpager2:viewpager2:1.0.0'
  implementation 'androidx.viewpager:viewpager:1.0.0'
  implementation 'com.github.bumptech.glide:annotations:4.12.0'
  implementation 'com.github.indexos.media-for-mobile:domain:43a9026f0973a2f0a74fa813132f6a16f7499c3a'
  implementation 'com.google.android.exoplayer:exoplayer-common:2.13.3'
  implementation 'com.google.android.exoplayer:exoplayer-core:2.13.3'
  implementation 'com.google.android.exoplayer:exoplayer-dash:2.13.3'
  implementation 'com.google.android.exoplayer:exoplayer-hls:2.13.3'
  implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.13.3'
  implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3'
  implementation 'com.google.android:flexbox:2.0.1'
  implementation 'com.google.dagger:dagger-android:2.42'
  implementation 'com.google.dagger:dagger:2.42'
  implementation 'com.google.dagger:hilt-core:2.42'
  implementation 'com.google.mlkit:barcode-scanning-common:17.0.0'
  implementation 'com.goterl:lazysodium-android:5.0.2'
  implementation 'com.squareup.okhttp3:okhttp:4.9.2'
  implementation 'com.squareup.retrofit2:retrofit:2.3.0'
  implementation 'com.zendesk.belvedere2:belvedere-core:3.0.0-RC'
  implementation 'com.zendesk.belvedere2:belvedere:3.0.0-RC'
  implementation 'com.zendesk:common-ui:4.0.1'
  implementation 'com.zendesk:core:4.0.2'
  implementation 'com.zendesk:guide:1.0.1'
  implementation 'com.zendesk:java-common:1.14'
  implementation 'com.zendesk:messaging:5.1.0'
  implementation 'com.zendesk:sdk-configurations:2.0.0'
  implementation 'com.zendesk:support-providers:5.0.2'
  implementation 'io.coil-kt:coil-base:1.4.0'
  implementation 'io.coil-kt:coil-compose-base:1.4.0'
  implementation 'io.coil-kt:coil:1.4.0'
  implementation 'javax.inject:javax.inject:1'
  implementation 'org.apache.commons:commons-lang3:3.12.0'
  implementation 'org.jetbrains.kotlin:kotlin-parcelize-runtime:1.6.10'
  implementation 'org.wordpress.aztec:wordpress-comments:v1.6.2'
  implementation 'org.wordpress.aztec:wordpress-shortcodes:v1.6.2'
  implementation 'org.wordpress.fluxc:fluxc-annotations:trunk-5863df97d8427540a8326b995647433882ca0e48'
  implementation 'org.wordpress.wellsql:wellsql-annotations:1.7.0'
  implementation 'org.wordpress:aztec:v1.6.2'
  implementation 'org.wordpress:wellsql:1.7.0'
  jetpackJalapenoDebugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  jetpackJalapenoDebugImplementation 'com.facebook.stetho:stetho:1.6.0'
  jetpackVanillaDebugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  jetpackVanillaDebugImplementation 'com.facebook.stetho:stetho:1.6.0'
  jetpackWasabiDebugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  jetpackWasabiDebugImplementation 'com.facebook.stetho:stetho:1.6.0'
  kapt 'com.google.dagger:dagger-compiler:2.42'
  testImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  testImplementation 'com.facebook.stetho:stetho:1.6.0'
  testImplementation 'org.jetbrains.kotlin:kotlin-test:1.6.10'
  wordpressJalapenoDebugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  wordpressJalapenoDebugImplementation 'com.facebook.stetho:stetho:1.6.0'
  wordpressWasabiDebugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
  wordpressWasabiDebugImplementation 'com.facebook.stetho:stetho:1.6.0'

Existing dependencies which should be modified to be as indicated:
  androidTestImplementation 'com.android.volley:volley:1.1.1' (was implementation)
  androidTestImplementation 'com.github.bumptech.glide:glide:4.10.0' (was implementation)
  wordpressVanillaDebugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0' (was debugImplementation)
  wordpressVanillaDebugImplementation 'com.facebook.stetho:stetho:1.6.0' (was debugImplementation)

Dependencies which should be removed or changed to runtime-only:
  runtimeOnly 'androidx.work:work-gcm:2.7.0' (was implementation)
  runtimeOnly 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' (was implementation)

Unused annotation processors that should be removed:
  kapt 'androidx.room:room-compiler:2.3.0'
  kapt 'com.google.dagger:hilt-compiler:2.42'

@ParaskP7
Copy link
Contributor

ParaskP7 commented Feb 3, 2023

I was able to run the Dependency Analysis Plugin, version 1.18.0 and configure it to target only one build variant & flavor mix 👍

You rock @ovitrif ! ❤️

After adding the plug-in I added this line to my gradle.properties file:

dependency.analysis.android.ignored.variants=release,jetpack,vanilla,jalapeno

It only took 2m 51s to build 🎉

🎉 Woohoo 🎉

I don't see anything related to compose & testing in the build-health-report.txt file. Afaik we're all good 🚀

Coolio onwards and upwards! 🚀

@ovitrif
Copy link
Contributor Author

ovitrif commented Feb 3, 2023

Merging this PR, thank y'all for your help here 🙇

@ovitrif ovitrif merged commit efa0565 into trunk Feb 3, 2023
@ovitrif ovitrif deleted the feature/add-compose-ui-testing-support branch February 3, 2023 16:12
@ParaskP7
Copy link
Contributor

ParaskP7 commented Feb 8, 2023

👋 @ovitrif !

After adding the plug-in I added this line to my gradle.properties file:

dependency.analysis.android.ignored.variants=release,jetpack,vanilla,jalapeno

It only took 2m 51s to build 🎉

Just a quick FYI that I did try that myself the other day and it seemed to be working as you described, it only took a couple of minutes on my PC as well. Because of that, today, I tried to add the Dependency Analysis plugin to the project. Unfortunately, it didn't work... 🤷

FYI:

  1. I added the 1.18.0 version, just like you did, and that because the 1.19.0 wasn't working due to this void org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments.setUseFir(boolean) failure (possible because of our current 1.6.10 Kotlin version).
  2. I wanted to try this dependency.analysis.android.ignored.variants feature on 1.19.0 due to that fact that I am seeing this Variant-specific declarations now more accurately map to variant-specific usages in the advice. fix within the 1.19.0 version changelog, which to be honest doesn't seem that related but you never know, it might be that this newer version fixes the issue I am having with 1.18.0.
  3. To test this 1.18.0 version of the Dependency Analysis plugin and its newly added dependency.analysis.android.ignored.variants feature, I first run ./gradlew clean, just to make sure that the project starts fresh in terms of build folders. Then, upon running ./gradlew buildHealth --dry-run I noticed that every variant was included there, even the ones I explicitly ignored via this newly added Gradle property. Obviously, me then running ./gradlew buildHealth took forever, as expected from my --dry-run check, and I forced stop it.

All the above, once more, made me stop from integrating the Dependency Analysis plugin to the project. After we update compileSdkVersion, AndroidX Compose and thus then Kotlin, I'll then try again with the 1.19.0 or any newer version of the plugin. 🤷

Btw Ovi, can you try that again on your side, after running ./gradlew clean first and see if it is still working as fast as you reported. 🙏

@ovitrif
Copy link
Contributor Author

ovitrif commented Feb 8, 2023

Btw Ovi, can you try that again on your side, after running ./gradlew clean first and see if it is still working as fast as you reported. 🙏

@ParaskP7 It takes forever for me as well 😅 . Don't remember how I managed to get it run so fast back then but one thing I know for sure is that I didn't run gradle from command-line (./gradlew buildHealth), but using the Android Studio UI:

Screenshot 2023-02-08 at 18 12 41

Although that as well takes forever and builds all variants now 😏

@ParaskP7
Copy link
Contributor

ParaskP7 commented Feb 9, 2023

👋 @ovitrif !

Yeah, I know, it worked for me too, just this once, and then stopped! 🤷 😅

But, at least this non-working behavior is replicated between us two... I'll try that again at some point in the future. 🤞

Thanks for trying it out once more! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Jetpack UI Tests Anything related to automated UI Tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants