Skip to content

Commit d50a497

Browse files
committed
test: reset mac app state
1 parent f3a26ce commit d50a497

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

sample/Tests/test/test_mac.py

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,52 @@ def test_1_device_code_login(self):
9696
# Wait for unauthenticated screen
9797
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
9898

99-
# Login
100-
print("Logging in...")
101-
self.setupChrome()
102-
bring_sample_app_to_foreground()
103-
self.altdriver.wait_for_object(By.NAME, "LoginBtn").tap()
104-
self.login()
105-
bring_sample_app_to_foreground()
106-
107-
# Wait for authenticated screen
108-
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
109-
print("Logged in")
99+
for attempt in range(2):
100+
try:
101+
# Check app state
102+
login_button = self.altdriver.find_object(By.NAME, "LoginBtn")
103+
print("Found login button, app is in the correct state")
104+
105+
# Login
106+
print("Logging in...")
107+
self.setupChrome()
108+
bring_sample_app_to_foreground()
109+
login_button.tap()
110+
self.login()
111+
bring_sample_app_to_foreground()
112+
113+
# Wait for authenticated screen
114+
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
115+
print("Logged in")
116+
return
117+
except Exception as err:
118+
if attempt == 0:
119+
# Reset app
120+
121+
# Relogin
122+
print("Try reset the app and log out once...")
123+
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()
124+
125+
# Wait for authenticated screen
126+
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
127+
print("Re-logged in")
128+
129+
# Logout
130+
print("Logging out...")
131+
self.setupChrome()
132+
bring_sample_app_to_foreground()
133+
self.altdriver.find_object(By.NAME, "LogoutBtn").tap()
134+
time.sleep(5)
135+
bring_sample_app_to_foreground()
136+
137+
# Wait for unauthenticated screen
138+
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")
139+
self.seleniumdriver.quit()
140+
print("Logged out and successfully reset app")
141+
142+
time.sleep(5)
143+
else:
144+
raise SystemExit(f"Failed to reset app {err}")
110145

111146
def test_2_other_functions(self):
112147
self.test_0_other_functions()

0 commit comments

Comments
 (0)