Skip to content

Commit

Permalink
Fix release_tests for the new login UI [VPNAND-2047].
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonides-proton authored and MargeBot committed Feb 3, 2025
1 parent 8c8c9e9 commit a5a8bb9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def accountSentryDsn = System.getenv("ACCOUNT_SENTRY_DSN") ?: ""
def preferencesSalt = System.getenv("DEPRECATED_PREF_SALT") ?: "Salt"
def preferencesKey = System.getenv("DEPRECATED_PREF_KEY") ?: "Key"
def serviceAccountCredentialsPath = project.hasProperty('serviceAccountFilePath') ? serviceAccountFilePath : "service_account.json"
def testAccountPassword = System.getenv("TEST_ACCOUNT_PASS") ?: "Pass"
def testAccountPassword = System.getenv("TEST_ACCOUNT_PASS") ?: project.hasProperty('testAccountPassword') ? testAccountPassword : "Pass"
def appId = project.hasProperty('appId') ? appId : "ch.protonvpn.android"
def supportedLocales = ['b+es+419', 'be', 'cs', 'de', 'el', 'en', 'es-rES', 'es-rMX', 'fa', 'fi', 'fr', 'hr', 'in', 'it', 'ja', 'ka', 'ko', 'nb-rNO', 'nl', 'pl', 'pt-rBR', 'pt-rPT', 'ro', 'ru', 'sk', 'sl', 'sv-rSE', 'tr', 'uk', 'zh-rTW']
def helpers = new Helpers(rootDir, providers)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ buildscript {
// We should migrate to version catalogs as soon as IDE support is available:
// https://issuetracker.google.com/issues/226078451
ext.androidx_lifecycle_version = '2.8.7'
ext.core_version = '30.3.1'
ext.core_version = '30.3.2'
ext.datastore_version = '1.1.1'
ext.desugar_jdk_version = '2.0.4'
ext.detekt_version = '1.23.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,35 @@

package com.protonvpn.android.release_tests.robots

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.protonvpn.android.release_tests.data.TestConstants
import me.proton.test.fusion.Fusion.byObject
import me.proton.test.fusion.Fusion.device
import me.proton.test.fusion.ui.uiautomator.ByObject

object LoginRobot {
fun signIn(username: String, password: String) {
fun signIn(username: String, password: String): LoginRobot {
navigateToSignIn()
enterCredentials(username, password)
pressSignIn()
waitUntilLoggedIn()
}

fun navigateToSignIn(): LoginRobot {
byObject.withTimeout(TestConstants.TWENTY_SECOND_TIMEOUT).withText("Sign in").click()
return this
}
// Skip Fusion, it's nothing but limitations.
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val hasNewUsernameInput = uiDevice.wait(
Until.hasObject(By.res("LOGIN_USERNAME_FIELD_TAG")),
TestConstants.FIVE_SECONDS_TIMEOUT_MS
)
if (hasNewUsernameInput) {
fillSignIn(username, password)
} else {
fillSignInLegacy(username, password)
}

fun enterCredentials(username: String, password: String): LoginRobot {
protonInput("usernameInput").typeText(username)
protonInput("passwordInput").typeText(password)
return this
}

fun pressSignIn(): LoginRobot {
// Use ID for the button because "Sign in" text is not unique (also used in header).
byObject.withResId(TestConstants.TEST_PACKAGE, "signInButton").click()
fun navigateToSignIn(): LoginRobot {
byObject.withTimeout(TestConstants.TWENTY_SECOND_TIMEOUT).withText("Sign in").click()
return this
}

Expand All @@ -57,7 +59,25 @@ object LoginRobot {
return this
}

private fun protonInput(resourceId: String): ByObject =
byObject.withResId(TestConstants.TEST_PACKAGE, resourceId)
private fun fillSignIn(username: String, password: String) {
byObject.protonComposeInput("LOGIN_USERNAME_FIELD_TAG").typeText(username)
byObject.withText("Continue").click()
byObject.protonComposeInput("LOGIN_PASSWORD_FIELD_TAG").typeText(password)
byObject.withText("Continue").click()
}

private fun fillSignInLegacy(username: String, password: String) {
byObject.protonInput("usernameInput").typeText(username)
byObject.protonInput("passwordInput").typeText(password)
// Use ID for the button because "Sign in" text is not unique (also used in header).
byObject.withResId(TestConstants.TEST_PACKAGE, "signInButton").click()
}

private fun ByObject.protonInput(resourceId: String): ByObject =
withResId(TestConstants.TEST_PACKAGE, resourceId)
.onDescendant(byObject.withResId(TestConstants.TEST_PACKAGE, "input"))
}

private fun ByObject.protonComposeInput(testTag: String): ByObject =
withResName(testTag)
.onDescendant(byObject.withResName("PROTON_OUTLINED_TEXT_INPUT_TAG"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class AltRoutingSli {
.addMeasurement(DurationMeasurement())
.setLogcatFilter(LokiConfig.logcatFilter)

LoginRobot.navigateToSignIn()
.enterCredentials("testas3", BuildConfig.TEST_ACCOUNT_PASSWORD)
.pressSignIn()
LoginRobot.signIn("testas3", BuildConfig.TEST_ACCOUNT_PASSWORD)

profile.measure {
LoginRobot.waitUntilLoggedIn()
Expand All @@ -78,4 +76,4 @@ class AltRoutingSli {
profile.pushLogcatLogs()
profile.clearLogcatLogs()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class MainMeasurementsSli {

@Before
fun setup() {
LoginRobot.navigateToSignIn()
.enterCredentials("testas3", BuildConfig.TEST_ACCOUNT_PASSWORD)
.pressSignIn()
LoginRobot.signIn("testas3", BuildConfig.TEST_ACCOUNT_PASSWORD)
}

@Test
Expand Down Expand Up @@ -126,4 +124,4 @@ class MainMeasurementsSli {
//Delay to prevent issues when sending SLI results
Thread.sleep(TestConstants.FIVE_SECONDS_TIMEOUT_MS)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class SmokeTest {
@Test
fun testSignIn() {
LoginRobot.signIn("testas3", BuildConfig.TEST_ACCOUNT_PASSWORD)
.waitUntilLoggedIn()
}
}
}

0 comments on commit a5a8bb9

Please sign in to comment.