Skip to content

Commit 5a9f34f

Browse files
authored
Merge pull request #12 from seamplex/copilot/add-network-logging-debugging
Add network logging and error visibility to Playwright CAD upload test
2 parents e918980 + 8a3f071 commit 5a9f34f

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

playwright.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ module.exports = defineConfig({
1111
use: {
1212
baseURL: 'http://localhost:8000',
1313
trace: 'on-first-retry',
14+
video: 'retain-on-failure',
15+
screenshot: 'only-on-failure',
16+
// Add HAR recording to capture all network traffic
17+
recordHar: {
18+
path: 'test-results/network.har',
19+
content: 'attach' // Include response bodies
20+
},
1421
},
1522

1623
projects: [

tests/e2e/create_case.spec.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,71 @@ const { test, expect } = require('@playwright/test');
33
const path = require('path');
44

55
test('create new case from sample.step', async ({ page }) => {
6+
// Add network request/response logging
7+
page.on('request', request => {
8+
console.log('>>', request.method(), request.url());
9+
});
10+
11+
page.on('response', async response => {
12+
const url = response.url();
13+
console.log('<<', response.status(), url);
14+
15+
// Log responses from PHP scripts involved in CAD processing
16+
if (url.includes('import_cad.php') || url.includes('process.php')) {
17+
try {
18+
const body = await response.text();
19+
console.log('Response body:', body);
20+
} catch (e) {
21+
console.log('Could not read response body:', e.message);
22+
}
23+
}
24+
});
25+
26+
// Add browser console logging
27+
page.on('console', msg => {
28+
console.log('BROWSER:', msg.type(), msg.text());
29+
});
30+
631
// 1. Go to /new
732
await page.goto('/new/');
833

934
// 2. In that view, there's a file upload input box. Put the file html/new/sample.step in the upload box
1035
// Note: path is relative to the test file.
1136
// tests/e2e/create_case.spec.js -> ../../html/new/sample.step
1237
const sampleFile = path.join(__dirname, '../../html/new/sample.step');
38+
39+
// Wait for the import response
40+
const importResponsePromise = page.waitForResponse(response =>
41+
response.url().includes('import_cad.php') && response.status() === 200,
42+
{ timeout: 30000 }
43+
);
44+
45+
await page.setInputFiles('#cad', sampleFile);
46+
47+
await importResponsePromise;
48+
49+
// Wait for the process response
50+
const processResponse = await page.waitForResponse(response =>
51+
response.url().includes('process.php') && response.status() === 200,
52+
{ timeout: 30000 }
53+
);
54+
55+
// Wait for the file to be processed and preview to be shown
56+
try {
57+
await expect(page.locator('#cad_preview')).toBeVisible({ timeout: 30000 });
58+
} catch (error) {
59+
// Check if there's an error message displayed
60+
const errorDiv = page.locator('#cad_error');
61+
if (await errorDiv.isVisible()) {
62+
const errorText = await errorDiv.textContent();
63+
console.log('CAD Error displayed:', errorText);
64+
}
65+
66+
// Take a screenshot for debugging
67+
await page.screenshot({ path: 'test-results/upload-failure.png', fullPage: true });
68+
69+
throw error;
70+
}
1371
await page.setInputFiles('#cad', sampleFile);
1472

1573
// Wait for the file to be processed and preview to be shown
@@ -24,6 +82,7 @@ test('create new case from sample.step', async ({ page }) => {
2482
// 5. Select "FeenoX" in the combo box for solver
2583
await page.selectOption('#solver', 'feenox');
2684

85+
// 6. Select "Gmsh" in the combo box for mesher
2786
// 6. Select "Gmsh" in thecombo box for mesher
2887
await page.selectOption('#mesher', 'gmsh');
2988

0 commit comments

Comments
 (0)