|
1 | | -const { chromium } = require('playwright'); |
2 | | - |
3 | | -let headless = false, host = 'localhost', port = '8080', hub = false; |
4 | | -process.argv.forEach(a => { |
5 | | - if (/^--headless/.test(a)) { |
6 | | - headless = true; |
7 | | - } else if (/^--ip=/.test(a)) { |
8 | | - ip = a.split('=')[1]; |
9 | | - } else if (/^--port=/.test(a)) { |
10 | | - port = a.split('=')[1]; |
11 | | - } |
12 | | -}); |
| 1 | +const { log, args, createPage, closePage, takeScreenshot, waitForServerReady, dismissDevmode } = require('./test-utils'); |
13 | 2 |
|
14 | 3 | (async () => { |
15 | | - const browser = await chromium.launch({ |
16 | | - headless: headless, |
17 | | - chromiumSandbox: false |
18 | | - }); |
19 | | - const context = await browser.newContext({ |
20 | | - viewport: { width: 1024, height: 800 } |
21 | | - }); |
22 | | - |
23 | | - const page = await context.newPage(); |
24 | | - page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' '))); |
25 | | - page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' '))); |
26 | | - |
27 | | - await page.goto(`http://${host}:${port}/`); |
28 | | - |
29 | | - await page.waitForURL('http://localhost:8080/login'); |
30 | | - await page.locator('input[name="username"]').click(); |
31 | | - await page.locator('input[name="username"]').fill('admin'); |
32 | | - await page.locator('input[name="password"]').click(); |
33 | | - await page.locator('input[name="password"]').fill('admin'); |
34 | | - await page.locator('vaadin-button[role="button"]:has-text("Log in")').click(); |
35 | | - await page.waitForLoadState(); |
36 | | - |
37 | | - await page.locator('text=Hello World').nth(0).click(); |
38 | | - await page.locator('text=Hello').nth(0).click(); |
39 | | - await page.locator('input[type="text"]').fill('Greet'); |
40 | | - await page.locator('text=Say hello').click(); |
41 | | - await page.locator('text=Hello Greet').waitFor({ state: 'visible' }); |
42 | | - |
43 | | - // TODO: investigate why this is needed when notification is visible click does not work in master-detail |
44 | | - await page.goto(`http://${host}:${port}/master-detail-view`); |
45 | | - await page.locator('text=Master-Detail').nth(0).click(); |
46 | | - console.log('--- Click on eula.lane'); |
47 | | - await page.locator('text=eula.lane').click(); |
48 | | - await page.locator('input[type="text"]').nth(0).fill('FOO'); |
49 | | - |
50 | | - // TODO: reduce screen height above and uncomment this when fixed |
51 | | - // https://github.com/vaadin/start/issues/3521 |
52 | | - // await page.locator('text=Save').scrollIntoViewIfNeeded(); |
53 | | - await page.locator('text=Save').click(); |
54 | | - await page.locator('text=/Data updated/').waitFor({ state: 'visible' }); |
55 | | - await page.waitForTimeout(5000); |
56 | | - |
57 | | - await page.locator('text=/Emma/').click(); |
58 | | - await page.locator('text=/Sign out/').click(); |
59 | | - await page.locator('h2:has-text("Log in")'); |
60 | | - |
61 | | - // --------------------- |
62 | | - await context.close(); |
63 | | - await browser.close(); |
| 4 | + const arg = args(); |
| 5 | + |
| 6 | + const page = await createPage(arg.headless); |
| 7 | + |
| 8 | + await waitForServerReady(page, arg.url); |
| 9 | + await takeScreenshot(page, __filename, 'page-loaded'); |
| 10 | + |
| 11 | + log('Testing authentication login flow'); |
| 12 | + await page.waitForURL(`${arg.url.replace(':8080', ':8080')}/login`); |
| 13 | + await page.locator('input[name="username"]').click(); |
| 14 | + await page.locator('input[name="username"]').fill('admin'); |
| 15 | + await page.locator('input[name="password"]').click(); |
| 16 | + await page.locator('input[name="password"]').fill('admin'); |
| 17 | + await page.locator('vaadin-button[role="button"]:has-text("Log in")').click(); |
| 18 | + await page.waitForLoadState(); |
| 19 | + await takeScreenshot(page, __filename, 'logged-in'); |
| 20 | + |
| 21 | + log('Testing Hello World functionality after login'); |
| 22 | + await page.locator('text=Hello World').nth(0).click(); |
| 23 | + await page.locator('text=Hello').nth(0).click(); |
| 24 | + await page.locator('input[type="text"]').fill('Greet'); |
| 25 | + await page.locator('text=Say hello').click(); |
| 26 | + await page.locator('text=Hello Greet').waitFor({ state: 'visible' }); |
| 27 | + await takeScreenshot(page, __filename, 'hello-world-tested'); |
| 28 | + |
| 29 | + log('Testing Master-Detail functionality'); |
| 30 | + // TODO: investigate why this is needed when notification is visible click does not work in master-detail |
| 31 | + await page.goto(`${arg.url}/master-detail-view`); |
| 32 | + await page.locator('text=Master-Detail').nth(0).click(); |
| 33 | + log('--- Click on eula.lane'); |
| 34 | + await page.locator('text=eula.lane').click(); |
| 35 | + await page.locator('input[type="text"]').nth(0).fill('FOO'); |
| 36 | + await takeScreenshot(page, __filename, 'master-detail-editing'); |
| 37 | + |
| 38 | + // TODO: reduce screen height above and uncomment this when fixed |
| 39 | + // https://github.com/vaadin/start/issues/3521 |
| 40 | + // await page.locator('text=Save').scrollIntoViewIfNeeded(); |
| 41 | + await page.locator('text=Save').click(); |
| 42 | + await page.locator('text=/Data updated/').waitFor({ state: 'visible' }); |
| 43 | + await page.waitForTimeout(5000); |
| 44 | + await takeScreenshot(page, __filename, 'data-updated'); |
| 45 | + |
| 46 | + log('Testing logout functionality'); |
| 47 | + await page.locator('text=/Emma/').click(); |
| 48 | + await page.locator('text=/Sign out/').click(); |
| 49 | + await page.locator('h2:has-text("Log in")'); |
| 50 | + await takeScreenshot(page, __filename, 'logged-out'); |
| 51 | + |
| 52 | + log('Authentication flow tested successfully'); |
| 53 | + await closePage(page); |
64 | 54 | })(); |
0 commit comments