Skip to content

Commit 0fa0c22

Browse files
committed
migrate scripts/pit/its/react-starter.js to use test-utils
1 parent 973a763 commit 0fa0c22

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

scripts/pit/its/react-starter.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
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');
132

143
(async () => {
15-
const browser = await chromium.launch({
16-
headless: headless,
17-
chromiumSandbox: false
18-
});
19-
const context = await browser.newContext();
4+
const arg = args();
5+
6+
const page = await createPage(arg.headless);
207

21-
const page = await context.newPage();
22-
page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' ')));
23-
page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' ')));
8+
await waitForServerReady(page, arg.url);
249

25-
await page.goto(`http://${host}:${port}/`);
10+
// Dismiss dev mode notification if present
11+
await dismissDevmode(page);
12+
await takeScreenshot(page, __filename, 'page-loaded');
2613

27-
await page.locator('text=Hello').nth(0).click();
28-
await page.locator('input[type="text"]').fill('Greet');
29-
await page.locator('text=Say hello').click();
30-
await page.locator('text=Hello Greet');
14+
log('Testing Hello functionality');
15+
await page.locator('text=Hello').nth(0).click();
16+
await page.locator('input[type="text"]').fill('Greet');
17+
await page.locator('text=Say hello').click();
18+
await page.locator('text=Hello Greet');
19+
await takeScreenshot(page, __filename, 'hello-tested');
3120

32-
await page.locator('text=About').nth(0).click();
33-
await page.locator('text=/This place/');
21+
log('Testing About page');
22+
await page.locator('text=About').nth(0).click();
23+
await page.locator('text=/This place/');
24+
await takeScreenshot(page, __filename, 'about-page-tested');
3425

35-
// ---------------------
36-
await context.close();
37-
await browser.close();
26+
log('React starter tested successfully');
27+
await closePage(page);
3828
})();

0 commit comments

Comments
 (0)