Skip to content

Commit 7a5154f

Browse files
committed
migrate scripts/pit/its/spreadsheet-demo.js to use test-utils
1 parent 54e3ec6 commit 7a5154f

File tree

1 file changed

+70
-62
lines changed

1 file changed

+70
-62
lines changed
Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,83 @@
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 } = 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 sleep = ms => new Promise(r => setTimeout(r, ms));
5+
const arg = args();
6+
7+
log('Creating browser with special headers for Spreadsheet 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 sleep = ms => new Promise(r => setTimeout(r, ms));
17+
18+
const page = await context.newPage();
19+
page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' ')));
20+
page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' ')));
21+
22+
await waitForServerReady(page, arg.url);
23+
await takeScreenshot(page, __filename, 'page-loaded');
2424

25-
const page = await context.newPage();
26-
page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' ')));
27-
page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' ')));
25+
await page.evaluate(() => {
26+
window.localStorage.setItem("vaadin.live-reload.dismissedNotifications","liveReloadUnavailable,preserveOnRefreshWarning")
27+
window.location.reload();
28+
});
2829

29-
await page.goto(`http://${host}:${port}`);
30-
await page.evaluate(() => {
31-
window.localStorage.setItem("vaadin.live-reload.dismissedNotifications","liveReloadUnavailable,preserveOnRefreshWarning")
32-
window.location.reload();
33-
});
30+
log('Testing Basic functionality');
31+
await page.getByRole('link', { name: 'Basic functionality' }).click();
32+
await page.waitForURL(`${arg.url}/demo/basic`);
33+
await takeScreenshot(page, __filename, 'basic-functionality');
3434

35-
await page.getByRole('link', { name: 'Basic functionality' }).click();
36-
await page.waitForURL(`http://${host}:${port}/demo/basic`);
35+
await page.locator('.col2').first().click();
36+
await sleep(100);
37+
const c = await page.getByText('SIMPLE MONTHLY BUDGET').count();
38+
if (!c) throw new Error('Text not found');
3739

38-
await page.locator('.col2').first().click();
39-
await sleep(100);
40-
const c = await page.getByText('SIMPLE MONTHLY BUDGET').count();
41-
if (!c) throw new Error('Text not found');
40+
log('Testing Collaborative features');
41+
await page.getByRole('link', { name: 'Collaborative features' }).click();
42+
await page.waitForURL(`${arg.url}/demo/collaborative`);
43+
await takeScreenshot(page, __filename, 'collaborative-features');
4244

43-
await page.getByRole('link', { name: 'Collaborative features' }).click();
44-
await page.waitForURL(`http://${host}:${port}/demo/collaborative`);
45-
await page.locator('vaadin-spreadsheet div:has-text("Loan calculator")').nth(2).click();
46-
await page.getByText('5.00%').dblclick();
47-
await page.locator('#cellinput').click();
48-
await page.locator('#cellinput').fill('0.03');
49-
await page.locator('#cellinput').press('Enter');
50-
await page.getByText('$10,315.49');
51-
await sleep(100);
52-
await page.keyboard.press('Enter');
53-
await sleep(100);
54-
await page.locator('#cellinput').click();
55-
await page.locator('#cellinput').fill('20');
56-
await page.locator('#cellinput').press('Enter');
57-
await page.getByText('$13,310.34').click();
58-
await sleep(100);
45+
await page.locator('vaadin-spreadsheet div:has-text("Loan calculator")').nth(2).click();
46+
await page.getByText('5.00%').dblclick();
47+
await page.locator('#cellinput').click();
48+
await page.locator('#cellinput').fill('0.03');
49+
await page.locator('#cellinput').press('Enter');
50+
await page.getByText('$10,315.49');
51+
await sleep(100);
52+
await page.keyboard.press('Enter');
53+
await sleep(100);
54+
await page.locator('#cellinput').click();
55+
await page.locator('#cellinput').fill('20');
56+
await page.locator('#cellinput').press('Enter');
57+
await page.getByText('$13,310.34').click();
58+
await sleep(100);
59+
await takeScreenshot(page, __filename, 'loan-calculator-tested');
5960

60-
await page.getByRole('link', { name: 'Grouping' }).click();
61-
await page.waitForURL(`http://${host}:${port}/demo/grouping`);
62-
await page.getByText('+').nth(3).click();
63-
await page.getByText('December').click();
61+
log('Testing Grouping features');
62+
await page.getByRole('link', { name: 'Grouping' }).click();
63+
await page.waitForURL(`${arg.url}/demo/grouping`);
64+
await page.getByText('+').nth(3).click();
65+
await page.getByText('December').click();
66+
await takeScreenshot(page, __filename, 'grouping-tested');
6467

65-
await page.getByRole('link', { name: 'Report mode' }).click();
66-
await page.waitForURL(`http://${host}:${port}/demo/reportMode`);
67-
await page.getByText('547 Demo Suites #85').click();
68+
log('Testing Report mode');
69+
await page.getByRole('link', { name: 'Report mode' }).click();
70+
await page.waitForURL(`${arg.url}/demo/reportMode`);
71+
await page.getByText('547 Demo Suites #85').click();
72+
await takeScreenshot(page, __filename, 'report-mode-tested');
6873

69-
await page.getByRole('link', { name: 'Simple invoice' }).click();
70-
await page.waitForURL(`http://${host}:${port}/demo/simpleInvoice`);
71-
await page.getByText('547 Demo Suites #85').click();
74+
log('Testing Simple invoice');
75+
await page.getByRole('link', { name: 'Simple invoice' }).click();
76+
await page.waitForURL(`${arg.url}/demo/simpleInvoice`);
77+
await page.getByText('547 Demo Suites #85').click();
78+
await takeScreenshot(page, __filename, 'simple-invoice-tested');
7279

73-
await context.close();
74-
await browser.close();
80+
log('Spreadsheet demo tested successfully');
81+
await context.close();
82+
await browser.close();
7583
})();

0 commit comments

Comments
 (0)