|
1 |
| -const { chromium } = require('playwright'); |
2 | 1 |
|
3 |
| -let headless = false, host = 'localhost', port = '8080', mode = false; |
4 |
| -process.argv.forEach(a => { |
5 |
| - if (/^--headless/.test(a)) { |
6 |
| - headless = true; |
7 |
| - } else if (/^--port=/.test(a)) { |
8 |
| - port = a.split('=')[1]; |
9 |
| - } else if (/^--mode=/.test(a)) { |
10 |
| - mode = a.split('=')[1]; |
11 |
| - } |
12 |
| -}); |
| 2 | +const {log, warn, args, createPage, closePage, takeScreenshot, waitForServerReady} = require('./test-utils'); |
13 | 3 |
|
14 | 4 | (async () => {
|
15 |
| - const browser = await chromium.launch({ |
16 |
| - headless: headless, |
17 |
| - chromiumSandbox: false |
18 |
| - }); |
19 |
| - const sleep = ms => new Promise(r => setTimeout(r, ms)); |
20 |
| - |
21 |
| - const context = await browser.newContext(); |
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}/`); |
| 5 | + const arg = args(); |
| 6 | + const page = await createPage(arg.headless, arg.ignoreHTTPSErrors); |
| 7 | + await waitForServerReady(page, arg.url); |
28 | 8 |
|
29 | 9 | await page.waitForSelector('#outlet > * > *:not(style):not(script)');
|
30 |
| - const txt = await page.locator('#outlet').first().innerHTML(); |
31 |
| - console.log('\n====== PAGE CONTENT ======\n', txt, '\n====== END ======\n'); |
| 10 | + await takeScreenshot(page, __filename, 'view-loaded'); |
| 11 | + try { |
| 12 | + const txt = await page.locator('#outlet').first().innerHTML(); |
| 13 | + log("====== PAGE CONTENT ======"); |
| 14 | + out(txt); |
| 15 | + log("====== END ======"); |
| 16 | + } catch (error) { |
| 17 | + const txt = await page.locator('html').innerHTML(); |
| 18 | + warn(`> PAGEERROR: ${txt}`); |
| 19 | + throw error; |
| 20 | + } |
32 | 21 |
|
33 |
| - await context.close(); |
34 |
| - await browser.close(); |
| 22 | + await closePage(page); |
35 | 23 | })();
|
0 commit comments