|
85 | 85 | const openai = new OpenAI({ apiKey: process.env['OPENAI_API_KEY'] })
|
86 | 86 |
|
87 | 87 | const completion = await openai.chat.completions.create({
|
88 |
| - model: 'gpt-3.5-turbo-0125', |
| 88 | + model: 'gpt-3.5-turbo', |
89 | 89 | messages,
|
90 | 90 | })
|
91 | 91 |
|
@@ -354,6 +354,131 @@ npx codeceptjs run --ai
|
354 | 354 | When execution finishes, you will receive information on token usage and code suggestions proposed by AI.
|
355 | 355 | By evaluating this information you will be able to check how effective AI can be for your case.
|
356 | 356 |
|
| 357 | +## Analyze Results |
| 358 | +
|
| 359 | +When running tests with AI enabled, CodeceptJS can automatically analyze test failures and provide insights. The analyze plugin helps identify patterns in test failures and provides detailed explanations of what went wrong. |
| 360 | +
|
| 361 | +Enable the analyze plugin in your config: |
| 362 | +
|
| 363 | +```js |
| 364 | +plugins: { |
| 365 | + analyze: { |
| 366 | + enabled: true, |
| 367 | + // analyze up to 3 failures in detail |
| 368 | + analyze: 3, |
| 369 | + // group similar failures when 5 or more tests fail |
| 370 | + clusterize: 5, |
| 371 | + // enable screenshot analysis (requires modal that can analyze screenshots) |
| 372 | + vision: false |
| 373 | + } |
| 374 | +} |
| 375 | +``` |
| 376 | +
|
| 377 | +When tests are executed with `--ai` flag, the analyze plugin will: |
| 378 | +
|
| 379 | +**Analyze Individual Failures**: For each failed test (up to the `analyze` limit), it will: |
| 380 | +
|
| 381 | +- Examine the error message and stack trace |
| 382 | +- Review the test steps that led to the failure |
| 383 | +- Provide a detailed explanation of what likely caused the failure |
| 384 | +- Suggest possible fixes and improvements |
| 385 | +
|
| 386 | +Sample Analysis report: |
| 387 | +
|
| 388 | +When analyzing individual failures (less than `clusterize` threshold), the output looks like this: |
| 389 | +
|
| 390 | +``` |
| 391 | +🪄 AI REPORT: |
| 392 | +-------------------------------- |
| 393 | +→ Cannot submit registration form with invalid email 👀 |
| 394 | + |
| 395 | +* SUMMARY: Form submission failed due to invalid email format, system correctly shows validation message |
| 396 | +* ERROR: expected element ".success-message" to be visible, but it is not present in DOM |
| 397 | +* CATEGORY: Data errors (password incorrect, no options in select, invalid format, etc) |
| 398 | +* STEPS: I.fillField('#email', 'invalid-email'); I.click('Submit'); I.see('.success-message') |
| 399 | +* URL: /register |
| 400 | + |
| 401 | +``` |
| 402 | +
|
| 403 | +> The 👀 emoji indicates that screenshot analysis was performed (when `vision: true`). |
| 404 | +
|
| 405 | +**Cluster Similar Failures**: When number of failures exceeds the `clusterize` threshold: |
| 406 | +
|
| 407 | +- Groups failures with similar error patterns |
| 408 | +- Identifies common root causes |
| 409 | +- Suggests fixes that could resolve multiple failures |
| 410 | +- Helps prioritize which issues to tackle first |
| 411 | +
|
| 412 | +**Categorize Failures**: Automatically classifies failures into categories like: |
| 413 | +
|
| 414 | +- Browser/connection issues |
| 415 | +- Network errors |
| 416 | +- Element locator problems |
| 417 | +- Navigation errors |
| 418 | +- Code errors |
| 419 | +- Data validation issues |
| 420 | +- etc. |
| 421 | +
|
| 422 | +Clusterization output: |
| 423 | +
|
| 424 | +``` |
| 425 | +🪄 AI REPORT: |
| 426 | +_______________________________ |
| 427 | + |
| 428 | +## Group 1 🔍 |
| 429 | + |
| 430 | +* SUMMARY: Element locator failures across login flow |
| 431 | +* CATEGORY: HTML / page elements (not found, not visible, etc) |
| 432 | +* ERROR: Element "#login-button" is not visible |
| 433 | +* STEP: I.click('#login-button') |
| 434 | +* SUITE: Authentication |
| 435 | +* TAG: @login |
| 436 | +* AFFECTED TESTS (4): |
| 437 | + x Cannot login with valid credentials |
| 438 | + x Should show error on invalid login |
| 439 | + x Login button should be disabled when form empty |
| 440 | + x Should redirect to dashboard after login |
| 441 | + |
| 442 | +## Group 2 🌐 |
| 443 | + |
| 444 | +* SUMMARY: API timeout issues during user data fetch |
| 445 | +* CATEGORY: Network errors (server error, timeout, etc) |
| 446 | +* URL: /api/v1/users |
| 447 | +* ERROR: Request failed with status code 504, Gateway Timeout |
| 448 | +* SUITE: User Management |
| 449 | +* AFFECTED TESTS (3): |
| 450 | + x Should load user profile data |
| 451 | + x Should display user settings |
| 452 | + x Should fetch user notifications |
| 453 | + |
| 454 | +## Group 3 ⚠️ |
| 455 | + |
| 456 | +* SUMMARY: Form validation errors on registration page |
| 457 | +* CATEGORY: Data errors (password incorrect, no options in select, invalid format, etc) |
| 458 | +* ERROR: Expected field "password" to have error "Must be at least 8 characters" |
| 459 | +* STEP: I.see('Must be at least 8 characters', '.error-message') |
| 460 | +* SUITE: User Registration |
| 461 | +* TAG: @registration |
| 462 | +* AFFECTED TESTS (2): |
| 463 | + x Should validate password requirements |
| 464 | + x Should show all validation errors on submit |
| 465 | +``` |
| 466 | +
|
| 467 | +If `vision: true` is enabled and your tests take screenshots on failure, the plugin will also analyze screenshots to provide additional visual context about the failure. |
| 468 | +
|
| 469 | +The analysis helps teams: |
| 470 | +
|
| 471 | +- Quickly understand the root cause of failures |
| 472 | +- Identify patterns in failing tests |
| 473 | +- Prioritize fixes based on impact |
| 474 | +- Maintain more stable test suites |
| 475 | +
|
| 476 | +Run tests with both AI and analyze enabled: |
| 477 | +
|
| 478 | +```bash |
| 479 | +npx codeceptjs run --ai |
| 480 | +``` |
| 481 | +
|
357 | 482 | ## Arbitrary Prompts
|
358 | 483 |
|
359 | 484 | What if you want to take AI on the journey of test automation and ask it questions while browsing pages?
|
|
0 commit comments