21
21
22
22
package com.protonvpn.android.release_tests.robots
23
23
24
+ import androidx.test.platform.app.InstrumentationRegistry
25
+ import androidx.test.uiautomator.By
26
+ import androidx.test.uiautomator.UiDevice
27
+ import androidx.test.uiautomator.Until
24
28
import com.protonvpn.android.release_tests.data.TestConstants
25
29
import me.proton.test.fusion.Fusion.byObject
26
- import me.proton.test.fusion.Fusion.device
27
30
import me.proton.test.fusion.ui.uiautomator.ByObject
28
31
29
32
object LoginRobot {
30
- fun signIn (username : String , password : String ) {
33
+ fun signIn (username : String , password : String ): LoginRobot {
31
34
navigateToSignIn()
32
- enterCredentials(username, password)
33
- pressSignIn()
34
- waitUntilLoggedIn()
35
- }
36
35
37
- fun navigateToSignIn (): LoginRobot {
38
- byObject.withTimeout(TestConstants .TWENTY_SECOND_TIMEOUT ).withText(" Sign in" ).click()
39
- return this
40
- }
36
+ // Skip Fusion, it's nothing but limitations.
37
+ val uiDevice = UiDevice .getInstance(InstrumentationRegistry .getInstrumentation())
38
+ val hasNewUsernameInput = uiDevice.wait(
39
+ Until .hasObject(By .res(" LOGIN_USERNAME_FIELD_TAG" )),
40
+ TestConstants .FIVE_SECONDS_TIMEOUT_MS
41
+ )
42
+ if (hasNewUsernameInput) {
43
+ fillSignIn(username, password)
44
+ } else {
45
+ fillSignInLegacy(username, password)
46
+ }
41
47
42
- fun enterCredentials (username : String , password : String ): LoginRobot {
43
- protonInput(" usernameInput" ).typeText(username)
44
- protonInput(" passwordInput" ).typeText(password)
45
48
return this
46
49
}
47
50
48
- fun pressSignIn (): LoginRobot {
49
- // Use ID for the button because "Sign in" text is not unique (also used in header).
50
- byObject.withResId(TestConstants .TEST_PACKAGE , " signInButton" ).click()
51
+ fun navigateToSignIn (): LoginRobot {
52
+ byObject.withTimeout(TestConstants .TWENTY_SECOND_TIMEOUT ).withText(" Sign in" ).click()
51
53
return this
52
54
}
53
55
@@ -57,7 +59,25 @@ object LoginRobot {
57
59
return this
58
60
}
59
61
60
- private fun protonInput (resourceId : String ): ByObject =
61
- byObject.withResId(TestConstants .TEST_PACKAGE , resourceId)
62
+ private fun fillSignIn (username : String , password : String ) {
63
+ byObject.protonComposeInput(" LOGIN_USERNAME_FIELD_TAG" ).typeText(username)
64
+ byObject.withText(" Continue" ).click()
65
+ byObject.protonComposeInput(" LOGIN_PASSWORD_FIELD_TAG" ).typeText(password)
66
+ byObject.withText(" Continue" ).click()
67
+ }
68
+
69
+ private fun fillSignInLegacy (username : String , password : String ) {
70
+ byObject.protonInput(" usernameInput" ).typeText(username)
71
+ byObject.protonInput(" passwordInput" ).typeText(password)
72
+ // Use ID for the button because "Sign in" text is not unique (also used in header).
73
+ byObject.withResId(TestConstants .TEST_PACKAGE , " signInButton" ).click()
74
+ }
75
+
76
+ private fun ByObject.protonInput (resourceId : String ): ByObject =
77
+ withResId(TestConstants .TEST_PACKAGE , resourceId)
62
78
.onDescendant(byObject.withResId(TestConstants .TEST_PACKAGE , " input" ))
63
- }
79
+
80
+ private fun ByObject.protonComposeInput (testTag : String ): ByObject =
81
+ withResName(testTag)
82
+ .onDescendant(byObject.withResName(" PROTON_OUTLINED_TEXT_INPUT_TAG" ))
83
+ }
0 commit comments