-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqa-testing-script.js
More file actions
486 lines (405 loc) · 16.1 KB
/
qa-testing-script.js
File metadata and controls
486 lines (405 loc) · 16.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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
g QR// TreeBio QA Testing Script - Comprehensive Feature Testing
// Run this in browser console at http://localhost:3000
console.log(`
🔍 TREEBIO QA TESTING SUITE - COMPREHENSIVE ANALYSIS
==================================================
📋 TESTING CHECKLIST:
✅ Page Loading & Initial State
✅ Button Functionality
✅ Link Validation
✅ Modal Operations
✅ Form Validations
✅ Interactive Elements
✅ Real-time Features
✅ Responsive Design
✅ Error Handling
✅ Console Error Detection
Starting automated tests...
`);
class TreeBioQATester {
constructor() {
this.errors = [];
this.warnings = [];
this.passed = [];
this.testResults = {};
}
// Utility functions
logTest(testName, status, details = '') {
const result = { test: testName, status, details, timestamp: new Date().toISOString() };
this.testResults[testName] = result;
if (status === 'PASS') {
this.passed.push(result);
console.log(\`✅ \${testName}: PASSED \${details}\`);
} else if (status === 'FAIL') {
this.errors.push(result);
console.error(\`❌ \${testName}: FAILED \${details}\`);
} else if (status === 'WARN') {
this.warnings.push(result);
console.warn(\`⚠️ \${testName}: WARNING \${details}\`);
}
}
async sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Test 1: Page Loading and Initial State
async testPageLoading() {
console.log('\\n🔄 Testing Page Loading...');
try {
// Check if main elements are loaded
const mainElements = [
'header',
'main',
'footer',
'[data-testid="hero-section"]',
'button'
];
for (const selector of mainElements) {
const element = document.querySelector(selector);
if (element) {
this.logTest(\`Page Element: \${selector}\`, 'PASS', 'Element found');
} else {
this.logTest(\`Page Element: \${selector}\`, 'WARN', 'Element not found - may be conditional');
}
}
// Check for critical buttons
const criticalButtons = [
'Design Your TreeBio',
'Get Started',
'Login',
'Sign Up'
];
criticalButtons.forEach(buttonText => {
const button = Array.from(document.querySelectorAll('button')).find(
btn => btn.textContent.includes(buttonText)
);
if (button) {
this.logTest(\`Critical Button: \${buttonText}\`, 'PASS', 'Button found and visible');
} else {
this.logTest(\`Critical Button: \${buttonText}\`, 'WARN', 'Button not found - may be user state dependent');
}
});
} catch (error) {
this.logTest('Page Loading', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 2: Button Functionality
async testButtonFunctionality() {
console.log('\\n🔄 Testing Button Functionality...');
try {
const buttons = document.querySelectorAll('button:not([disabled])');
this.logTest('Button Count', 'PASS', \`Found \${buttons.length} enabled buttons\`);
let clickableButtons = 0;
let problematicButtons = 0;
buttons.forEach((button, index) => {
try {
// Check if button has text or accessible name
const hasText = button.textContent.trim().length > 0;
const hasAriaLabel = button.getAttribute('aria-label');
const hasTitle = button.getAttribute('title');
if (hasText || hasAriaLabel || hasTitle) {
clickableButtons++;
// Check if button has click handlers
const hasOnClick = button.onclick !== null;
const hasEventListeners = button.getEventListeners ?
Object.keys(button.getEventListeners()).length > 0 : true; // Assume true if method not available
if (hasOnClick || hasEventListeners || button.type === 'submit') {
this.logTest(\`Button \${index + 1}\`, 'PASS',
\`Text: "\${button.textContent.trim().substring(0, 20)}..." - Interactive\`);
} else {
this.logTest(\`Button \${index + 1}\`, 'WARN',
\`Text: "\${button.textContent.trim().substring(0, 20)}..." - No obvious click handler\`);
}
} else {
problematicButtons++;
this.logTest(\`Button \${index + 1}\`, 'FAIL', 'Button has no text or accessible name');
}
} catch (error) {
problematicButtons++;
this.logTest(\`Button \${index + 1}\`, 'FAIL', \`Error testing button: \${error.message}\`);
}
});
this.logTest('Button Accessibility', clickableButtons > 0 ? 'PASS' : 'FAIL',
\`\${clickableButtons} accessible buttons, \${problematicButtons} problematic\`);
} catch (error) {
this.logTest('Button Functionality', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 3: Link Validation
async testLinkValidation() {
console.log('\\n🔄 Testing Link Validation...');
try {
const links = document.querySelectorAll('a');
this.logTest('Link Count', 'PASS', \`Found \${links.length} links\`);
let validLinks = 0;
let problematicLinks = 0;
links.forEach((link, index) => {
const href = link.getAttribute('href');
const text = link.textContent.trim();
if (!href) {
this.logTest(\`Link \${index + 1}\`, 'WARN', \`No href attribute - Text: "\${text.substring(0, 20)}..."\`);
problematicLinks++;
return;
}
// Check for different link types
if (href.startsWith('#')) {
// Anchor link
const target = document.querySelector(href);
if (target) {
this.logTest(\`Anchor Link \${index + 1}\`, 'PASS', \`Links to: \${href}\`);
validLinks++;
} else {
this.logTest(\`Anchor Link \${index + 1}\`, 'FAIL', \`Broken anchor: \${href}\`);
problematicLinks++;
}
} else if (href.startsWith('/')) {
// Internal link
this.logTest(\`Internal Link \${index + 1}\`, 'PASS', \`Path: \${href}\`);
validLinks++;
} else if (href.startsWith('http')) {
// External link
const hasTargetBlank = link.getAttribute('target') === '_blank';
this.logTest(\`External Link \${index + 1}\`, hasTargetBlank ? 'PASS' : 'WARN',
\`URL: \${href.substring(0, 30)}... \${hasTargetBlank ? '(opens in new tab)' : '(same tab)'}\`);
validLinks++;
} else if (href.startsWith('mailto:') || href.startsWith('tel:')) {
// Protocol links
this.logTest(\`Protocol Link \${index + 1}\`, 'PASS', \`Type: \${href.split(':')[0]}\`);
validLinks++;
} else {
this.logTest(\`Link \${index + 1}\`, 'WARN', \`Unusual href: \${href}\`);
problematicLinks++;
}
});
this.logTest('Link Validation Summary', validLinks > 0 ? 'PASS' : 'FAIL',
\`\${validLinks} valid links, \${problematicLinks} issues\`);
} catch (error) {
this.logTest('Link Validation', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 4: Modal Operations
async testModalOperations() {
console.log('\\n🔄 Testing Modal Operations...');
try {
// Look for modal triggers (buttons that might open modals)
const modalTriggers = Array.from(document.querySelectorAll('button')).filter(btn =>
btn.textContent.includes('Design Your TreeBio') ||
btn.textContent.includes('Modal') ||
btn.textContent.includes('Open') ||
btn.getAttribute('data-modal') ||
btn.getAttribute('data-dialog')
);
if (modalTriggers.length === 0) {
this.logTest('Modal Triggers', 'WARN', 'No obvious modal triggers found');
return;
}
this.logTest('Modal Triggers', 'PASS', \`Found \${modalTriggers.length} potential modal triggers\`);
// Check for modal containers
const modalSelectors = [
'[role="dialog"]',
'.modal',
'[data-dialog]',
'[data-modal]',
'.dialog-content'
];
let modalCount = 0;
modalSelectors.forEach(selector => {
const modals = document.querySelectorAll(selector);
modalCount += modals.length;
});
this.logTest('Modal Containers', modalCount > 0 ? 'PASS' : 'WARN',
\`Found \${modalCount} modal containers\`);
} catch (error) {
this.logTest('Modal Operations', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 5: Form Validation
async testFormValidation() {
console.log('\\n🔄 Testing Form Validation...');
try {
const forms = document.querySelectorAll('form');
const inputs = document.querySelectorAll('input, textarea, select');
this.logTest('Form Count', 'PASS', \`Found \${forms.length} forms\`);
this.logTest('Input Count', 'PASS', \`Found \${inputs.length} form inputs\`);
// Check form inputs for validation attributes
let validatedInputs = 0;
let totalInputs = inputs.length;
inputs.forEach((input, index) => {
const hasRequired = input.hasAttribute('required');
const hasPattern = input.hasAttribute('pattern');
const hasType = input.type !== 'text' && input.type !== 'textarea';
const hasValidation = hasRequired || hasPattern || hasType;
if (hasValidation) {
validatedInputs++;
this.logTest(\`Input \${index + 1} Validation\`, 'PASS',
\`Type: \${input.type}, Required: \${hasRequired}, Pattern: \${hasPattern}\`);
} else if (input.type === 'submit' || input.type === 'button') {
// Skip validation check for buttons
} else {
this.logTest(\`Input \${index + 1} Validation\`, 'WARN',
\`No validation attributes - Type: \${input.type}\`);
}
});
if (totalInputs > 0) {
this.logTest('Form Validation Coverage', 'PASS',
\`\${validatedInputs}/\${totalInputs} inputs have validation\`);
}
} catch (error) {
this.logTest('Form Validation', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 6: Interactive Elements
async testInteractiveElements() {
console.log('\\n🔄 Testing Interactive Elements...');
try {
// Test dropdowns, toggles, accordions
const interactiveSelectors = [
'select',
'[role="button"]',
'[role="tab"]',
'[role="tabpanel"]',
'.accordion',
'.dropdown',
'.toggle',
'[data-toggle]',
'details',
'summary'
];
let interactiveCount = 0;
interactiveSelectors.forEach(selector => {
const elements = document.querySelectorAll(selector);
if (elements.length > 0) {
interactiveCount += elements.length;
this.logTest(\`Interactive \${selector}\`, 'PASS', \`Found \${elements.length} elements\`);
}
});
this.logTest('Interactive Elements Total', 'PASS', \`Found \${interactiveCount} interactive elements\`);
} catch (error) {
this.logTest('Interactive Elements', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 7: Console Error Detection
async testConsoleErrors() {
console.log('\\n🔄 Testing Console Errors...');
try {
// Override console methods to capture errors
const originalError = console.error;
const originalWarn = console.warn;
const capturedErrors = [];
const capturedWarnings = [];
console.error = function(...args) {
capturedErrors.push(args.join(' '));
originalError.apply(console, args);
};
console.warn = function(...args) {
capturedWarnings.push(args.join(' '));
originalWarn.apply(console, args);
};
// Wait a bit to capture any async errors
await this.sleep(2000);
// Restore original console methods
console.error = originalError;
console.warn = originalWarn;
this.logTest('Console Errors', capturedErrors.length === 0 ? 'PASS' : 'FAIL',
\`\${capturedErrors.length} errors found\`);
this.logTest('Console Warnings', capturedWarnings.length === 0 ? 'PASS' : 'WARN',
\`\${capturedWarnings.length} warnings found\`);
} catch (error) {
this.logTest('Console Error Detection', 'FAIL', \`Error: \${error.message}\`);
}
}
// Test 8: Responsive Design
async testResponsiveDesign() {
console.log('\\n🔄 Testing Responsive Design...');
try {
const originalWidth = window.innerWidth;
const originalHeight = window.innerHeight;
// Test different viewport sizes
const testSizes = [
{ name: 'Mobile', width: 375, height: 667 },
{ name: 'Tablet', width: 768, height: 1024 },
{ name: 'Desktop', width: 1920, height: 1080 }
];
for (const size of testSizes) {
// Note: We can't actually resize in a real browser, but we can check CSS
const mediaQuery = \`(max-width: \${size.width}px)\`;
const matches = window.matchMedia(mediaQuery).matches;
this.logTest(\`Responsive \${size.name}\`, 'PASS',
\`Media query \${mediaQuery} - \${matches ? 'matches' : 'does not match'}\`);
}
// Check for responsive elements
const responsiveElements = document.querySelectorAll('[class*="sm:"], [class*="md:"], [class*="lg:"], [class*="xl:"]');
this.logTest('Responsive Classes', responsiveElements.length > 0 ? 'PASS' : 'WARN',
\`Found \${responsiveElements.length} elements with responsive classes\`);
} catch (error) {
this.logTest('Responsive Design', 'FAIL', \`Error: \${error.message}\`);
}
}
// Main test runner
async runAllTests() {
console.log('🚀 Starting comprehensive QA testing...');
await this.testPageLoading();
await this.testButtonFunctionality();
await this.testLinkValidation();
await this.testModalOperations();
await this.testFormValidation();
await this.testInteractiveElements();
await this.testConsoleErrors();
await this.testResponsiveDesign();
// Generate summary report
this.generateReport();
}
generateReport() {
console.log(\`
🔍 TREEBIO QA TESTING REPORT
===========================
📊 TEST SUMMARY:
✅ Passed: \${this.passed.length}
❌ Failed: \${this.errors.length}
⚠️ Warnings: \${this.warnings.length}
\${this.errors.length === 0 ? '🎉 NO CRITICAL ERRORS FOUND!' : '🚨 CRITICAL ERRORS DETECTED!'}
📋 DETAILED RESULTS:
\`);
// Show failed tests first
if (this.errors.length > 0) {
console.log('\\n❌ FAILED TESTS:');
this.errors.forEach(error => {
console.log(\` • \${error.test}: \${error.details}\`);
});
}
// Show warnings
if (this.warnings.length > 0) {
console.log('\\n⚠️ WARNINGS:');
this.warnings.forEach(warning => {
console.log(\` • \${warning.test}: \${warning.details}\`);
});
}
// Show passed tests summary
console.log(\`\\n✅ PASSED TESTS: \${this.passed.length}\`);
console.log(\`
🎯 RECOMMENDATIONS:
\${this.errors.length > 0 ? '1. Fix critical errors immediately' : '1. No critical issues found'}
\${this.warnings.length > 5 ? '2. Review and address warnings' : '2. Warning levels are acceptable'}
3. Test actual user interactions manually
4. Verify real-time features work correctly
5. Test on actual mobile devices
✅ QA Testing Complete!
\`);
return {
passed: this.passed.length,
failed: this.errors.length,
warnings: this.warnings.length,
results: this.testResults
};
}
}
// Auto-run tests
const tester = new TreeBioQATester();
tester.runAllTests().then(() => {
console.log('🏁 Automated QA testing finished. Check the report above!');
});
// Export for manual testing
window.TreeBioQATester = TreeBioQATester;
window.runQATests = () => {
const newTester = new TreeBioQATester();
return newTester.runAllTests();
};