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

Fix login uiautomator flakiness #5276

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
Expand All @@ -57,6 +60,7 @@ import net.mullvad.mullvadvpn.compose.state.LoginError
import net.mullvad.mullvadvpn.compose.state.LoginState
import net.mullvad.mullvadvpn.compose.state.LoginState.*
import net.mullvad.mullvadvpn.compose.state.LoginUiState
import net.mullvad.mullvadvpn.compose.test.LOGIN_TITLE_TEST_TAG
import net.mullvad.mullvadvpn.compose.textfield.mullvadWhiteTextFieldColors
import net.mullvad.mullvadvpn.compose.util.accountTokenVisualTransformation
import net.mullvad.mullvadvpn.lib.theme.AlphaTopBar
Expand Down Expand Up @@ -95,6 +99,7 @@ private fun PreviewLoginSuccess() {
AppTheme { LoginScreen(uiState = LoginUiState(loginState = Success)) }
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun LoginScreen(
uiState: LoginUiState,
Expand All @@ -105,6 +110,7 @@ fun LoginScreen(
onSettingsClick: () -> Unit = {},
) {
ScaffoldWithTopBar(
modifier = Modifier.semantics { testTagsAsResourceId = true },
topBarColor = MaterialTheme.colorScheme.primary,
statusBarColor = MaterialTheme.colorScheme.primary,
navigationBarColor = MaterialTheme.colorScheme.background,
Expand Down Expand Up @@ -147,7 +153,10 @@ private fun LoginContent(
text = uiState.loginState.title(),
style = MaterialTheme.typography.headlineLarge,
color = MaterialTheme.colorScheme.onPrimary,
modifier = Modifier.fillMaxWidth().padding(bottom = Dimens.smallPadding)
modifier =
Modifier.testTag(LOGIN_TITLE_TEST_TAG)
.fillMaxWidth()
.padding(bottom = Dimens.smallPadding)
)

var tfFocusState: FocusState? by remember { mutableStateOf(null) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ const val LOCATION_INFO_TEST_TAG = "location_info_test_tag"

// ConnectScreen - Notification banner
const val NOTIFICATION_BANNER = "notification_banner"

const val LOGIN_TITLE_TEST_TAG = "login_title_test_tag"
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package net.mullvad.mullvadvpn.test.mockapi

import androidx.test.runner.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import net.mullvad.mullvadvpn.compose.test.LOGIN_TITLE_TEST_TAG
import net.mullvad.mullvadvpn.test.common.constant.DEFAULT_INTERACTION_TIMEOUT
import net.mullvad.mullvadvpn.test.common.extension.clickAgreeOnPrivacyDisclaimer
import net.mullvad.mullvadvpn.test.common.extension.clickAllowOnNotificationPermissionPromptIfApiLevel33AndAbove
import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout
import net.mullvad.mullvadvpn.test.mockapi.util.currentUtcTimeWithOffsetZero
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -28,7 +32,12 @@ class LoginMockApiTest : MockApiTest() {
app.attemptLogin(validAccountToken)

// Assert
device.findObjectWithTimeout(By.text("Login failed"))
val result =
device
.findObject(By.res(LOGIN_TITLE_TEST_TAG))
.wait(Until.textEquals("Login failed"), DEFAULT_INTERACTION_TIMEOUT)

assertTrue(result)
}

@Test
Expand Down