Skip to content

Commit b39076a

Browse files
committed
migrate scripts/pit/its/start.js to use test-utils
1 parent 986bc0c commit b39076a

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

scripts/pit/its/start.js

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
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-
20-
// TODO: should work with smaller viewport too like in 24.9
21-
const context = await browser.newContext({
22-
viewport: { width: 1920, height: 1080 }
23-
});
4+
const arg = args();
5+
6+
const page = await createPage(arg.headless);
7+
// TODO: should work with smaller viewport too like in 24.9
8+
page.setViewportSize({ width: 1920, height: 1080 });
249

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, ' ')));
10+
await waitForServerReady(page, arg.url);
2811

29-
await page.goto(`http://${host}:${port}/`);
12+
// Dismiss dev mode notification if present
13+
await dismissDevmode(page);
14+
await takeScreenshot(page, __filename, 'page-loaded');
3015

31-
await page.locator('text=Hello').nth(0).click();
32-
await page.locator('input[type="text"]').fill('Greet');
33-
await page.locator('text=Say hello').click();
34-
await page.locator('text=Hello Greet');
16+
log('Testing Hello functionality');
17+
await page.locator('text=Hello').nth(0).click();
18+
await page.locator('input[type="text"]').fill('Greet');
19+
await page.locator('text=Say hello').click();
20+
await page.locator('text=Hello Greet');
21+
await takeScreenshot(page, __filename, 'hello-tested');
3522

36-
await page.locator('text=Master-Detail').nth(0).click();
37-
await page.locator('text=eula.lane').click();
38-
await page.locator('input[type="text"]').nth(0).fill('FOO');
39-
await page.locator('text=Save').click();
40-
await page.locator('text=/stored/');
23+
log('Testing Master-Detail functionality');
24+
await page.locator('text=Master-Detail').nth(0).click();
25+
await page.locator('text=eula.lane').click();
26+
await page.locator('input[type="text"]').nth(0).fill('FOO');
27+
await page.locator('text=Save').click();
28+
await page.locator('text=/stored/');
29+
await takeScreenshot(page, __filename, 'master-detail-tested');
4130

42-
// ---------------------
43-
await context.close();
44-
await browser.close();
31+
log('Start application tested successfully');
32+
await closePage(page);
4533
})();

scripts/pit/its/test-utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ async function createPage(headless, ignoreHTTPSErrors) {
133133
return page;
134134
}
135135
async function closePage(page) {
136+
await takeScreenshot(page, getCallingTestFile(), 'ss', '_after');
136137
await page.goto('about:blank');
137138
await page.context().close();
138139
await page.browser.close();
@@ -152,6 +153,23 @@ async function takeScreenshot(page, name, descr, prefix) {
152153
out(` 📸 Screenshot taken: ${file}\n`);
153154
}
154155

156+
// Helper function to get the calling test file name
157+
function getCallingTestFile() {
158+
const stack = new Error().stack;
159+
const stackLines = stack.split('\n');
160+
161+
// Look for the first line that contains a .js file that's not test-utils.js
162+
for (const line of stackLines) {
163+
if (line.includes('.js') && !line.includes('test-utils.js') && !line.includes('node_modules')) {
164+
const match = line.match(/\/([^\/]+\.js)/);
165+
if (match) {
166+
return match[1].replace('.js', '');
167+
}
168+
}
169+
}
170+
return '';
171+
}
172+
155173
// Wait for the server to be ready and to get a valid response
156174
async function waitForServerReady(page, url, options = {}) {
157175
const {
@@ -168,6 +186,7 @@ async function waitForServerReady(page, url, options = {}) {
168186
if (response && response.status() < 400) {
169187
await page.waitForTimeout(1000);
170188
ok(` ✓ Attempt ${attempt} Server is ready and returned a valid response. ${response.status()}\n`);
189+
await takeScreenshot(page, getCallingTestFile(), 'ss', '_before');
171190
return response;
172191
} else {
173192
out(` ⏲ Attempt ${attempt} Server is not ready yet. ${response.status()}\n`);
@@ -181,6 +200,7 @@ async function waitForServerReady(page, url, options = {}) {
181200
}
182201
await page.waitForTimeout(retryInterval);
183202
}
203+
await takeScreenshot(page, getCallingTestFile(), 'ss', '_before');
184204
throw new Error(`Server did not become ready after ${maxRetries} attempts.\n`);
185205
}
186206

0 commit comments

Comments
 (0)