1- import { Page , expect } from '@playwright/test' ;
1+ import { Page } from '@playwright/test' ;
22
33export class LoginPage {
44 readonly page : Page ;
@@ -8,58 +8,58 @@ export class LoginPage {
88 }
99
1010 async goto ( ) {
11+ //navigate to the baseURL defined in playwright.config.ts
1112 await this . page . goto ( '/' ) ;
1213 }
1314
15+ //login Via OpenShift SSO
1416 async loginViaOpenShift ( user : string , pass : string , idp : string = 'kube:admin' ) {
15-
16- // ======================================================
17- // Argo CD Login Screen
18- // ======================================================
19- // We just wait patiently. Even if Argo CD does its weird
20- // redirect dance for 2 seconds, Playwright will wait up to
21- // 10 seconds for this button to finally appear.
17+ //click the SSO button on the Argo CD landing page
2218 const ssoButton = this . page . getByText ( / L O G I N V I A O P E N S H I F T / i) ;
2319 await ssoButton . waitFor ( { state : 'visible' , timeout : 10000 } ) ;
2420 await ssoButton . click ( ) ;
2521
26- // ======================================================
27- // OpenShift Login (with optional IDP step)
28- // ======================================================
29- // Sometimes OpenShift asks which IDP to use. We check for it quickly.
22+ //handle the OpenShift IDP selection screen if it appears
3023 try {
3124 const idpButton = this . page . getByText ( idp , { exact : true } ) ;
32- // Only wait 3 seconds. If it's not there, OpenShift skipped straight to the form.
3325 await idpButton . waitFor ( { state : 'visible' , timeout : 3000 } ) ;
3426 await idpButton . click ( ) ;
35- console . log ( `Clicked IDP: ${ idp } ` ) ;
3627 } catch ( e ) {
37- console . log ( 'No IDP selection screen, proceeding to credentials form...' ) ;
28+ //if it's not there then OpenShift likely defaulted to another
3829 }
3930
40- // Now fill out the actual Username/Password form
31+ //fil out the OpenShift credentials
4132 await this . page . getByLabel ( / U s e r n a m e / i) . waitFor ( { state : 'visible' } ) ;
4233 await this . page . getByLabel ( / U s e r n a m e / i) . fill ( user ) ;
4334 await this . page . getByLabel ( / P a s s w o r d / i) . fill ( pass ) ;
4435 await this . page . getByRole ( 'button' , { name : / L o g i n / i } ) . click ( ) ;
4536
46- // ======================================================
47- // Authorize Access (First Login Only)
48- // ======================================================
37+ //Auth Handle the Allow Permissions screen
4938 try {
50- const allowButton = this . page . getByRole ( 'button' , { name : 'Allow selected permissions' } ) ;
51- // Wait 5 seconds. If it's not there, we've already authorized in the past.
39+ const allowButton = this . page . getByRole ( 'button' , { name : / A l l o w s e l e c t e d p e r m i s s i o n s / i } ) ;
5240 await allowButton . waitFor ( { state : 'visible' , timeout : 5000 } ) ;
5341 await allowButton . click ( ) ;
54- console . log ( 'Clicked Authorize Access button.' ) ;
5542 } catch ( error ) {
56- console . log ( 'No Authorize screen appeared, continuing...' ) ;
43+ // Screen didn't appear likely already authorised.
5744 }
5845
59- // ======================================================
60- // Argo CD Dashboard (Success)
61- // ======================================================
62- // Wait for the URL to change to the applications dashboard
46+ //Success Checking make we land on the applications dashboard
6347 await this . page . waitForURL ( '**/applications**' , { timeout : 20000 } ) ;
6448 }
49+
50+ //login As Local Admin
51+ async loginAsLocalAdmin ( password : string ) {
52+ //force the local login screen by appending ?dex=none
53+ await this . page . goto ( `${ this . page . url ( ) } ?dex=none` ) ;
54+
55+ //fill out the local admin credentials
56+ const userField = this . page . getByRole ( 'textbox' ) . first ( ) ;
57+ await userField . waitFor ( { state : 'visible' } ) ;
58+ await userField . fill ( 'admin' ) ;
59+
60+ await this . page . locator ( 'input[type="password"]' ) . fill ( password ) ;
61+
62+ //Click sign in
63+ await this . page . getByRole ( 'button' , { name : / s i g n i n / i } ) . click ( ) ;
64+ }
6565}
0 commit comments