Skip to content

Commit cb48d3b

Browse files
committed
migrate scripts/pit/its/mpr-demo.js to use test-utils
1 parent d2e5355 commit cb48d3b

File tree

1 file changed

+57
-49
lines changed

1 file changed

+57
-49
lines changed

scripts/pit/its/mpr-demo.js

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,73 @@
11
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-
});
2+
const { log, args, closePage, takeScreenshot, waitForServerReady, dismissDevmode } = require('./test-utils');
133

144
(async () => {
15-
const browser = await chromium.launch({
16-
headless: headless
17-
});
18-
const context = await browser.newContext({
19-
extraHTTPHeaders: {
20-
'X-AppUpdate': 'FOO'
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, ' ')));
5+
const arg = args();
6+
7+
log('Creating browser with special headers for MPR demo');
8+
const browser = await chromium.launch({
9+
headless: arg.headless
10+
});
11+
const context = await browser.newContext({
12+
extraHTTPHeaders: {
13+
'X-AppUpdate': 'FOO'
14+
}
15+
});
16+
const page = await context.newPage();
17+
page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' ')));
18+
page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' ')));
2619

27-
await page.goto(`http://${host}:${port}`);
28-
await page.evaluate(() => {
29-
window.localStorage.setItem("vaadin.live-reload.dismissedNotifications","liveReloadUnavailable,preserveOnRefreshWarning")
30-
window.location.reload();
31-
});
20+
await waitForServerReady(page, arg.url);
21+
await takeScreenshot(page, __filename, 'page-loaded');
3222

33-
await page.locator('vaadin-notification-card[role="alert"]:has-text("Hello") div').nth(1).click();
23+
await page.evaluate(() => {
24+
window.localStorage.setItem("vaadin.live-reload.dismissedNotifications","liveReloadUnavailable,preserveOnRefreshWarning")
25+
window.location.reload();
26+
});
3427

35-
await page.getByRole('link', { name: 'Spreadsheet' }).click();
36-
await page.waitForURL(`http://${host}:${port}/spreadsheet`);
28+
await page.locator('vaadin-notification-card[role="alert"]:has-text("Hello") div').nth(1).click();
29+
await takeScreenshot(page, __filename, 'notification-dismissed');
3730

38-
await page.getByText('90', { exact: true }).click();
39-
await page.locator('div:nth-child(59)').dblclick();
31+
log('Testing Spreadsheet view');
32+
await page.getByRole('link', { name: 'Spreadsheet' }).click();
33+
await page.waitForURL(`${arg.url}/spreadsheet`);
34+
await takeScreenshot(page, __filename, 'spreadsheet-loaded');
4035

41-
await page.locator('#cellinput').click();
42-
await page.locator('#cellinput').fill('=B4*3');
43-
await page.locator('#cellinput').press('Enter');
44-
await page.getByText('270').click();
36+
await page.getByText('90', { exact: true }).click();
37+
await page.locator('div:nth-child(59)').dblclick();
4538

46-
await page.getByRole('link', { name: 'Tree' }).click();
47-
await page.waitForURL(`http://${host}:${port}/tree`);
39+
await page.locator('#cellinput').click();
40+
await page.locator('#cellinput').fill('=B4*3');
41+
await page.locator('#cellinput').press('Enter');
42+
await page.getByText('270').click();
43+
await takeScreenshot(page, __filename, 'spreadsheet-formula-tested');
4844

45+
log('Testing Tree view');
46+
await page.getByRole('link', { name: 'Tree' }).click();
47+
await page.waitForURL(`${arg.url}/tree`);
48+
await takeScreenshot(page, __filename, 'tree-loaded');
4949

50-
await page.locator('span.v-tree8-expander').nth(0).click()
51-
await page.locator('span.v-tree8-expander').nth(1).click()
50+
await page.locator('span.v-tree8-expander').nth(0).click()
51+
await page.locator('span.v-tree8-expander').nth(1).click()
52+
await takeScreenshot(page, __filename, 'tree-expanded');
5253

53-
await page.getByRole('link', { name: 'Video' }).click();
54-
await page.waitForURL(`http://${host}:${port}/video`);
55-
await page.getByRole('link', { name: 'Legacy' }).click();
54+
log('Testing Video view');
55+
await page.getByRole('link', { name: 'Video' }).click();
56+
await page.waitForURL(`${arg.url}/video`);
57+
await takeScreenshot(page, __filename, 'video-loaded');
5658

57-
await page.waitForURL(`http://${host}:${port}/legacy`);
58-
await page.getByText('Here we are!').click();
59+
log('Testing Legacy view');
60+
await page.getByRole('link', { name: 'Legacy' }).click();
61+
await page.waitForURL(`${arg.url}/legacy`);
62+
await page.getByText('Here we are!').click();
63+
await takeScreenshot(page, __filename, 'legacy-tested');
5964

60-
await page.locator('vaadin-vertical-layout:has-text("SpreadsheetTreeVideoLegacy") path').click();
61-
await page.waitForURL(`http://${host}:${port}`);
65+
log('Testing navigation back to home');
66+
await page.locator('vaadin-vertical-layout:has-text("SpreadsheetTreeVideoLegacy") path').click();
67+
await page.waitForURL(`${arg.url}`);
68+
await takeScreenshot(page, __filename, 'back-to-home');
6269

63-
await context.close();
64-
await browser.close();
70+
log('MPR demo tested successfully');
71+
await context.close();
72+
await browser.close();
6573
})();

0 commit comments

Comments
 (0)