From 4ae298b5aa67f6318ff4b21827305a8deb9e1b3b Mon Sep 17 00:00:00 2001 From: Denys Bondarenko Date: Wed, 25 Nov 2026 14:48:16 +0200 Subject: [PATCH 1/5] test: fix and re-enable AddOtherAccountFlowTest#testShowWarningIfAuthFail The test mixed up field indexes (it restored wrong values into the next fields), never checked the network error title, and relied on the common idling resource, which can miss the settings check. The test servers pointed to 10.0.2.3, where a connection hangs until the 30 s timeout, so the run time and the outcome depended on what was left in the form. Use hosts of *.flowcrypt.test, where the IMAP and SMTP ports are closed, set one incorrect value per check and restore it afterwards, and wait for the result dialog. --- .../email/ui/AddOtherAccountFlowTest.kt | 108 +++++++----------- .../user_with_not_existed_server.json | 10 +- 2 files changed, 48 insertions(+), 70 deletions(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/AddOtherAccountFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/AddOtherAccountFlowTest.kt index 59892fbdaf..d66f67bc86 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/AddOtherAccountFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/AddOtherAccountFlowTest.kt @@ -6,11 +6,10 @@ package com.flowcrypt.email.ui import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.clearText import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.replaceText import androidx.test.espresso.action.ViewActions.scrollTo -import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.isDialog import androidx.test.espresso.matcher.ViewMatchers.isDisplayed @@ -21,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import com.flowcrypt.email.R import com.flowcrypt.email.TestConstants +import com.flowcrypt.email.junit.annotations.FlowCryptTestSettings import com.flowcrypt.email.rules.ClearAppSettingsRule import com.flowcrypt.email.rules.GrantPermissionRuleChooser import com.flowcrypt.email.rules.RetryRule @@ -31,18 +31,19 @@ import com.flowcrypt.email.util.AuthCredentialsManager import com.flowcrypt.email.util.TestGeneralUtil import org.hamcrest.Matchers.anyOf import org.hamcrest.Matchers.startsWith -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain import org.junit.rules.TestRule import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit /** * @author Denys Bondarenko */ @MediumTest @RunWith(AndroidJUnit4::class) +@FlowCryptTestSettings(useCommonIdling = false) class AddOtherAccountFlowTest : AddOtherAccountBaseTest() { override val activeActivityRule = activityScenarioRule( @@ -60,84 +61,61 @@ class AddOtherAccountFlowTest : AddOtherAccountBaseTest() { .around(ScreenshotTestRule()) @Test - //@Ignore("flaky 8") - //RepeatableAndroidJUnit4ClassRunner 50 attempts passed - @Ignore("flaky. Temporary disabled") fun testShowWarningIfAuthFail() { enableAdvancedMode() val credentials = AuthCredentialsManager.getAuthCredentials("user_with_not_existed_server.json") fillAllFields(credentials) - val someFailTextToChangeRightValue = "123" - val fieldIdentifiersWithIncorrectData = intArrayOf( - R.id.editTextEmail, - R.id.editTextUserName, - R.id.editTextImapServer, - R.id.editTextImapPort, - R.id.editTextSmtpServer, - R.id.editTextSmtpPort, - R.id.editTextSmtpUsername, - R.id.editTextSmtpPassword + // Nothing listens on the IMAP and SMTP ports of *.flowcrypt.test (127.0.0.1), so every + // attempt fails fast with a connection error, whichever field has an incorrect value. + // The email goes last: changing it also overwrites the servers and the username. + val checks = listOf( + FieldCheck(R.id.editTextUserName, credentials.username, "wrong_user"), + FieldCheck(R.id.editTextImapServer, credentials.imapServer, "wrong.imap.flowcrypt.test"), + FieldCheck(R.id.editTextImapPort, credentials.imapPort.toString(), CLOSED_PORT), + FieldCheck(R.id.editTextSmtpServer, credentials.smtpServer, "wrong.smtp.flowcrypt.test"), + FieldCheck(R.id.editTextSmtpPort, credentials.smtpPort.toString(), CLOSED_PORT), + FieldCheck(R.id.editTextEmail, credentials.email, "wrong_user@flowcrypt.test") ) - val correctData = arrayOf( - credentials.email, - credentials.username, - credentials.password, - credentials.imapServer, - credentials.imapPort.toString(), - credentials.smtpServer, - credentials.smtpPort.toString(), - credentials.smtpSigInUsername, - credentials.smtpSignInPassword - ) - - val numberOfChecks = if (credentials.hasCustomSignInForSmtp) { - fieldIdentifiersWithIncorrectData.size - } else { - fieldIdentifiersWithIncorrectData.size - 2 - } - - for (i in 0 until numberOfChecks) { - onView(withId(fieldIdentifiersWithIncorrectData[i])) - .perform( - scrollTo(), - typeText(someFailTextToChangeRightValue), - closeSoftKeyboard() - ) + for (check in checks) { + replaceFieldText(check.viewId, check.incorrectValue) onView(withId(R.id.buttonTryToConnect)) .perform(scrollTo(), click()) - onView( - anyOf( - withText(startsWith(TestConstants.IMAP)), - withText(startsWith(TestConstants.SMTP)) - ) - ).check(matches(isDisplayed())) - - if (i in intArrayOf( - R.id.editTextImapServer, - R.id.editTextImapPort, - R.id.editTextSmtpServer, - R.id.editTextSmtpPort - ) - ) { - onView(withText(getResString(R.string.network_error))) - .check(matches(isDisplayed())) - } + // The settings are checked in the background, so wait for the result dialog + waitUntilViewMatches( + viewId = android.R.id.message, + matcher = withText(anyOf(startsWith(TestConstants.IMAP), startsWith(TestConstants.SMTP))), + root = isDialog(), + timeoutMs = TimeUnit.SECONDS.toMillis(30) + ) + onView(withText(getResString(R.string.network_error))) + .inRoot(isDialog()) + .check(matches(isDisplayed())) onView(withText(getResString(R.string.cancel))) .inRoot(isDialog()) .check(matches(isDisplayed())) .perform(click()) + waitUntilViewMatches(viewId = R.id.buttonTryToConnect, matcher = isDisplayed()) - onView(withId(fieldIdentifiersWithIncorrectData[i])) - .perform( - scrollTo(), - clearText(), - typeText(correctData[i]), - closeSoftKeyboard() - ) + replaceFieldText(check.viewId, check.correctValue) } } + + private fun replaceFieldText(viewId: Int, text: String) { + onView(withId(viewId)) + .perform(scrollTo(), replaceText(text), closeSoftKeyboard()) + } + + private data class FieldCheck( + val viewId: Int, + val correctValue: String, + val incorrectValue: String + ) + + companion object { + private const val CLOSED_PORT = "1" + } } diff --git a/FlowCrypt/src/androidTest/resources/user_with_not_existed_server.json b/FlowCrypt/src/androidTest/resources/user_with_not_existed_server.json index 866ce17f9d..42a0e98b35 100644 --- a/FlowCrypt/src/androidTest/resources/user_with_not_existed_server.json +++ b/FlowCrypt/src/androidTest/resources/user_with_not_existed_server.json @@ -1,12 +1,12 @@ { "email": "user_with_not_existed_server@flowcrypt.test", - "imapPort": 993, + "imapPort": 143, "imapOpt": "NONE", - "imapServer": "10.0.2.3", + "imapServer": "imap.flowcrypt.test", "hasCustomSignInForSmtp": false, "password": "qwerty1234", - "smtpPort": 587, + "smtpPort": 25, "smtpOpt": "NONE", - "smtpServer": "10.0.2.3", + "smtpServer": "smtp.flowcrypt.test", "username": "user_with_not_existed_server@flowcrypt.test" -} \ No newline at end of file +} From 1faf203fc307aa8c715e7b6465bc10058d7aedb9 Mon Sep 17 00:00:00 2001 From: Denys Bondarenko Date: Wed, 25 Nov 2026 19:47:16 +0200 Subject: [PATCH 2/5] test: re-enable forward of PGP/MIME message test as a flaky test StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmailApiFlow was ignored, but CI history since August shows one failure without a stack trace, and it passes on a slow CI-like emulator. Run it with @FlakyTest like the other forward tests to collect data on CI. Wait for the forwarded attachments on the compose screen instead of a fixed sleep, and for the message details screen after sending, before pressing Back, as the sibling forward tests do. --- ...hOriginalAttachmentsComposeGmailApiFlow.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmailApiFlow.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmailApiFlow.kt index 08339b87de..522e110f77 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmailApiFlow.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmailApiFlow.kt @@ -16,6 +16,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.FlakyTest import androidx.test.filters.MediumTest import com.flowcrypt.email.R import com.flowcrypt.email.TestConstants @@ -26,6 +27,7 @@ import com.flowcrypt.email.api.retrofit.response.model.VerificationResult import com.flowcrypt.email.database.entity.MessageEntity import com.flowcrypt.email.junit.annotations.FlowCryptTestSettings import com.flowcrypt.email.junit.annotations.OutgoingMessageConfiguration +import com.flowcrypt.email.matchers.CustomMatchers.Companion.withRecyclerViewItemCount import com.flowcrypt.email.model.MessageEncryptionType import com.flowcrypt.email.model.MessageType import com.flowcrypt.email.rules.AddRecipientsToDatabaseRule @@ -43,9 +45,9 @@ import jakarta.mail.internet.MimeMultipart import okhttp3.mockwebserver.Dispatcher import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest +import org.hamcrest.Matchers.allOf import org.junit.Assert.assertEquals import org.junit.Rule -import org.junit.Ignore import org.junit.Test import org.junit.rules.RuleChain import org.junit.rules.TestRule @@ -88,7 +90,7 @@ class StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmai .around(ScreenshotTestRule()) @Test - @Ignore("Flaky. Need to fix") + @FlakyTest fun testSending() { //need to wait while the app loads the messages list waitForObjectWithText(SUBJECT_EXISTING_STANDARD, TimeUnit.SECONDS.toMillis(10)) @@ -116,8 +118,8 @@ class StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmai val outgoingMessageConfiguration = requireNotNull(outgoingMessageConfigurationRule.outgoingMessageConfiguration) - //need to wait while all action for forward case will be applied - Thread.sleep(1000) + //the original attachments are added to the compose screen asynchronously + waitUntilViewMatches(R.id.rVAttachments, withRecyclerViewItemCount(3)) fillData(outgoingMessageConfiguration) //enqueue outgoing message @@ -125,7 +127,19 @@ class StandardForwardOfEncryptedPgpMimeMessageWithOriginalAttachmentsComposeGmai .check(matches(isDisplayed())) .perform(click()) - //back to the message details screen + //wait for enqueuing an outgoing message and return back to the message details screen + val subjectOfForwardedMessage = + onView(allOf(withId(R.id.textViewSubject), withText(SUBJECT_EXISTING_PGP_MIME))) + waitUntil(TimeUnit.SECONDS.toMillis(30)) { + runCatching { + subjectOfForwardedMessage + .withFailureHandler { error, _ -> throw error } + .check(matches(isDisplayed())) + }.isSuccess + } + subjectOfForwardedMessage.check(matches(isDisplayed())) + + //back to the messages list screen pressBack() doAfterSendingChecks { _, rawMime, mimeMessage -> From deea998564af585108b2c399b80516896fa21cb2 Mon Sep 17 00:00:00 2001 From: Denys Bondarenko Date: Wed, 25 Nov 2026 19:47:25 +0200 Subject: [PATCH 3/5] test: run StandardReplyComposeGmailApiFlow as a regular test All its CI failures since August were infrastructure problems (the system crashed during instrumentation, or the device went offline), not test failures. It passes on a slow CI-like emulator. --- .../email/ui/gmailapi/StandardReplyComposeGmailApiFlow.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardReplyComposeGmailApiFlow.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardReplyComposeGmailApiFlow.kt index 3e540485f2..74d0e7f336 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardReplyComposeGmailApiFlow.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/StandardReplyComposeGmailApiFlow.kt @@ -14,7 +14,6 @@ import androidx.test.espresso.contrib.RecyclerViewActions import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.FlakyTest import androidx.test.filters.MediumTest import com.flowcrypt.email.R import com.flowcrypt.email.TestConstants @@ -85,7 +84,6 @@ class StandardReplyComposeGmailApiFlow : BaseComposeGmailFlow() { .around(ScreenshotTestRule()) @Test - @FlakyTest fun testSending() { //need to wait while the app loads the messages list waitForObjectWithText(SUBJECT_EXISTING_ENCRYPTED, TimeUnit.SECONDS.toMillis(10)) From 8399dfb59539599811f32fae0087c7ea4ad8d767 Mon Sep 17 00:00:00 2001 From: Denys Bondarenko Date: Wed, 25 Nov 2026 21:32:54 +0200 Subject: [PATCH 4/5] test: retry WebView checks until enabled JavaScript reaches the renderer The app keeps JavaScript disabled in WebViews, and tests enable it with forceJavascriptEnabled() right before a web check. That only calls setJavaScriptEnabled(true), and the setting reaches the renderer asynchronously. On a slow CI emulator the check ran first and failed with "Could not parse: null" or a 10 s timeout, although the message was already rendered (4 MessageDetailsFlowTest tests on master, every retry failed the same way because each retry starts a new WebView). Add checkWebViewWithJavascript() that enables JavaScript and retries the check for up to 30 s, then runs it once more to fail with the real error. --- .../java/com/flowcrypt/email/base/BaseTest.kt | 19 +++++++++++++++++ .../email/ui/MessageDetailsFlowTest.kt | 21 ++++++++++--------- .../ui/base/BaseMessageDetailsFlowTest.kt | 8 +++---- ...iewFromAssetsRawFragmentInIsolationTest.kt | 10 ++++----- .../base/BaseThreadDetailsGmailApiFlowTest.kt | 7 +++---- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/base/BaseTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/base/BaseTest.kt index 5b04eb74ac..86a52e3409 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/base/BaseTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/base/BaseTest.kt @@ -39,6 +39,8 @@ import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.web.sugar.Web +import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By @@ -393,6 +395,23 @@ abstract class BaseTest : BaseActivityTestImplementation { } } + /** + * Enable JavaScript in the WebView that matches [webViewMatcher] and run [check] on it. + * The app keeps JavaScript disabled, and the new setting reaches the WebView renderer + * asynchronously, so on a slow emulator the first checks can fail with + * "Could not parse: null" or time out. Retry [check] until it passes or [timeoutMs] + * expires, then run it once more to fail with the real error. + */ + protected fun checkWebViewWithJavascript( + webViewMatcher: Matcher, + timeoutMs: Long = TimeUnit.SECONDS.toMillis(30), + check: (Web.WebInteraction) -> Unit + ) { + onWebView(webViewMatcher).forceJavascriptEnabled() + waitUntil(timeoutMs) { runCatching { check(onWebView(webViewMatcher)) }.isSuccess } + check(onWebView(webViewMatcher)) + } + protected fun waitUntil( timeoutInMilliseconds: Long = TimeUnit.SECONDS.toMillis(10), predicate: () -> Boolean diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/MessageDetailsFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/MessageDetailsFlowTest.kt index 020a4c934b..b66794c4ac 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/MessageDetailsFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/MessageDetailsFlowTest.kt @@ -1008,9 +1008,8 @@ class MessageDetailsFlowTest : BaseMessageDetailsFlowTest() { ) baseCheck(msgInfo, checkWebContent = false) - onWebView(withId(R.id.emailWebView)).forceJavascriptEnabled() - onWebView(withId(R.id.emailWebView)) - .check( + checkWebViewWithJavascript(withId(R.id.emailWebView)) { webView -> + webView.check( webContent( elementByXPath( "/html/body", @@ -1023,6 +1022,7 @@ class MessageDetailsFlowTest : BaseMessageDetailsFlowTest() { ) ) ) + } testPgpBadges( 2, @@ -1197,10 +1197,11 @@ class MessageDetailsFlowTest : BaseMessageDetailsFlowTest() { Atoms.castOrDie(String::class.java) ) - onWebView(withId(R.id.emailWebView)).forceJavascriptEnabled() - onWebView(withId(R.id.emailWebView)) - .withElement(findElement(Locator.XPATH, xpath)) - .check(webMatches(imgSrcViaJavaScript, equalTo(imgSrc))) + checkWebViewWithJavascript(withId(R.id.emailWebView)) { webView -> + webView + .withElement(findElement(Locator.XPATH, xpath)) + .check(webMatches(imgSrcViaJavaScript, equalTo(imgSrc))) + } } @Test @@ -1221,9 +1222,8 @@ class MessageDetailsFlowTest : BaseMessageDetailsFlowTest() { baseCheck(msgInfo) - onWebView(withId(R.id.emailWebView)).forceJavascriptEnabled() - onWebView(withId(R.id.emailWebView)) - .check( + checkWebViewWithJavascript(withId(R.id.emailWebView)) { webView -> + webView.check( webContent( elementByXPath( "/html/body", @@ -1231,6 +1231,7 @@ class MessageDetailsFlowTest : BaseMessageDetailsFlowTest() { ) ) ) + } Thread.sleep(1000) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseMessageDetailsFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseMessageDetailsFlowTest.kt index aa81064245..9bb04b02ea 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseMessageDetailsFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/base/BaseMessageDetailsFlowTest.kt @@ -26,7 +26,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.web.assertion.TagSoupDocumentParser import androidx.test.espresso.web.assertion.WebViewAssertions.webContent import androidx.test.espresso.web.matcher.DomMatchers.elementByXPath -import androidx.test.espresso.web.sugar.Web.onWebView import com.flowcrypt.email.R import com.flowcrypt.email.api.email.EmailUtil import com.flowcrypt.email.api.email.model.AttachmentInfo @@ -212,10 +211,9 @@ abstract class BaseMessageDetailsFlowTest : BaseTest() { .joinToString(separator = "\n") { it.textContent } .trim() - onWebView(withId(R.id.emailWebView)).forceJavascriptEnabled() - onWebView(withId(R.id.emailWebView)) - .check(webContent(elementByXPath("/html/body", withTextContentMatcher(`is`(content))))) - //.check(webContent(withBody(withTextContentMatcher(`is`(content))))) + checkWebViewWithJavascript(withId(R.id.emailWebView)) { webView -> + webView.check(webContent(elementByXPath("/html/body", withTextContentMatcher(`is`(content))))) + } } protected fun testMissingKey(incomingMsgInfo: IncomingMessageInfo?) { diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/HtmlViewFromAssetsRawFragmentInIsolationTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/HtmlViewFromAssetsRawFragmentInIsolationTest.kt index 7c5ded2a4a..bb79d456af 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/HtmlViewFromAssetsRawFragmentInIsolationTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/fragment/isolation/incontainer/HtmlViewFromAssetsRawFragmentInIsolationTest.kt @@ -10,7 +10,6 @@ import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.web.assertion.WebViewAssertions.webMatches -import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.getText import androidx.test.espresso.web.webdriver.Locator @@ -56,9 +55,10 @@ class HtmlViewFromAssetsRawFragmentInIsolationTest : BaseTest() { onView(withId(R.id.webView)) .check(matches(isDisplayed())) - onWebView(withId(R.id.webView)).forceJavascriptEnabled() - onWebView(withId(R.id.webView)) - .withElement(findElement(Locator.TAG_NAME, "h1")) - .check(webMatches(getText(), containsString("FlowCrypt Privacy Policy"))) + checkWebViewWithJavascript(withId(R.id.webView)) { webView -> + webView + .withElement(findElement(Locator.TAG_NAME, "h1")) + .check(webMatches(getText(), containsString("FlowCrypt Privacy Policy"))) + } } } diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/base/BaseThreadDetailsGmailApiFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/base/BaseThreadDetailsGmailApiFlowTest.kt index b9978f6cfe..a2937e69a2 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/base/BaseThreadDetailsGmailApiFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/base/BaseThreadDetailsGmailApiFlowTest.kt @@ -24,7 +24,6 @@ import androidx.test.espresso.matcher.ViewMatchers.withParent import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.web.assertion.WebViewAssertions.webContent import androidx.test.espresso.web.matcher.DomMatchers.elementByXPath -import androidx.test.espresso.web.sugar.Web.onWebView import com.flowcrypt.email.R import com.flowcrypt.email.TestConstants import com.flowcrypt.email.api.email.model.LocalFolder @@ -285,9 +284,9 @@ abstract class BaseThreadDetailsGmailApiFlowTest( } protected fun checkWebViewText(content: String?) { - onWebView(allOf(withId(R.id.emailWebView), isDisplayed())).forceJavascriptEnabled() - onWebView(allOf(withId(R.id.emailWebView), isDisplayed())) - .check(webContent(elementByXPath("/html/body", withTextContentMatcher(`is`(content))))) + checkWebViewWithJavascript(allOf(withId(R.id.emailWebView), isDisplayed())) { webView -> + webView.check(webContent(elementByXPath("/html/body", withTextContentMatcher(`is`(content))))) + } } protected fun openThreadBasedOnPosition(position: Int) { From 4d0caa725bc2e106fc1502109733114f45f94456 Mon Sep 17 00:00:00 2001 From: Denys Bondarenko Date: Wed, 25 Nov 2026 21:59:38 +0200 Subject: [PATCH 5/5] test: fix and re-enable SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest The test passes against the local mail server, but it had fixed sleeps and short waits that silently continued on timeout. Wait for concrete states instead: the create key button (the app checks the settings and searches for backups first), the evaluated passphrase strength (the button does nothing before it), and the attester call. The app sends a backup of the created key to the inbox, and other tests expect that this user has no backups. The mail server delivers the email asynchronously, so the cleanup now waits for it before deleting it. --- ...eyAfterCreationNonGoogleAccountFlowTest.kt | 68 ++++++++++++------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest.kt index 01c05c9bd5..9982705a29 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest.kt @@ -14,6 +14,7 @@ import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.activityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest @@ -37,8 +38,8 @@ import kotlinx.coroutines.runBlocking import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest import org.eclipse.angus.mail.imap.IMAPFolder +import org.hamcrest.Matchers.containsString import org.junit.Assert.assertTrue -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -57,11 +58,11 @@ import java.util.concurrent.TimeUnit @MediumTest @RunWith(AndroidJUnit4::class) @FlowCryptTestSettings(useIntents = true, useCommonIdling = false) -@Ignore("temporary disabled") class SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest : BaseSignTest() { override val activityScenarioRule = activityScenarioRule() private val userWithoutBackups = AccountDaoManager.getUserWithoutBackup() + @Volatile private var isSubmitPubKeyCalled = false val mockWebServerRule = FlowCryptMockWebServerRule( @@ -109,20 +110,24 @@ class SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest : BaseSignTest() { .check(matches(isDisplayed())) .perform(click()) - waitForObjectWithText( - getResString(R.string.create_a_new_key).uppercase(), - TimeUnit.SECONDS.toMillis(5) + //the app checks the settings and searches for backups on the mail server first + waitUntilViewMatches( + viewId = R.id.buttonCreateNewKey, + matcher = isDisplayed(), + timeoutMs = TimeUnit.SECONDS.toMillis(30) ) - onView(withId(R.id.buttonCreateNewKey)) - .check(matches(isDisplayed())) .perform(click()) val passphrase = UUID.randomUUID().toString() + UUID.randomUUID().toString() onView(withId(R.id.editTextKeyPassword)) .check(matches(isDisplayed())) .perform(replaceText(passphrase)) - Thread.sleep(TimeUnit.SECONDS.toMillis(1)) + //the button does nothing until the passphrase strength is evaluated in the background + waitUntilViewMatches( + viewId = R.id.textViewPasswordQualityInfo, + matcher = withText(containsString(getResString(R.string.password_quality_subtext))) + ) onView(withId(R.id.buttonSetPassPhrase)) .check(matches(isDisplayed())) .perform(click()) @@ -133,26 +138,43 @@ class SubmitPublicKeyAfterCreationNonGoogleAccountFlowTest : BaseSignTest() { .check(matches(isDisplayed())) .perform(click()) - //need to wait while a key is creating - waitForObjectWithText(JavaEmailConstants.FOLDER_INBOX, TimeUnit.SECONDS.toMillis(10)) - + //the app sends a backup of the key to the inbox first, then submits the public key + waitUntil(TimeUnit.SECONDS.toMillis(30)) { isSubmitPubKeyCalled } assertTrue(isSubmitPubKeyCalled) } finally { - runBlocking { - val imapStoreConnection = IMAPStoreConnection(getTargetContext(), userWithoutBackups) - imapStoreConnection.connect() - imapStoreConnection.store.use { store -> - store.getFolder("INBOX").use { folder -> - val imapFolder = (folder as IMAPFolder).apply { open(Folder.READ_WRITE) } - val msgs = - imapFolder.messages.filter { it.subject == "Your FlowCrypt Backup" }.toTypedArray() - if (msgs.isNotEmpty()) { - imapFolder.setFlags(msgs, Flags(Flags.Flag.DELETED), true) - } - folder.expunge() + deleteBackupEmails() + } + } + + /** + * Other tests expect that [userWithoutBackups] has no backups in the inbox. The mail server + * delivers the backup email asynchronously, so if the key was created, wait for the email + * before deleting it. + */ + private fun deleteBackupEmails() { + runBlocking { + val imapStoreConnection = IMAPStoreConnection(getTargetContext(), userWithoutBackups) + imapStoreConnection.connect() + imapStoreConnection.store.use { store -> + store.getFolder(JavaEmailConstants.FOLDER_INBOX).use { folder -> + val imapFolder = (folder as IMAPFolder).apply { open(Folder.READ_WRITE) } + val findBackups = { + imapFolder.messages.filter { it.subject == BACKUP_EMAIL_SUBJECT }.toTypedArray() + } + if (isSubmitPubKeyCalled) { + waitUntil(TimeUnit.SECONDS.toMillis(30)) { findBackups().isNotEmpty() } } + val backups = findBackups() + if (backups.isNotEmpty()) { + imapFolder.setFlags(backups, Flags(Flags.Flag.DELETED), true) + } + folder.expunge() } } } } + + companion object { + private const val BACKUP_EMAIL_SUBJECT = "Your FlowCrypt Backup" + } }