7
7
8
8
class WindowsTest (UnityTest ):
9
9
10
- altdriver = None
11
-
12
10
@classmethod
13
11
def setUpClass (cls ):
14
12
open_sample_app ()
15
- cls .altdriver = AltDriver ()
13
+ time .sleep (5 ) # Give time for the app to open
14
+ super ().setUpClass ()
16
15
17
16
@classmethod
18
17
def tearDownClass (cls ):
19
- cls . altdriver . stop ()
20
- stop_sample_app ()
18
+ super (). tearDownClass ()
19
+ stop_sample_app ()
21
20
22
- def test_1_device_code_login (self ):
23
- # Select use device code auth
24
- self .altdriver .find_object (By .NAME , "DeviceCodeAuth" ).tap ()
21
+ def restart_app_and_altdriver (self ):
22
+ self .stop_altdriver ()
23
+ stop_sample_app ()
24
+ open_sample_app ()
25
+ time .sleep (5 ) # Give time for the app to open
26
+ self .start_altdriver ()
27
+
28
+ def select_auth_type (self , use_pkce : bool ):
29
+ auth_type = "PKCE" if use_pkce else "DeviceCodeAuth"
30
+ self .get_altdriver ().find_object (By .NAME , auth_type ).tap ()
31
+
32
+ def login (self , use_pkce : bool ):
33
+ self .select_auth_type (use_pkce )
25
34
26
35
# Wait for unauthenticated screen
27
- self .altdriver .wait_for_current_scene_to_be ("UnauthenticatedScene" )
36
+ self .get_altdriver () .wait_for_current_scene_to_be ("UnauthenticatedScene" )
28
37
29
38
for attempt in range (2 ):
30
39
try :
31
40
# Check app state
32
- login_button = self .altdriver .find_object (By .NAME , "LoginBtn" )
41
+ login_button = self .get_altdriver () .find_object (By .NAME , "LoginBtn" )
33
42
print ("Found login button, app is in the correct state" )
34
43
35
44
# Login
36
45
print ("Logging in..." )
37
46
launch_browser ()
38
47
bring_sample_app_to_foreground ()
39
48
login_button .tap ()
40
- login ()
49
+ login (use_pkce )
41
50
bring_sample_app_to_foreground ()
42
51
43
52
# Wait for authenticated screen
44
- self .altdriver .wait_for_current_scene_to_be ("AuthenticatedScene" )
53
+ self .get_altdriver () .wait_for_current_scene_to_be ("AuthenticatedScene" )
45
54
stop_browser ()
46
55
print ("Logged in" )
47
56
return
@@ -54,31 +63,38 @@ def test_1_device_code_login(self):
54
63
# Relogin (optional: only if the button is present)
55
64
print ("Try reset the app and log out once..." )
56
65
try :
57
- self .altdriver .wait_for_object (By .NAME , "ReloginBtn" ).tap ()
66
+ self .get_altdriver () .wait_for_object (By .NAME , "ReloginBtn" ).tap ()
58
67
except Exception as e :
59
68
print ("ReloginBtn not found, skipping relogin step. User may already be in AuthenticatedScene." )
60
69
61
70
# Wait for authenticated screen
62
- self .altdriver .wait_for_current_scene_to_be ("AuthenticatedScene" )
71
+ self .get_altdriver () .wait_for_current_scene_to_be ("AuthenticatedScene" )
63
72
print ("Re-logged in" )
64
73
65
74
# Logout
66
75
print ("Logging out..." )
67
76
launch_browser ()
68
77
bring_sample_app_to_foreground ()
69
- self .altdriver .find_object (By .NAME , "LogoutBtn" ).tap ()
78
+ self .get_altdriver () .find_object (By .NAME , "LogoutBtn" ).tap ()
70
79
time .sleep (5 )
71
80
bring_sample_app_to_foreground ()
72
-
81
+
73
82
# Wait for unauthenticated screen
74
- self .altdriver .wait_for_current_scene_to_be ("UnauthenticatedScene" )
83
+ self .get_altdriver () .wait_for_current_scene_to_be ("UnauthenticatedScene" )
75
84
stop_browser ()
76
85
print ("Logged out and successfully reset app" )
77
86
78
87
time .sleep (5 )
79
88
else :
80
89
raise SystemExit (f"Failed to reset app { err } " )
81
90
91
+ def test_1a_pkce_login (self ):
92
+ self .login (True )
93
+
94
+ def test_1b_device_code_login (self ):
95
+ self .restart_app_and_altdriver ()
96
+ self .login (False )
97
+
82
98
def test_2_other_functions (self ):
83
99
self .test_0_other_functions ()
84
100
@@ -92,111 +108,95 @@ def test_5_zkevm_functions(self):
92
108
self .test_3_zkevm_functions ()
93
109
94
110
def test_6_relogin (self ):
95
- # Close and reopen app
96
- stop_sample_app ()
97
- open_sample_app ()
98
-
99
- # Restart AltTester
100
- self .altdriver .stop ()
101
- self .altdriver = AltDriver ()
102
- time .sleep (5 )
111
+ self .restart_app_and_altdriver ()
103
112
104
113
# Select use device code auth
105
- self .altdriver . find_object ( By . NAME , "DeviceCodeAuth" ). tap ( )
114
+ self .select_auth_type ( use_pkce = False )
106
115
107
116
# Relogin
108
117
print ("Re-logging in..." )
109
- self .altdriver .wait_for_object (By .NAME , "ReloginBtn" ).tap ()
118
+ self .get_altdriver () .wait_for_object (By .NAME , "ReloginBtn" ).tap ()
110
119
111
120
# Wait for authenticated screen
112
- self .altdriver .wait_for_current_scene_to_be ("AuthenticatedScene" )
121
+ self .get_altdriver () .wait_for_current_scene_to_be ("AuthenticatedScene" )
113
122
print ("Re-logged in" )
114
123
115
124
# Get access token
116
- self .altdriver .find_object (By .NAME , "GetAccessTokenBtn" ).tap ()
117
- output = self .altdriver .find_object (By .NAME , "Output" )
125
+ self .get_altdriver () .find_object (By .NAME , "GetAccessTokenBtn" ).tap ()
126
+ output = self .get_altdriver () .find_object (By .NAME , "Output" )
118
127
self .assertTrue (len (output .get_text ()) > 50 )
119
128
120
129
# Click Connect to IMX button
121
- self .altdriver .find_object (By .NAME , "ConnectBtn" ).tap ()
130
+ self .get_altdriver () .find_object (By .NAME , "ConnectBtn" ).tap ()
122
131
self .assertEqual ("Connected to IMX" , output .get_text ())
123
132
124
- self .altdriver .stop ()
125
-
126
133
def test_7_reconnect_device_code_connect_imx (self ):
127
- # Close and reopen app
128
- stop_sample_app ()
129
- open_sample_app ()
134
+ self .restart_app_and_altdriver ()
130
135
131
- # Restart AltTester
132
- self .altdriver .stop ()
133
- self .altdriver = AltDriver ()
134
- time .sleep (5 )
135
-
136
- # Select use device code auth
137
- self .altdriver .find_object (By .NAME , "DeviceCodeAuth" ).tap ()
136
+ use_pkce = False
137
+ self .select_auth_type (use_pkce )
138
138
139
139
# Reconnect
140
140
print ("Reconnecting..." )
141
- self .altdriver .wait_for_object (By .NAME , "ReconnectBtn" ).tap ()
141
+ self .get_altdriver () .wait_for_object (By .NAME , "ReconnectBtn" ).tap ()
142
142
143
143
# Wait for authenticated screen
144
- self .altdriver .wait_for_current_scene_to_be ("AuthenticatedScene" )
144
+ self .get_altdriver () .wait_for_current_scene_to_be ("AuthenticatedScene" )
145
145
print ("Reconnected" )
146
146
147
147
# Get access token
148
- self .altdriver .find_object (By .NAME , "GetAccessTokenBtn" ).tap ()
149
- output = self .altdriver .find_object (By .NAME , "Output" )
148
+ self .get_altdriver () .find_object (By .NAME , "GetAccessTokenBtn" ).tap ()
149
+ output = self .get_altdriver () .find_object (By .NAME , "Output" )
150
150
self .assertTrue (len (output .get_text ()) > 50 )
151
151
152
152
# Get address without having to click Connect to IMX button
153
- self .altdriver .find_object (By .NAME , "GetAddressBtn" ).tap ()
153
+ self .get_altdriver () .find_object (By .NAME , "GetAddressBtn" ).tap ()
154
154
self .assertEqual (TestConfig .WALLET_ADDRESS , output .get_text ())
155
155
156
156
# Logout
157
157
print ("Logging out..." )
158
158
launch_browser ()
159
159
bring_sample_app_to_foreground ()
160
- self .altdriver .find_object (By .NAME , "LogoutBtn" ).tap ()
160
+ self .get_altdriver () .find_object (By .NAME , "LogoutBtn" ).tap ()
161
161
time .sleep (5 )
162
162
bring_sample_app_to_foreground ()
163
163
164
164
# Wait for authenticated screen
165
- self .altdriver .wait_for_current_scene_to_be ("UnauthenticatedScene" )
165
+ self .get_altdriver () .wait_for_current_scene_to_be ("UnauthenticatedScene" )
166
166
stop_browser ()
167
167
print ("Logged out" )
168
168
169
169
# Connect IMX
170
170
print ("Logging in and connecting to IMX..." )
171
171
launch_browser ()
172
172
bring_sample_app_to_foreground ()
173
- self .altdriver .wait_for_object (By .NAME , "ConnectBtn" ).tap ()
174
- login ()
173
+ self .get_altdriver () .wait_for_object (By .NAME , "ConnectBtn" ).tap ()
174
+ login (use_pkce )
175
175
bring_sample_app_to_foreground ()
176
-
176
+
177
177
# Wait for authenticated screen
178
- self .altdriver .wait_for_current_scene_to_be ("AuthenticatedScene" )
178
+ self .get_altdriver () .wait_for_current_scene_to_be ("AuthenticatedScene" )
179
179
print ("Logged in and connected to IMX" )
180
180
stop_browser ()
181
181
182
182
# Get access token
183
- self .altdriver .find_object (By .NAME , "GetAccessTokenBtn" ).tap ()
184
- output = self .altdriver .find_object (By .NAME , "Output" )
183
+ self .get_altdriver () .find_object (By .NAME , "GetAccessTokenBtn" ).tap ()
184
+ output = self .get_altdriver () .find_object (By .NAME , "Output" )
185
185
self .assertTrue (len (output .get_text ()) > 50 )
186
186
187
187
# Get address without having to click Connect to IMX button
188
- self .altdriver .find_object (By .NAME , "GetAddressBtn" ).tap ()
188
+ self .get_altdriver () .find_object (By .NAME , "GetAddressBtn" ).tap ()
189
189
self .assertEqual (TestConfig .WALLET_ADDRESS , output .get_text ())
190
190
191
191
# Logout
192
192
launch_browser ()
193
193
bring_sample_app_to_foreground ()
194
194
print ("Logging out..." )
195
- self .altdriver .find_object (By .NAME , "LogoutBtn" ).tap ()
195
+ self .get_altdriver () .find_object (By .NAME , "LogoutBtn" ).tap ()
196
196
time .sleep (5 )
197
197
bring_sample_app_to_foreground ()
198
-
198
+
199
199
# Wait for authenticated screen
200
- self .altdriver .wait_for_current_scene_to_be ("UnauthenticatedScene" )
200
+ self .get_altdriver () .wait_for_current_scene_to_be ("UnauthenticatedScene" )
201
201
stop_browser ()
202
202
print ("Logged out" )
0 commit comments