1+ import { Page , expect , Locator } from '@playwright/test' ;
2+
3+ export class ApplicationsPage {
4+ readonly page : Page ;
5+ readonly newAppButton : Locator ;
6+ readonly appNameInput : Locator ;
7+ readonly projectInput : Locator ;
8+ readonly repoUrlInput : Locator ;
9+ readonly pathInput : Locator ;
10+ readonly clusterUrlInput : Locator ;
11+ readonly namespaceInput : Locator ;
12+ readonly createButton : Locator ;
13+
14+ constructor ( page : Page ) {
15+ this . page = page ;
16+
17+ //header buttons
18+ this . newAppButton = page . getByRole ( 'button' , { name : / N E W A P P / i } ) ;
19+ this . createButton = page . getByRole ( 'button' , { name : 'Create' , exact : true } ) ;
20+
21+ this . appNameInput = page . getByLabel ( 'Application Name' , { exact : true } ) ;
22+ this . projectInput = page . locator ( '[qe-id="application-create-field-project"]' ) ;
23+ this . repoUrlInput = page . locator ( '.argo-form-row' ) . filter ( { hasText : 'Repository URL' } ) . locator ( 'input' ) . first ( ) ;
24+ this . pathInput = page . locator ( '.argo-form-row' ) . filter ( { hasText : 'Path' } ) . locator ( 'input' ) . first ( ) ;
25+
26+ //dest
27+ this . clusterUrlInput = page . locator ( '.argo-form-row' ) . filter ( { hasText : 'Cluster URL' } ) . locator ( 'input' ) . first ( ) ;
28+ this . namespaceInput = page . locator ( '.argo-form-row' )
29+ . filter ( { has : page . getByText ( 'Namespace' , { exact : true } ) } )
30+ . locator ( 'input' ) . first ( ) ;
31+ }
32+
33+ async navigate ( ) {
34+ await this . page . goto ( '/applications' ) ;
35+
36+ //ingnore the "failed to load data" banner if it appears
37+ const errorBanner = this . page . getByText ( 'try again' ) ;
38+ try {
39+ //wait 3 secs
40+ await errorBanner . waitFor ( { state : 'visible' , timeout : 3000 } ) ;
41+ await errorBanner . click ( ) ;
42+ } catch ( error ) {
43+ //banner didn't appear so just continue
44+ }
45+
46+ await expect ( this . newAppButton ) . toBeVisible ( { timeout : 15000 } ) ;
47+ }
48+
49+ //helper for fields that need to have select a pre existing option
50+ async fillDropdown ( locator : Locator , value : string ) {
51+ await locator . click ( ) ;
52+ await locator . pressSequentially ( value , { delay : 50 } ) ;
53+ await this . page . waitForTimeout ( 500 ) ;
54+ await locator . press ( 'Enter' ) ;
55+ }
56+
57+ async createApp ( appName : string , repoUrl : string , repoPath : string ) {
58+ await this . newAppButton . click ( ) ;
59+ await this . page . getByText ( 'Loading...' ) . first ( ) . waitFor ( { state : 'hidden' , timeout : 15000 } ) ;
60+
61+ await this . appNameInput . fill ( appName ) ;
62+ await this . fillDropdown ( this . projectInput , 'default' ) ;
63+
64+ //src
65+ await this . repoUrlInput . fill ( repoUrl ) ;
66+ await this . pathInput . fill ( repoPath ) ;
67+
68+ //dest
69+ await this . clusterUrlInput . fill ( 'https://kubernetes.default.svc' ) ;
70+
71+ //deploy
72+ await this . namespaceInput . fill ( 'openshift-gitops' ) ;
73+ await this . createButton . click ( ) ;
74+ }
75+
76+ async syncApplication ( appName : string ) {
77+ //search for app
78+ await this . page . getByPlaceholder ( / S e a r c h a p p l i c a t i o n s / i) . fill ( appName ) ;
79+
80+ const appContainer = this . page . locator ( '.white-box, .argo-table-list__row' ) . filter ( { hasText : appName } ) ;
81+ await appContainer . waitFor ( { state : 'visible' , timeout : 20000 } ) ;
82+ await appContainer . getByText ( 'Sync' , { exact : true } ) . click ( ) ;
83+
84+ //slideout panel
85+ const resourcesSection = this . page . locator ( '.argo-form-row' ) . filter ( { hasText : 'SYNCHRONIZE RESOURCES' } ) ;
86+ await expect ( resourcesSection ) . toContainText ( 'spring-petclinic' , { timeout : 15000 } ) ;
87+
88+ //click all
89+ await resourcesSection . getByText ( 'all' , { exact : true } ) . click ( ) ;
90+
91+ //handle the validation error that appears in older versions
92+ const validationWarning = resourcesSection . getByText ( 'Select at least one resource' ) ;
93+ await this . page . waitForTimeout ( 500 ) ;
94+
95+ //if the red text exists (4.14) wait for it to vanish so means boxes are checked
96+ if ( await validationWarning . isVisible ( ) ) {
97+ await validationWarning . waitFor ( { state : 'hidden' , timeout : 10000 } ) ;
98+ }
99+
100+ //click
101+ await this . page . getByRole ( 'button' , { name : / ^ s y n c h r o n i z e $ / i } ) . click ( ) ;
102+ }
103+
104+ async verifyStatus ( appName : string ) {
105+ //re-apply search filter just in case
106+ await this . page . getByPlaceholder ( / S e a r c h a p p l i c a t i o n s / i) . fill ( appName ) ;
107+ const appContainer = this . page . locator ( '.white-box, .argo-table-list__row' ) . filter ( { hasText : appName } ) ;
108+
109+ //90 secs
110+ await expect ( appContainer . getByText ( / s y n c e d / i) ) . toBeVisible ( { timeout : 90000 } ) ;
111+ await expect ( appContainer . getByText ( / h e a l t h y / i) ) . toBeVisible ( { timeout : 90000 } ) ;
112+ }
113+ }
0 commit comments