From 17ccd9e2f44807b2a70c90765b031891898d68a0 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 12 Jun 2025 11:37:13 +0200 Subject: [PATCH 1/9] Use non-deprecated wrapper-validation action See details: https://github.com/gradle/wrapper-validation-action --- .github/workflows/gradle-wrapper-validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 405a2b306..5e1413088 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -7,4 +7,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: gradle/wrapper-validation-action@v1 + - uses: gradle/actions/wrapper-validation@v3 From 332cd289f295a9267fd0ac4441df872cad393ecf Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 12 Jun 2025 11:39:02 +0200 Subject: [PATCH 2/9] Use Pixel 9a for connected tests --- .buildkite/commands/connected-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/commands/connected-tests.sh b/.buildkite/commands/connected-tests.sh index 2fc465dbf..890ad1a2e 100644 --- a/.buildkite/commands/connected-tests.sh +++ b/.buildkite/commands/connected-tests.sh @@ -17,5 +17,5 @@ gcloud firebase test android run \ --type instrumentation \ --app app/build/outputs/apk/debug/app-debug.apk \ --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \ - --device model=Nexus5X,version=26,locale=en,orientation=portrait \ + --device model=Pixel9a,version=35,locale=en,orientation=portrait \ --verbosity info From c2952fec88dd7834d6b256f308758b5f63c0ad0f Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 12 Jun 2025 12:03:09 +0200 Subject: [PATCH 3/9] Use model id instead of name --- .buildkite/commands/connected-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.buildkite/commands/connected-tests.sh b/.buildkite/commands/connected-tests.sh index 890ad1a2e..c880a1c6c 100644 --- a/.buildkite/commands/connected-tests.sh +++ b/.buildkite/commands/connected-tests.sh @@ -17,5 +17,6 @@ gcloud firebase test android run \ --type instrumentation \ --app app/build/outputs/apk/debug/app-debug.apk \ --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \ - --device model=Pixel9a,version=35,locale=en,orientation=portrait \ + # tegu = Pixel 9a + --device model=tegu,version=35,locale=en,orientation=portrait \ --verbosity info From 1842919d9c5a5cc5c0abd8546b94adad22ed68d2 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 13 Jun 2025 09:36:16 +0200 Subject: [PATCH 4/9] Grant only necessary permission and use UiAutomation for it `pm` is less effective, according to logs --- .../kotlin/org/wordpress/aztec/demo/BaseTest.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt index df840aac5..0c45dc468 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt @@ -2,18 +2,23 @@ package org.wordpress.aztec.demo +import android.Manifest.permission.CAMERA import android.util.Log -import androidx.test.rule.GrantPermissionRule +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.runner.AndroidJUnit4 -import org.junit.Rule +import org.junit.Before import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) abstract class BaseTest { - @Rule - @JvmField - val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.CAMERA, - android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + + @Before + fun grantPermissions() { + val (uiAutomation, packageName) = with(InstrumentationRegistry.getInstrumentation()) { + Pair(uiAutomation, targetContext.packageName) + } + uiAutomation.grantRuntimePermission(packageName, CAMERA) + } companion object { fun label(label: String) { From 2a93d6260643f5df6ef44f49107398ce919c07e2 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 13 Jun 2025 09:36:45 +0200 Subject: [PATCH 5/9] Run UI tests on Pixel 5 It's default test device on FTL --- .buildkite/commands/connected-tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) mode change 100644 => 100755 .buildkite/commands/connected-tests.sh diff --git a/.buildkite/commands/connected-tests.sh b/.buildkite/commands/connected-tests.sh old mode 100644 new mode 100755 index c880a1c6c..38d8308c1 --- a/.buildkite/commands/connected-tests.sh +++ b/.buildkite/commands/connected-tests.sh @@ -17,6 +17,5 @@ gcloud firebase test android run \ --type instrumentation \ --app app/build/outputs/apk/debug/app-debug.apk \ --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \ - # tegu = Pixel 9a - --device model=tegu,version=35,locale=en,orientation=portrait \ + --device model=redfin,version=30 \ --verbosity info From 242aaa17e4a829d4c644ccede811009a03f379d3 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 13 Jun 2025 09:56:44 +0200 Subject: [PATCH 6/9] Fix `EditLinkPage#updateURL` action by introducing safety mechanisms: assert focus, add a delay, close the keyboard --- .../wordpress/aztec/demo/pages/EditLinkPage.kt | 16 +++++++++++++++- .../aztec/demo/tests/LinkHistoryTests.kt | 11 +++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt index c1f22a764..f441e8226 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt @@ -33,7 +33,16 @@ class EditLinkPage : BasePage() { } fun updateURL(url: String): EditLinkPage { - urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard()) + threadSleep(2000L) // Wait for the page to load + try { + urlField.perform(click()) + urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard()) + } catch (e: RuntimeException){ + // If the URL field is not visible, it might be because the keyboard is open. + // Close the keyboard and try again. + urlField.perform(ViewActions.closeSoftKeyboard()) + urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard()) + } label("Entered url") return this @@ -80,4 +89,9 @@ class EditLinkPage : BasePage() { cancelButton.perform(click()) label("Canceled") } + + fun threadSleep(millis: Long): EditLinkPage { + Thread.sleep(millis) + return this + } } diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/LinkHistoryTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/LinkHistoryTests.kt index 83d75e0fb..11c945a6e 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/LinkHistoryTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/LinkHistoryTests.kt @@ -204,11 +204,14 @@ class LinkHistoryTests : BaseHistoryTest() { */ private fun addLinkAndVerify(editorPage: EditorPage, link: String, expected: String, name: String? = null) { editorPage.makeLink() - EditLinkPage().updateURL(link) + editorPage.threadSleep(throttleTime) + + val editLinkPage = EditLinkPage() + editLinkPage.updateURL(link) name?.let { - EditLinkPage().updateName(it) + editLinkPage.updateName(it) } - EditLinkPage().ok() + editLinkPage.ok() editorPage .toggleHtml() @@ -216,4 +219,4 @@ class LinkHistoryTests : BaseHistoryTest() { .toggleHtml() .threadSleep(throttleTime) } -} \ No newline at end of file +} From e2ea258d6b2745dcffa9e58d3a87518420cffc58 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 13 Jun 2025 10:53:28 +0200 Subject: [PATCH 7/9] Remove hints from text views of the test app They seem to interfere with instrumented the tests execution --- app/src/main/res/layout/activity_main.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index fedc7ca55..b1da08d29 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -30,7 +30,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top|start" - android:hint="@string/edit_hint" android:inputType="textCapSentences|textMultiLine" android:paddingEnd="16dp" android:paddingLeft="16dp" @@ -46,7 +45,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top|start" - android:hint="@string/source_hint" android:inputType="textNoSuggestions|textMultiLine" android:paddingEnd="16dp" android:paddingLeft="16dp" From 4746d9b544f74a8aa38f4755f49cc83f42fffdf3 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 13 Jun 2025 13:54:38 +0200 Subject: [PATCH 8/9] Fix formatting --- .../kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt index f441e8226..73f36c708 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt @@ -37,7 +37,7 @@ class EditLinkPage : BasePage() { try { urlField.perform(click()) urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard()) - } catch (e: RuntimeException){ + } catch (e: RuntimeException) { // If the URL field is not visible, it might be because the keyboard is open. // Close the keyboard and try again. urlField.perform(ViewActions.closeSoftKeyboard()) From a05f08416c0da482dd9e2734c85d299a7c42d912 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 13 Jun 2025 13:56:36 +0200 Subject: [PATCH 9/9] Print stack trace of RuntimeException It'll happen whenever Espresso waited for too long for an input --- .../kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt index 73f36c708..e7a93726c 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditLinkPage.kt @@ -42,6 +42,7 @@ class EditLinkPage : BasePage() { // Close the keyboard and try again. urlField.perform(ViewActions.closeSoftKeyboard()) urlField.perform(replaceText(url), ViewActions.closeSoftKeyboard()) + e.printStackTrace() } label("Entered url")