From cbc880d79b75817155ac14dde89a521987abc93b Mon Sep 17 00:00:00 2001 From: agonzalez-r Date: Fri, 15 Nov 2024 08:20:22 +0100 Subject: [PATCH] chore: extract timeout value and remove/reorganise inconsistent waitUntil calls --- .../android/periodpals/endtoend/EndToEndM2.kt | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/src/androidTest/java/com/android/periodpals/endtoend/EndToEndM2.kt b/app/src/androidTest/java/com/android/periodpals/endtoend/EndToEndM2.kt index 2f177a614..2d968e0f1 100644 --- a/app/src/androidTest/java/com/android/periodpals/endtoend/EndToEndM2.kt +++ b/app/src/androidTest/java/com/android/periodpals/endtoend/EndToEndM2.kt @@ -8,7 +8,6 @@ import androidx.compose.ui.test.onAllNodesWithTag import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput -import androidx.test.espresso.Espresso import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import com.android.periodpals.MainActivity @@ -25,6 +24,7 @@ import org.junit.Test import org.junit.runner.RunWith private const val TAG = "EndToEnd2" +private const val TIMEOUT = 10000L // 10 seconds, adjust for slower devices, networks and CI @RunWith(AndroidJUnit4::class) class EndToEndM2 : TestCase() { @@ -59,25 +59,22 @@ class EndToEndM2 : TestCase() { .onNodeWithTag(AuthenticationScreens.PASSWORD_FIELD) .assertIsDisplayed() .performTextInput(PASSWORD) - Espresso.closeSoftKeyboard() - composeTestRule.waitUntil(6000) { true } composeTestRule.onNodeWithTag(SignInScreen.SIGN_IN_BUTTON).assertIsDisplayed().performClick() + composeTestRule.waitUntil(TIMEOUT) { + composeTestRule.onAllNodesWithTag(ProfileScreen.SCREEN).fetchSemanticsNodes().size == 1 + } // Profile Screen is displayed composeTestRule.waitForIdle() Log.d(TAG, "User arrives on Profile Screen") - composeTestRule.waitUntil(20000) { - composeTestRule.onAllNodesWithTag(ProfileScreen.SCREEN).fetchSemanticsNodes().size == 1 - } - Log.d(TAG, "User arrives on Edit Profile Screen") - composeTestRule.waitUntil(6000) { true } composeTestRule.onNodeWithTag(TopAppBar.EDIT_BUTTON).assertIsDisplayed().performClick() + composeTestRule.waitUntil(TIMEOUT) { + composeTestRule.onAllNodesWithTag(EditProfileScreen.SCREEN).fetchSemanticsNodes().size == 1 + } // Edit Profile Screen is displayed, edit name, dob and description composeTestRule.waitForIdle() - composeTestRule.waitUntil(20000) { - composeTestRule.onAllNodesWithTag(EditProfileScreen.SCREEN).fetchSemanticsNodes().size == 1 - } + Log.d(TAG, "User arrives on Edit Profile Screen") composeTestRule .onNodeWithTag(ProfileScreens.NAME_INPUT_FIELD) .assertIsDisplayed() @@ -90,15 +87,13 @@ class EndToEndM2 : TestCase() { .onNodeWithTag(ProfileScreens.DESCRIPTION_INPUT_FIELD) .assertIsDisplayed() .performTextInput(description) - Espresso.closeSoftKeyboard() - composeTestRule.waitUntil(6000) { true } composeTestRule.onNodeWithTag(ProfileScreens.SAVE_BUTTON).assertIsDisplayed().performClick() + composeTestRule.waitUntil(TIMEOUT) { + composeTestRule.onAllNodesWithTag(ProfileScreen.SCREEN).fetchSemanticsNodes().size == 1 + } // Profile Screen, check if the changes are saved composeTestRule.waitForIdle() - composeTestRule.waitUntil(20000) { - composeTestRule.onAllNodesWithTag(ProfileScreen.SCREEN).fetchSemanticsNodes().size == 1 - } Log.d(TAG, "User arrives on Profile Screen") composeTestRule.onNodeWithTag(ProfileScreen.NAME_FIELD).assertExists().assertTextEquals(name) composeTestRule