1- const { chromium } = require ( 'playwright' ) ;
1+ const { expect } = require ( '@playwright/test' ) ;
2+ const { log, args, createPage, closePage, takeScreenshot, waitForServerReady, dismissDevmode } = require ( './test-utils' ) ;
23// When using playwright in lib mode we cannot use expect, thus we use regular asserts
34const assert = require ( 'assert' ) ;
45
5- let headless = false , host = 'localhost' , port = '8080' , mode = false ;
6- process . argv . forEach ( a => {
7- if ( / ^ - - h e a d l e s s / . test ( a ) ) {
8- headless = true ;
9- } else if ( / ^ - - p o r t = / . test ( a ) ) {
10- port = a . split ( '=' ) [ 1 ] ;
11- } else if ( / ^ - - m o d e = / . test ( a ) ) {
12- mode = a . split ( '=' ) [ 1 ] ;
13- }
14- } ) ;
15-
166( async ( ) => {
17- const browser1 = await chromium . launch ( {
18- headless : headless ,
19- chromiumSandbox : true
20- } ) ;
21-
22- const browser2 = await chromium . launch ( {
23- headless : headless ,
24- chromiumSandbox : true
25- } ) ;
26-
27- // TODO: should work with smaller viewport too like in 24.9
28- const context1 = await browser1 . newContext ( {
29- viewport : { width : 1920 , height : 1080 }
30- } ) ;
31- const page1 = await context1 . newPage ( ) ;
32- page1 . on ( 'console' , msg => console . log ( "> PAGE1 CONSOLE:" , ( msg . text ( ) + ' - ' + msg . location ( ) . url ) . replace ( / \s + / g, ' ' ) ) ) ;
33- page1 . on ( 'pageerror' , err => console . log ( "> PAGE1 PAGEERROR:" , ( '' + err ) . replace ( / \s + / g, ' ' ) ) ) ;
34-
35- await page1 . goto ( `http://${ host } :${ port } /` ) ;
36-
37- // TODO: should work with smaller viewport too like in 24.9
38- const context2 = await browser2 . newContext ( {
39- viewport : { width : 1920 , height : 1080 }
40- } ) ;
41- const page2 = await context2 . newPage ( ) ;
42- page2 . on ( 'console' , msg => console . log ( "> PAGE2 CONSOLE:" , ( msg . text ( ) + ' - ' + msg . location ( ) . url ) . replace ( / \s + / g, ' ' ) ) ) ;
43- page2 . on ( 'pageerror' , err => console . log ( "> PAGE2 PAGEERROR:" , ( '' + err ) . replace ( / \s + / g, ' ' ) ) ) ;
44-
45- await page2 . goto ( `http://${ host } :${ port } /` ) ;
46-
47- /*
48- This script tests the collaboration view from Vaadin Start.
49- First, it has two users trying to chat in a channel. Second, it check whether the avatars are properly displayed.
50- Third, it tests two users taking turns on editing one entry in the master-detail view.
51- */
52-
53-
54- //send a message
55- await page1 . getByText ( '#support' ) . click ( ) ;
56- await page1 . getByText ( '#casual' ) . click ( ) ;
57- await page1 . getByText ( '#general' ) . click ( ) ;
58- await page1 . getByLabel ( 'Message' ) . click ( ) ;
59- await page1 . getByLabel ( 'Message' ) . fill ( 'Test from user 1' ) ;
60- await page1 . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
61-
62- //check if user 2 received it and reply
63- await page2 . getByText ( '#general' ) . click ( ) ;
64- await page2 . getByText ( 'Test from user 1' ) ;
65- await page2 . getByLabel ( 'Message' ) . click ( ) ;
66- await page2 . getByLabel ( 'Message' ) . fill ( 'Test from user 2' ) ;
67- await page2 . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
68-
69- //check if user1 received answer
70- await page1 . getByText ( 'Test from user 2' ) ;
71-
72- //Check avatar groups:
73- //There is always one more avatar in the group than there are users (which displays
74- //the number of non-visible 'other' avatars, i.e., the overflow.) It is invisible in our case.
75- let expectedAvatarCount = 2 + 1 ;
76-
77- const avatarCount1 = await page1 . locator ( 'vaadin-avatar-group > vaadin-avatar' ) . count ( ) ;
78- assert ( avatarCount1 === expectedAvatarCount , "Expected two users but found: " + ( avatarCount1 - 1 ) ) ;
79-
80- const avatarCount2 = await page2 . locator ( 'vaadin-avatar-group > vaadin-avatar' ) . count ( ) ;
81- assert ( avatarCount2 === expectedAvatarCount , "Expected two users but found: " + ( avatarCount2 - 1 ) ) ;
82-
83- //edit one entry as user 1
84- await page1 . getByRole ( 'link' , { name : 'Master Detail' } ) . click ( ) ;
85- await page1 . getByText ( 'Gene' , { exact : true } ) . click ( ) ;
86- await page1 . waitForTimeout ( 1000 ) ;
87- await page1 . getByLabel ( 'First Name' , { exact : true } ) . click ( ) ;
88- await page1 . getByLabel ( 'First Name' , { exact : true } ) . fill ( 'Gene James' ) ;
89- await page1 . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
90- //wait for the notification of data updated (the count is only there for the promise to be resolved)
91- await page1 . getByRole ( 'alert' ) . count ( ) ;
92-
93- //check if changes appear for user 2
94- await page2 . getByRole ( 'link' , { name : 'Master Detail' } ) . click ( ) ;
95-
96- await page1 . waitForTimeout ( 1000 ) ;
97- await page2 . waitForTimeout ( 1000 ) ;
98- await page1 . reload ( ) ;
99- await page2 . reload ( ) ;
100-
101- await page2 . getByText ( 'Gene James' , { exact : true } ) . click ( ) ;
102- await page1 . waitForTimeout ( 1000 ) ;
103- await page2 . getByLabel ( 'First Name' , { exact : true } ) . fill ( 'Gene James, 3rd' ) ;
104- await page2 . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
105- //wait for the notification of data updated
106- await page2 . getByRole ( 'alert' ) . count ( ) ;
107-
108- await page1 . waitForTimeout ( 1000 ) ;
109- await page2 . waitForTimeout ( 1000 ) ;
110- await page1 . reload ( ) ;
111- await page2 . reload ( ) ;
112-
113- await page1 . getByText ( 'Gene James, 3rd' , { exact : true } ) . click ( ) ;
114-
115- await context1 . close ( ) ;
116- await browser1 . close ( ) ;
117-
118- await context2 . close ( ) ;
119- await browser2 . close ( ) ;
7+ const arg = args ( ) ;
8+
9+ log ( 'Starting collaboration test with two browser instances' ) ;
10+
11+ // Create two separate pages for collaboration testing
12+ const page1 = await createPage ( arg . headless ) ;
13+ const page2 = await createPage ( arg . headless ) ;
14+
15+ // TODO: should work with smaller viewport too like in 24.9
16+ // The createPage function already sets viewport to 1792x970, which should be sufficient
17+
18+ await waitForServerReady ( page1 , arg . url ) ;
19+ await waitForServerReady ( page2 , arg . url ) ;
20+
21+ // Dismiss dev mode notifications if present
22+ await dismissDevmode ( page1 ) ;
23+ await dismissDevmode ( page2 ) ;
24+ await takeScreenshot ( page1 , __filename , 'page1-loaded' ) ;
25+ await takeScreenshot ( page2 , __filename , 'page2-loaded' ) ;
26+
27+ /*
28+ This script tests the collaboration view from Vaadin Start.
29+ First, it has two users trying to chat in a channel. Second, it check whether the avatars are properly displayed.
30+ Third, it tests two users taking turns on editing one entry in the master-detail view.
31+ */
32+
33+ log ( 'Testing chat functionality between two users' ) ;
34+
35+ //send a message
36+ await page1 . getByText ( '#support' ) . click ( ) ;
37+ await page1 . getByText ( '#casual' ) . click ( ) ;
38+ await page1 . getByText ( '#general' ) . click ( ) ;
39+ await page1 . getByLabel ( 'Message' ) . click ( ) ;
40+ await page1 . getByLabel ( 'Message' ) . fill ( 'Test from user 1' ) ;
41+ await page1 . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
42+ await takeScreenshot ( page1 , __filename , 'user1-sent-message' ) ;
43+
44+ //check if user 2 received it and reply
45+ await page2 . getByText ( '#general' ) . click ( ) ;
46+ await page2 . getByText ( 'Test from user 1' ) ;
47+ await page2 . getByLabel ( 'Message' ) . click ( ) ;
48+ await page2 . getByLabel ( 'Message' ) . fill ( 'Test from user 2' ) ;
49+ await page2 . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
50+ await takeScreenshot ( page2 , __filename , 'user2-sent-reply' ) ;
51+
52+ //check if user1 received answer
53+ await page1 . getByText ( 'Test from user 2' ) ;
54+ await takeScreenshot ( page1 , __filename , 'user1-received-reply' ) ;
55+
56+ log ( 'Testing avatar groups' ) ;
57+
58+ //Check avatar groups:
59+ //There is always one more avatar in the group than there are users (which displays
60+ //the number of non-visible 'other' avatars, i.e., the overflow.) It is invisible in our case.
61+ let expectedAvatarCount = 2 + 1 ;
62+
63+ const avatarCount1 = await page1 . locator ( 'vaadin-avatar-group > vaadin-avatar' ) . count ( ) ;
64+ assert ( avatarCount1 === expectedAvatarCount , "Expected two users but found: " + ( avatarCount1 - 1 ) ) ;
65+
66+ const avatarCount2 = await page2 . locator ( 'vaadin-avatar-group > vaadin-avatar' ) . count ( ) ;
67+ assert ( avatarCount2 === expectedAvatarCount , "Expected two users but found: " + ( avatarCount2 - 1 ) ) ;
68+
69+ log ( 'Avatar counts verified successfully' ) ;
70+
71+ log ( 'Testing master-detail collaboration' ) ;
72+
73+ //edit one entry as user 1
74+ await page1 . getByRole ( 'link' , { name : 'Master Detail' } ) . click ( ) ;
75+ await page1 . getByText ( 'Gene' , { exact : true } ) . click ( ) ;
76+ await page1 . waitForTimeout ( 1000 ) ;
77+ await page1 . getByLabel ( 'First Name' , { exact : true } ) . click ( ) ;
78+ await page1 . getByLabel ( 'First Name' , { exact : true } ) . fill ( 'Gene James' ) ;
79+ await page1 . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
80+ //wait for the notification of data updated (the count is only there for the promise to be resolved)
81+ await page1 . getByRole ( 'alert' ) . count ( ) ;
82+ await takeScreenshot ( page1 , __filename , 'user1-edited-entry' ) ;
83+
84+ //check if changes appear for user 2
85+ await page2 . getByRole ( 'link' , { name : 'Master Detail' } ) . click ( ) ;
86+
87+ await page1 . waitForTimeout ( 1000 ) ;
88+ await page2 . waitForTimeout ( 1000 ) ;
89+ await page1 . reload ( ) ;
90+ await page2 . reload ( ) ;
91+
92+ await page2 . getByText ( 'Gene James' , { exact : true } ) . click ( ) ;
93+ await page1 . waitForTimeout ( 1000 ) ;
94+ await page2 . getByLabel ( 'First Name' , { exact : true } ) . fill ( 'Gene James, 3rd' ) ;
95+ await page2 . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
96+ //wait for the notification of data updated
97+ await page2 . getByRole ( 'alert' ) . count ( ) ;
98+ await takeScreenshot ( page2 , __filename , 'user2-edited-entry' ) ;
99+
100+ await page1 . waitForTimeout ( 1000 ) ;
101+ await page2 . waitForTimeout ( 1000 ) ;
102+ await page1 . reload ( ) ;
103+ await page2 . reload ( ) ;
104+
105+ await page1 . getByText ( 'Gene James, 3rd' , { exact : true } ) . click ( ) ;
106+ await takeScreenshot ( page1 , __filename , 'user1-sees-changes' ) ;
107+
108+ log ( 'Collaboration test completed successfully' ) ;
109+
110+ await closePage ( page1 ) ;
111+ await closePage ( page2 ) ;
120112} ) ( ) ;
0 commit comments