11import { test , expect } from '@playwright/test' ;
2- import { doLogin } from './helper.js' ;
2+ import { doLogin , createGeneralPage , createCWLPage } from './helper.js' ;
33
44test . describe ( 'Generic Test Suite - CWL and General access' , ( ) => {
55 const password = 'test' ;
6+ const titleMessage = 'Playwright Test Basic Page' ;
67 const bodyMessage = 'Playwright body text' ;
7- const generalpageURL = ' /general' ;
8- const cwlpageURL = ' /cwl' ;
8+ const generalpageURL = ` /general- ${ Date . now ( ) } ` ;
9+ const cwlpageURL = ` /cwl- ${ Date . now ( ) } ` ;
910
1011 test . beforeEach ( async ( { page, baseURL } ) => {
11- await doLogin ( page , baseURL ) ;
12+ await doLogin ( page , baseURL ) ;
13+ await createGeneralPage ( page , generalpageURL , titleMessage , bodyMessage ) ;
14+ await createCWLPage ( page , cwlpageURL , titleMessage , bodyMessage ) ;
1215 } ) ;
1316
14- test ( 'Create a basic page with General access' , async ( { page } ) => {
17+ test ( 'Create and test CWL user access' , async ( { page } ) => {
18+ // Check basic pages are created
1519 await page . goto ( generalpageURL ) ;
16- const titleMessage = 'Playwright Test Basic Page - General' ;
17- const text = await page . locator ( '#block-olivero-page-title' ) . textContent ( ) ;
18-
19- if ( text && text . includes ( titleMessage ) ) {
20- console . log ( 'Page already exists. Skipping creation.' ) ;
21- } else {
22- await page . goto ( '/node/add/page' ) ;
23-
24- // Type title
25- const titleInput = page . locator ( '[data-drupal-selector="edit-title-wrapper"] input' ) ;
26- await titleInput . fill ( titleMessage ) ;
27- await expect ( titleInput ) . toHaveValue ( titleMessage ) ;
28-
29- // Locate CKEditor editable area by class + role
30- const ckEditor = page . locator ( '#edit-body-wrapper .ck[role="textbox"]' ) ;
31-
32- // Focus and type text (equivalent to realClick + realType)
33- await ckEditor . click ( ) ;
34- await page . keyboard . type ( bodyMessage , { delay : 0 } ) ;
35-
36- // Verify CKEditor content using its API
37- const editorData = await ckEditor . evaluate ( el => el . ckeditorInstance . getData ( ) ) ;
38- await expect ( editorData ) . toContain ( bodyMessage ) ;
39-
40- // Publish the content type
41- const status = page . locator ( '[data-drupal-selector="edit-status-value"]' ) ;
42- await status . check ( ) ;
43-
44- // Check General Visibility
45- await page . fill ( '[data-drupal-selector="edit-field-visibility-0-target-id"]' , 'General' ) ;
46- await expect ( page . locator ( '#edit-field-visibility-0-target-id' ) ) . toHaveValue ( / G e n e r a l / ) ;
47-
48- // Add menu
49- await page . locator ( '[data-drupal-selector="edit-menu"]' ) . first ( ) . locator ( 'summary' ) . click ( ) ;
50- await page . check ( 'input[type="checkbox"][name="menu[enabled]"]' ) ;
51-
52- // Add alias
53- await page . locator ( '[data-drupal-selector="edit-path-0"]' ) . click ( ) ;
54- await page . fill ( '[data-drupal-selector="edit-path-0-alias"]' , generalpageURL ) ;
55-
56- // Save changes
57- await page . locator ( ' [data-drupal-selector="edit-submit"]' ) . click ( ) ;
58- }
59-
60- // Verify the page content
6120 await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
6221 await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
63- } ) ;
22+ await expect ( page . locator ( '.field--name-field-visibility .field__item' ) ) . toContainText ( 'General' ) ;
6423
65- test ( 'Create a basic page with CWL access' , async ( { page } ) => {
6624 await page . goto ( cwlpageURL ) ;
67- const titleMessage = 'Playwright Test Basic Page - CWL' ;
68- const text = await page . locator ( '#block-olivero-page-title' ) . textContent ( ) ;
69-
70- if ( text && text . includes ( titleMessage ) ) {
71- console . log ( 'Page already exists. Skipping creation.' ) ;
72- } else {
73-
74- await page . goto ( '/node/add/page' ) ;
75-
76- // Type title
77- const titleInput = page . locator ( '[data-drupal-selector="edit-title-wrapper"] input' ) ;
78- await titleInput . fill ( titleMessage ) ;
79- await expect ( titleInput ) . toHaveValue ( titleMessage ) ;
80-
81- // Locate CKEditor editable area by class + role
82- const ckEditor = page . locator ( '#edit-body-wrapper .ck[role="textbox"]' ) ;
83-
84- // Focus and type text (equivalent to realClick + realType)
85- await ckEditor . click ( ) ;
86- await page . keyboard . type ( bodyMessage , { delay : 0 } ) ;
87-
88- // Verify CKEditor content using its API
89- const editorData = await ckEditor . evaluate ( el => el . ckeditorInstance . getData ( ) ) ;
90- await expect ( editorData ) . toContain ( bodyMessage ) ;
91-
92- // Publish the content type
93- const status = page . locator ( '[data-drupal-selector="edit-status-value"]' ) ;
94- await status . check ( ) ;
95-
96- // Check General Visibility
97- await page . fill ( '[data-drupal-selector="edit-field-visibility-0-target-id"]' , 'CWL' ) ;
98- await expect ( page . locator ( '#edit-field-visibility-0-target-id' ) ) . toHaveValue ( / C W L / ) ;
99-
100- // Add menu
101- await page . locator ( '[data-drupal-selector="edit-menu"]' ) . first ( ) . locator ( 'summary' ) . click ( ) ;
102- await page . check ( 'input[type="checkbox"][name="menu[enabled]"]' ) ;
103-
104- // Add alias
105- await page . locator ( '[data-drupal-selector="edit-path-0"]' ) . click ( ) ;
106- await page . fill ( '[data-drupal-selector="edit-path-0-alias"]' , cwlpageURL ) ;
107-
108- // Save changes
109- await page . locator ( ' [data-drupal-selector="edit-submit"]' ) . click ( ) ;
110- }
111-
112- // Verify the page content
11325 await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
11426 await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
115- } ) ;
27+ await expect ( page . locator ( '.field--name-field-visibility .field__item' ) ) . toContainText ( 'CWL' ) ;
11628
117- test ( 'Create and test CWL user access' , async ( { page } ) => {
29+ // Create CWL user
11830 await page . goto ( '/admin/people' ) ;
119- const username = 'playwrightCWL' ;
120- const usernames = await page . locator ( '#views-form-user-admin-people-page-1 .username' ) . allTextContents ( ) ;
121- const exists = usernames . some ( name => name . includes ( username ) ) ;
31+ const username = `testCWL-${ Date . now ( ) } ` ;
32+ await page . goto ( '/admin/people/create' ) ;
12233
123- if ( exists ) {
124- console . log ( `User "${ username } " already exists. Skipping creation.` ) ;
125- } else {
126- await page . goto ( '/admin/people/create' ) ;
34+ // Type username
35+ await page . fill ( '[data-drupal-selector="edit-name"]' , username ) ;
12736
128- // Type username
129- await page . fill ( '[data-drupal-selector="edit-name"]' , username ) ;
37+ // Type password
38+ await page . fill ( '[data-drupal-selector="edit-pass-pass1"]' , password ) ;
39+ await page . fill ( '[data-drupal-selector="edit-pass-pass2"]' , password ) ;
13040
131- // Type password
132- await page . fill ( '[data-drupal-selector="edit-pass-pass1"]' , password ) ;
133- await page . fill ( '[data-drupal-selector="edit-pass-pass2"]' , password ) ;
41+ // Check CWL Role
42+ await page . check ( '[data-drupal-selector="edit-roles-cwl"][name="roles[cwl]"]' ) ;
13443
135- // Check CWL Role
136- await page . check ( ' [data-drupal-selector="edit-roles-cwl"][name="roles[cwl]"]' ) ;
44+ // Save changes
45+ await page . locator ( ' [data-drupal-selector="edit-submit"]' ) . click ( ) ;
13746
138- // Save changes
139- await page . locator ( ' [data-drupal-selector="edit-submit"]' ) . click ( ) ;
140-
141- // Verify the page content
142- const primaryContent = page . locator ( '#message-status-title' ) ;
143- await expect ( primaryContent ) . toContainText ( 'Status message' ) ;
144- }
47+ // Verify the page content
48+ const primaryContent = page . locator ( '#message-status-title' ) ;
49+ await expect ( primaryContent ) . toContainText ( 'Status message' ) ;
14550
14651 // Log out
14752 await page . goto ( '/user/logout/confirm' ) ;
@@ -153,46 +58,47 @@ test.describe('Generic Test Suite - CWL and General access', () => {
15358 await page . fill ( '#edit-pass' , password ) ;
15459 await page . click ( 'input#edit-submit[value="Log in"]' ) ;
15560
156- // CWL page
61+ // Check both cwl and general pages can be accessed
15762 await page . goto ( cwlpageURL ) ;
158-
159- // Verify the page content
160- await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( 'Playwright Test Basic Page - CWL' ) ;
63+ await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
16164 await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
16265
163- // General page
164- await page . goto ( generalpageURL ) ;
16566
166- // Verify the page content
167- await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( 'Playwright Test Basic Page - General' ) ;
67+ await page . goto ( generalpageURL ) ;
68+ await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
16869 await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
16970 } ) ;
17071
17172 test ( 'Create and test General user access' , async ( { page } ) => {
172- await page . goto ( '/admin/people' ) ;
173- const username = 'playwrightGeneral' ;
174- const usernames = await page . locator ( '#views-form-user-admin-people-page-1 .username' ) . allTextContents ( ) ;
175- const exists = usernames . some ( name => name . includes ( username ) ) ;
73+ // Check basic pages are created
74+ await page . goto ( generalpageURL ) ;
75+ await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
76+ await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
77+ await expect ( page . locator ( '.field--name-field-visibility .field__item' ) ) . toContainText ( 'General' ) ;
17678
177- if ( exists ) {
178- console . log ( `User " ${ username } " already exists. Skipping creation.` ) ;
179- } else {
180- await page . goto ( '/admin/people/create ') ;
79+ await page . goto ( cwlpageURL ) ;
80+ await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
81+ await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
82+ await expect ( page . locator ( '.field--name-field-visibility .field__item' ) ) . toContainText ( 'CWL ') ;
18183
182- // Type username
183- await page . fill ( '[data-drupal-selector="edit-name"]' , username ) ;
84+ // Create General user
85+ const username = `testGeneral-${ Date . now ( ) } ` ;
86+ await page . goto ( '/admin/people/create' ) ;
18487
185- // Type password
186- await page . fill ( '[data-drupal-selector="edit-pass-pass1"]' , password ) ;
187- await page . fill ( '[data-drupal-selector="edit-pass-pass2"]' , password ) ;
88+ // Type username
89+ await page . fill ( '[data-drupal-selector="edit-name"]' , username ) ;
18890
189- // Save changes
190- await page . locator ( ' [data-drupal-selector="edit-submit"]' ) . click ( ) ;
91+ // Type password
92+ await page . fill ( '[data-drupal-selector="edit-pass-pass1"]' , password ) ;
93+ await page . fill ( '[data-drupal-selector="edit-pass-pass2"]' , password ) ;
94+
95+ // Save changes
96+ await page . locator ( ' [data-drupal-selector="edit-submit"]' ) . click ( ) ;
97+
98+ // Verify the page content
99+ const primaryContent = page . locator ( '#message-status-title' ) ;
100+ await expect ( primaryContent ) . toContainText ( 'Status message' ) ;
191101
192- // Verify the page content
193- const primaryContent = page . locator ( '#message-status-title' ) ;
194- await expect ( primaryContent ) . toContainText ( 'Status message' ) ;
195- }
196102
197103 // Log out
198104 await page . goto ( '/user/logout/confirm' ) ;
@@ -204,17 +110,13 @@ test.describe('Generic Test Suite - CWL and General access', () => {
204110 await page . fill ( '#edit-pass' , password ) ;
205111 await page . click ( 'input#edit-submit[value="Log in"]' ) ;
206112
207- // CWL page
113+ // Check only general page can be accessed
208114 await page . goto ( cwlpageURL ) ;
209-
210- // Verify the page content
211115 await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( 'Page not found' ) ;
212116
213- // General page
117+
214118 await page . goto ( generalpageURL ) ;
215-
216- // Verify the page content
217- await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( 'Playwright Test Basic Page - General' ) ;
119+ await expect ( page . locator ( '#block-olivero-page-title' ) ) . toContainText ( titleMessage ) ;
218120 await expect ( page . locator ( '#block-olivero-content' ) ) . toContainText ( bodyMessage ) ;
219121 } ) ;
220122
0 commit comments