@@ -81,53 +81,38 @@ def login(self):
8181 raise SystemExit (f"App stuck in unknown scene: { current_scene } " )
8282
8383 def _perform_login (self ):
84- """Perform normal login flow when app is in UnauthenticatedScene"""
85- try :
86- # Debug: Check what scene we're actually in and what objects exist
84+ """Perform normal login flow when app is in UnauthenticatedScene.
85+ Retries once if the first attempt fails (e.g. deep link dialog not handled)."""
86+ for attempt in range ( 2 ):
8787 try :
8888 current_scene = self .get_altdriver ().get_current_scene ()
89- print (f"DEBUG: _perform_login - current scene: { current_scene } " )
90- except Exception as e :
91- print (f"DEBUG: Could not get current scene: { e } " )
92-
93- # Wait a moment for UI to stabilize and check if app is still running
94- time .sleep (3 )
95-
96- # Debug: Check if we can still communicate with the app
97- try :
98- connection_test = self .get_altdriver ().get_current_scene ()
99- print (f"DEBUG: App still responsive, scene: { connection_test } " )
100- except Exception as e :
101- print (f"DEBUG: App may have crashed or lost connection: { e } " )
102- raise SystemExit ("App connection lost during login attempt" )
103-
104- # Debug: Try to find any buttons to see what's available
105- try :
106- all_objects = self .get_altdriver ().get_all_elements ()
107- button_objects = [obj for obj in all_objects if 'btn' in obj .name .lower () or 'button' in obj .name .lower ()]
108- print (f"DEBUG: Found button-like objects: { [obj .name for obj in button_objects ]} " )
109- except Exception as e :
110- print (f"DEBUG: Could not get all objects: { e } " )
111-
112- # Check for login button
113- login_button = self .get_altdriver ().find_object (By .NAME , "LoginBtn" )
114- print ("Found login button - performing login" )
115-
116- # Login
117- launch_browser ()
118- bring_sample_app_to_foreground ()
119- login_button .tap ()
120- login ()
121- bring_sample_app_to_foreground ()
122-
123- # Wait for authenticated screen
124- self .get_altdriver ().wait_for_current_scene_to_be ("AuthenticatedScene" )
125- stop_browser ()
126- print ("[SUCCESS] Login successful" )
127-
128- except Exception as err :
129- stop_browser ()
130- raise SystemExit (f"Login failed: { err } " )
89+ print (f"Login attempt { attempt + 1 } /2 - current scene: { current_scene } " )
90+
91+ time .sleep (3 )
92+
93+ login_button = self .get_altdriver ().find_object (By .NAME , "LoginBtn" )
94+ print ("Found login button - performing login" )
95+
96+ launch_browser ()
97+ bring_sample_app_to_foreground ()
98+ login_button .tap ()
99+ login ()
100+ bring_sample_app_to_foreground ()
101+
102+ self .get_altdriver ().wait_for_current_scene_to_be ("AuthenticatedScene" , timeout = 30 )
103+ stop_browser ()
104+ print ("[SUCCESS] Login successful" )
105+ return
106+
107+ except Exception as err :
108+ stop_browser ()
109+ if attempt == 0 :
110+ print (f"Login attempt 1 failed: { err } " )
111+ print ("Retrying login..." )
112+ time .sleep (5 )
113+ bring_sample_app_to_foreground ()
114+ else :
115+ raise SystemExit (f"Login failed after 2 attempts: { err } " )
131116
132117 def _logout_and_login (self ):
133118 """Handle logout and then login when app starts authenticated"""
0 commit comments