@@ -114,12 +114,13 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
114114
115115 # Give page time to load
116116 import time
117+
117118 time .sleep (3 )
118119
119120 try :
120121 print (f"Current URL after navigation: { driver .current_url } " )
121122 print (f"Page title: { driver .title } " )
122-
123+
123124 # First, check if we're already on the dashboard (no login required)
124125 try :
125126 # Try multiple possible dashboard indicators
@@ -135,12 +136,14 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
135136 (By .CSS_SELECTOR , "[class*='odh-dashboard']" ),
136137 (By .CSS_SELECTOR , "[class*='app-launcher']" ),
137138 ]
138-
139+
139140 for locator in dashboard_indicators :
140141 try :
141142 element = driver .find_element (* locator )
142143 if element .is_displayed ():
143- print (f"Already on dashboard, no login required (found: { locator } )" )
144+ print (
145+ f"Already on dashboard, no login required (found: { locator } )"
146+ )
144147 return driver
145148 except :
146149 continue
@@ -149,19 +152,19 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
149152
150153 # Not on dashboard, try to login
151154 print ("Dashboard not found, attempting login..." )
152-
155+
153156 # First, check if we need to select an identity provider (OpenShift OAuth page)
154157 # This page typically shows buttons like "htpasswd", "ldap", etc.
155158 try :
156159 print ("Checking for identity provider selection page..." )
157-
160+
158161 # Try to find all available IDPs
159162 idp_selectors = [
160163 (By .XPATH , "//a[contains(@href, 'oauth/authorize')]" ),
161164 (By .XPATH , "//div[@data-test-id='login']//a" ),
162165 (By .XPATH , "//div[contains(@class, 'login')]//a" ),
163166 ]
164-
167+
165168 all_idp_buttons = []
166169 for by , value in idp_selectors :
167170 try :
@@ -170,33 +173,49 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
170173 elem_text = elem .text .lower () if elem .text else ""
171174 elem_href = elem .get_attribute ("href" ) or ""
172175 # Check if it's an IDP link
173- if "authorize" in elem_href or any (keyword in elem_text for keyword in ["htpasswd" , "ldap" , "login" , "log in" , "sign in" , "kube" ]):
176+ if "authorize" in elem_href or any (
177+ keyword in elem_text
178+ for keyword in [
179+ "htpasswd" ,
180+ "ldap" ,
181+ "login" ,
182+ "log in" ,
183+ "sign in" ,
184+ "kube" ,
185+ ]
186+ ):
174187 all_idp_buttons .append ((elem , elem .text , elem_href ))
175- print (f"Found IDP option: text='{ elem .text } ', href='{ elem_href [:100 ]} '" )
188+ print (
189+ f"Found IDP option: text='{ elem .text } ', href='{ elem_href [:100 ]} '"
190+ )
176191 except Exception as e :
177192 continue
178-
193+
179194 if all_idp_buttons :
180195 # Try to intelligently select the right IDP based on username
181196 username = test_credentials ["username" ].lower ()
182197 selected_idp = None
183-
198+
184199 # Strategy 1: Match username pattern to IDP name
185200 if "ldap" in username :
186201 # Look for ldap IDP
187202 for elem , text , href in all_idp_buttons :
188203 if "ldap" in text .lower () or "ldap" in href .lower ():
189204 selected_idp = (elem , text )
190- print (f"Selected LDAP IDP based on username pattern: { text } " )
205+ print (
206+ f"Selected LDAP IDP based on username pattern: { text } "
207+ )
191208 break
192209 elif "htpasswd" in username or "admin" in username :
193210 # Look for htpasswd IDP
194211 for elem , text , href in all_idp_buttons :
195212 if "htpasswd" in text .lower () or "htpasswd" in href .lower ():
196213 selected_idp = (elem , text )
197- print (f"Selected htpasswd IDP based on username pattern: { text } " )
214+ print (
215+ f"Selected htpasswd IDP based on username pattern: { text } "
216+ )
198217 break
199-
218+
200219 # Strategy 2: If no match, use environment variable if set
201220 if not selected_idp :
202221 idp_name = os .getenv ("OPENSHIFT_IDP_NAME" , "" ).lower ()
@@ -206,16 +225,18 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
206225 selected_idp = (elem , text )
207226 print (f"Selected IDP from environment variable: { text } " )
208227 break
209-
228+
210229 # Strategy 3: If still no match and only one IDP, use it
211230 if not selected_idp and len (all_idp_buttons ) == 1 :
212231 selected_idp = (all_idp_buttons [0 ][0 ], all_idp_buttons [0 ][1 ])
213232 print (f"Only one IDP available, using: { selected_idp [1 ]} " )
214-
233+
215234 # Strategy 4: If multiple IDPs and no match, skip IDP selection
216235 # (some clusters may not require IDP selection if there's a default)
217236 if not selected_idp :
218- print (f"Multiple IDPs found but couldn't determine which to use. Available: { [text for _ , text , _ in all_idp_buttons ]} " )
237+ print (
238+ f"Multiple IDPs found but couldn't determine which to use. Available: { [text for _ , text , _ in all_idp_buttons ]} "
239+ )
219240 print ("Skipping IDP selection, will try direct login form" )
220241 else :
221242 print (f"Clicking identity provider button: { selected_idp [1 ]} " )
@@ -224,7 +245,7 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
224245 print (f"After IDP click - URL: { driver .current_url } " )
225246 except Exception as e :
226247 print (f"No identity provider selection needed or failed to handle: { e } " )
227-
248+
228249 # Handle OpenShift OAuth login flow
229250 # Wait for username field (various possible IDs depending on OAuth provider)
230251 username_field = None
@@ -292,18 +313,18 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
292313 # Try multiple possible indicators that we're on the dashboard
293314 print ("Waiting for dashboard to load..." )
294315 dashboard_loaded = False
295-
316+
296317 for i in range (6 ): # Try for up to 30 seconds (6 * 5 seconds)
297318 time .sleep (5 )
298319 print (f"Attempt { i + 1 } /6 - Current URL: { driver .current_url } " )
299320 print (f"Attempt { i + 1 } /6 - Page title: { driver .title } " )
300-
321+
301322 # Check if page title indicates we're on the dashboard
302323 if "Red Hat OpenShift AI" in driver .title or "OpenShift" in driver .title :
303324 print (f"Dashboard loaded successfully (title: { driver .title } )" )
304325 dashboard_loaded = True
305326 break
306-
327+
307328 # Try finding dashboard elements
308329 for locator in dashboard_indicators :
309330 try :
@@ -314,7 +335,7 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
314335 break
315336 except :
316337 continue
317-
338+
318339 if dashboard_loaded :
319340 break
320341
@@ -336,14 +357,13 @@ def login_to_dashboard(selenium_driver, dashboard_url, test_credentials):
336357 print (f"Screenshot saved to: { screenshot_path } " )
337358 except :
338359 pass
339-
360+
340361 # Print page source for debugging (first 1000 chars)
341362 try :
342363 print (f"\n Page source preview:\n { driver .page_source [:1000 ]} " )
343364 except :
344365 pass
345-
366+
346367 raise
347368
348369 return driver
349-
0 commit comments