-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_connection_wizard_ui.js
More file actions
459 lines (394 loc) · 19.1 KB
/
test_connection_wizard_ui.js
File metadata and controls
459 lines (394 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
const { chromium } = require('playwright');
const fs = require('fs');
const path = require('path');
async function testConnectionWizardUI() {
console.log('🚀 Starting Connection Wizard UI Test...\n');
const browser = await chromium.launch({
headless: false, // Show browser for debugging
slowMo: 1000 // Slow down for visibility
});
const context = await browser.newContext();
const page = await context.newPage();
// Enable console logging
page.on('console', msg => {
console.log(`[BROWSER CONSOLE ${msg.type().toUpperCase()}]:`, msg.text());
});
// Enable error logging
page.on('pageerror', error => {
console.error(`[PAGE ERROR]:`, error);
});
try {
console.log('📋 Test Report\n' + '='.repeat(50));
// Step 1: Navigate to the BOM processing page
console.log('\n1️⃣ STEP 1: Navigate to BOM processing page');
await page.goto('http://localhost:3000');
await page.waitForLoadState('networkidle');
// Take initial screenshot
await page.screenshot({ path: 'step1_homepage.png', fullPage: true });
console.log(' ✅ Successfully navigated to http://localhost:3000');
console.log(' 📸 Screenshot saved: step1_homepage.png');
// Check page title
const title = await page.title();
console.log(` 📄 Page title: "${title}"`);
// Step 2: Look for file upload functionality
console.log('\n2️⃣ STEP 2: Locate file upload functionality');
// Wait for the page to fully load and look for upload elements
await page.waitForTimeout(2000);
// Look for common file upload patterns
const uploadSelectors = [
'input[type="file"]',
'[data-testid="file-upload"]',
'.file-upload',
'.dropzone',
'[accept*=".csv"]',
'button:has-text("Upload")',
'button:has-text("Choose File")',
'div:has-text("Drop files")',
'div:has-text("upload")'
];
let uploadElement = null;
let uploadSelector = null;
for (const selector of uploadSelectors) {
try {
uploadElement = await page.locator(selector).first();
if (await uploadElement.count() > 0) {
uploadSelector = selector;
console.log(` ✅ Found upload element: ${selector}`);
break;
}
} catch (e) {
// Continue searching
}
}
if (!uploadElement || await uploadElement.count() === 0) {
console.log(' ❌ No file upload element found. Searching for navigation...');
// Look for navigation to BOM processing page
const navSelectors = [
'a:has-text("BOM")',
'button:has-text("BOM")',
'a[href*="bom"]',
'nav a',
'.nav-link'
];
for (const selector of navSelectors) {
try {
const navElement = await page.locator(selector).first();
if (await navElement.count() > 0) {
console.log(` 📍 Found navigation element: ${selector}`);
await navElement.click();
await page.waitForTimeout(2000);
await page.screenshot({ path: 'step2_after_navigation.png', fullPage: true });
break;
}
} catch (e) {
// Continue searching
}
}
}
// Re-check for upload elements after potential navigation
for (const selector of uploadSelectors) {
try {
uploadElement = await page.locator(selector).first();
if (await uploadElement.count() > 0) {
uploadSelector = selector;
console.log(` ✅ Found upload element after navigation: ${selector}`);
break;
}
} catch (e) {
// Continue searching
}
}
await page.screenshot({ path: 'step2_upload_search.png', fullPage: true });
console.log(' 📸 Screenshot saved: step2_upload_search.png');
// Step 3: Upload a sample BOM file
console.log('\n3️⃣ STEP 3: Upload sample BOM file');
const sampleBomPath = path.resolve('/Users/aswnthraja/PCB_Agent.v2 copy/backend/test_data/simple_bom.csv');
if (uploadElement && await uploadElement.count() > 0) {
try {
if (uploadSelector === 'input[type="file"]') {
// Direct file input
await uploadElement.setInputFiles(sampleBomPath);
console.log(' ✅ File uploaded via file input');
} else {
// Look for file input within or near the upload element
const fileInput = await page.locator('input[type="file"]').first();
if (await fileInput.count() > 0) {
await fileInput.setInputFiles(sampleBomPath);
console.log(' ✅ File uploaded via nested file input');
} else {
console.log(' ⚠️ Upload element found but no file input detected');
}
}
await page.waitForTimeout(3000); // Wait for file processing
await page.screenshot({ path: 'step3_file_uploaded.png', fullPage: true });
console.log(' 📸 Screenshot saved: step3_file_uploaded.png');
} catch (error) {
console.log(` ❌ Error uploading file: ${error.message}`);
}
} else {
console.log(' ❌ No upload element found - cannot upload file');
await page.screenshot({ path: 'step3_no_upload.png', fullPage: true });
}
// Step 4: Find and click "Switch Mode" button
console.log('\n4️⃣ STEP 4: Look for "Switch Mode" button');
const switchModeSelectors = [
'button:has-text("Switch Mode")',
'button:has-text("Mode")',
'button:has-text("Wizard")',
'button:has-text("Connection")',
'[data-testid="switch-mode"]',
'.mode-switch',
'.switch-mode',
'button[title*="mode"]',
'button[aria-label*="mode"]'
];
let switchModeButton = null;
let switchModeSelector = null;
for (const selector of switchModeSelectors) {
try {
switchModeButton = await page.locator(selector).first();
if (await switchModeButton.count() > 0 && await switchModeButton.isVisible()) {
switchModeSelector = selector;
console.log(` ✅ Found Switch Mode button: ${selector}`);
break;
}
} catch (e) {
// Continue searching
}
}
if (switchModeButton && await switchModeButton.count() > 0) {
try {
await switchModeButton.click();
console.log(' ✅ Clicked Switch Mode button');
await page.waitForTimeout(2000);
await page.screenshot({ path: 'step4_switch_mode_clicked.png', fullPage: true });
console.log(' 📸 Screenshot saved: step4_switch_mode_clicked.png');
} catch (error) {
console.log(` ❌ Error clicking Switch Mode button: ${error.message}`);
}
} else {
console.log(' ❌ Switch Mode button not found');
await page.screenshot({ path: 'step4_no_switch_mode.png', fullPage: true });
}
// Step 5: Select "Connection Wizard" mode
console.log('\n5️⃣ STEP 5: Select "Connection Wizard" mode');
const wizardModeSelectors = [
'option:has-text("Connection Wizard")',
'option:has-text("Wizard")',
'button:has-text("Connection Wizard")',
'button:has-text("Wizard")',
'[value="wizard"]',
'[value="connection-wizard"]',
'input[type="radio"][value*="wizard"]',
'.mode-option:has-text("Wizard")',
'select option[value*="wizard"]'
];
let wizardModeElement = null;
let wizardModeSelector = null;
for (const selector of wizardModeSelectors) {
try {
wizardModeElement = await page.locator(selector).first();
if (await wizardModeElement.count() > 0 && await wizardModeElement.isVisible()) {
wizardModeSelector = selector;
console.log(` ✅ Found Connection Wizard option: ${selector}`);
break;
}
} catch (e) {
// Continue searching
}
}
if (wizardModeElement && await wizardModeElement.count() > 0) {
try {
await wizardModeElement.click();
console.log(' ✅ Selected Connection Wizard mode');
await page.waitForTimeout(2000);
await page.screenshot({ path: 'step5_wizard_selected.png', fullPage: true });
console.log(' 📸 Screenshot saved: step5_wizard_selected.png');
} catch (error) {
console.log(` ❌ Error selecting Connection Wizard mode: ${error.message}`);
}
} else {
console.log(' ❌ Connection Wizard mode option not found');
// Look for any dropdown or select elements
const dropdowns = await page.locator('select, .dropdown, .select').all();
if (dropdowns.length > 0) {
console.log(` 📋 Found ${dropdowns.length} dropdown/select elements - investigating...`);
for (let i = 0; i < dropdowns.length; i++) {
try {
const text = await dropdowns[i].textContent();
console.log(` 📋 Dropdown ${i + 1}: "${text?.substring(0, 100)}..."`);
} catch (e) {
console.log(` 📋 Dropdown ${i + 1}: Could not get text`);
}
}
}
await page.screenshot({ path: 'step5_no_wizard_option.png', fullPage: true });
}
// Step 6: Verify mode selection (look for visual indicators)
console.log('\n6️⃣ STEP 6: Verify mode selection with visual indicators');
// Look for visual indicators that wizard mode is selected
const indicators = [
'.active:has-text("Wizard")',
'.selected:has-text("Wizard")',
'.checked:has-text("Wizard")',
'input[checked][value*="wizard"]',
'.mode-indicator',
'.current-mode',
'[aria-selected="true"]'
];
let foundIndicator = false;
for (const selector of indicators) {
try {
const indicator = await page.locator(selector).first();
if (await indicator.count() > 0 && await indicator.isVisible()) {
const text = await indicator.textContent();
console.log(` ✅ Found visual indicator: ${selector} - "${text}"`);
foundIndicator = true;
}
} catch (e) {
// Continue checking
}
}
if (!foundIndicator) {
console.log(' ⚠️ No clear visual indicators found for mode selection');
}
await page.screenshot({ path: 'step6_verify_selection.png', fullPage: true });
console.log(' 📸 Screenshot saved: step6_verify_selection.png');
// Step 7: Find and click "Start S-Expression Generation" button
console.log('\n7️⃣ STEP 7: Look for "Start S-Expression Generation" button');
const startButtonSelectors = [
'button:has-text("Start S-Expression Generation")',
'button:has-text("Start Generation")',
'button:has-text("Generate")',
'button:has-text("Process")',
'button:has-text("Start")',
'button:has-text("Convert")',
'button:has-text("Create Schematic")',
'[data-testid="start-generation"]',
'.start-button',
'.generate-button',
'input[type="submit"]',
'button[type="submit"]'
];
let startButton = null;
let startButtonSelector = null;
for (const selector of startButtonSelectors) {
try {
startButton = await page.locator(selector).first();
if (await startButton.count() > 0 && await startButton.isVisible()) {
startButtonSelector = selector;
console.log(` ✅ Found Start button: ${selector}`);
break;
}
} catch (e) {
// Continue searching
}
}
if (startButton && await startButton.count() > 0) {
try {
// Check if button is enabled
const isEnabled = await startButton.isEnabled();
console.log(` 📋 Button enabled: ${isEnabled}`);
if (isEnabled) {
await startButton.click();
console.log(' ✅ Clicked Start S-Expression Generation button');
await page.waitForTimeout(3000); // Wait for response
} else {
console.log(' ⚠️ Start button found but disabled');
}
await page.screenshot({ path: 'step7_start_clicked.png', fullPage: true });
console.log(' 📸 Screenshot saved: step7_start_clicked.png');
} catch (error) {
console.log(` ❌ Error clicking Start button: ${error.message}`);
}
} else {
console.log(' ❌ Start S-Expression Generation button not found');
await page.screenshot({ path: 'step7_no_start_button.png', fullPage: true });
}
// Step 8: Monitor what happens - wait for any navigation or wizard to start
console.log('\n8️⃣ STEP 8: Monitor post-click behavior');
await page.waitForTimeout(5000); // Wait for any processing or navigation
const currentUrl = page.url();
console.log(` 📍 Current URL: ${currentUrl}`);
// Check for any loading indicators
const loadingSelectors = [
'.loading',
'.spinner',
'.progress',
'[data-loading="true"]',
'.processing'
];
for (const selector of loadingSelectors) {
try {
const loading = await page.locator(selector).first();
if (await loading.count() > 0 && await loading.isVisible()) {
console.log(` 🔄 Found loading indicator: ${selector}`);
}
} catch (e) {
// Continue checking
}
}
// Check for wizard interface elements
const wizardSelectors = [
'.wizard',
'.connection-wizard',
'.step-indicator',
'.wizard-step',
'.wizard-container',
'[data-wizard]'
];
let wizardStarted = false;
for (const selector of wizardSelectors) {
try {
const wizard = await page.locator(selector).first();
if (await wizard.count() > 0 && await wizard.isVisible()) {
console.log(` 🧙♂️ Wizard interface detected: ${selector}`);
wizardStarted = true;
}
} catch (e) {
// Continue checking
}
}
if (!wizardStarted) {
console.log(' ⚠️ No wizard interface detected after clicking Start');
}
await page.screenshot({ path: 'step8_post_click_state.png', fullPage: true });
console.log(' 📸 Screenshot saved: step8_post_click_state.png');
// Step 9: Check browser console for JavaScript errors
console.log('\n9️⃣ STEP 9: Final console error check');
// Errors are already being logged via page.on('console') and page.on('pageerror')
console.log(' 📋 Console errors (if any) are displayed above with [BROWSER CONSOLE] or [PAGE ERROR] prefix');
// Step 10: Take final screenshot
console.log('\n🔟 STEP 10: Final documentation');
await page.screenshot({ path: 'step10_final_state.png', fullPage: true });
console.log(' 📸 Final screenshot saved: step10_final_state.png');
// Summary
console.log('\n📊 TEST SUMMARY');
console.log('='.repeat(50));
console.log(`✅ Successfully navigated to frontend`);
console.log(`${uploadElement && await uploadElement.count() > 0 ? '✅' : '❌'} File upload functionality found`);
console.log(`${switchModeButton && await switchModeButton.count() > 0 ? '✅' : '❌'} Switch Mode button found`);
console.log(`${wizardModeElement && await wizardModeElement.count() > 0 ? '✅' : '❌'} Connection Wizard option found`);
console.log(`${startButton && await startButton.count() > 0 ? '✅' : '❌'} Start Generation button found`);
console.log(`${wizardStarted ? '✅' : '❌'} Wizard interface started after click`);
console.log('\n📁 Generated Files:');
console.log(' • step1_homepage.png - Initial homepage');
console.log(' • step2_upload_search.png - Upload element search');
console.log(' • step3_file_uploaded.png - After file upload');
console.log(' • step4_switch_mode_clicked.png - After clicking switch mode');
console.log(' • step5_wizard_selected.png - After selecting wizard mode');
console.log(' • step6_verify_selection.png - Visual verification');
console.log(' • step7_start_clicked.png - After clicking start');
console.log(' • step8_post_click_state.png - Post-click state');
console.log(' • step10_final_state.png - Final state');
} catch (error) {
console.error('❌ Test failed with error:', error);
await page.screenshot({ path: 'error_state.png', fullPage: true });
console.log('📸 Error screenshot saved: error_state.png');
} finally {
await browser.close();
console.log('\n🏁 Test completed!');
}
}
// Run the test
testConnectionWizardUI().catch(console.error);