Features
End to End Testing

E2E UI Test Generator

Streamline the process of creating and maintaining comprehensive end-to-end tests for web applications using the Playwright testing framework.
Generate robust and maintainable test scripts that can be seamlessly integrated into a CI/CD pipeline.

Key Features

  1. Test Plan Generation: The feature analyzes the application requirements or specifications and automatically generates a comprehensive test plan, covering various user flows and scenarios.

  2. Playwright Test Script Generation: Based on the test plan, the feature generates Playwright test scripts written in Python 3.9, following best practices and industry standards.

  3. Page Object Model: The generated scripts implement the Page Object Model (POM) design pattern, promoting code reusability, maintainability, and separation of concerns.

  4. Web Element Interaction: The scripts leverage Playwright's powerful features for interacting with web elements, such as clicking buttons, filling out forms, and navigating between pages.

  5. Visual Testing: The feature utilizes Playwright's capabilities to capture screenshots and videos during test execution, enabling visual validation and debugging.

How it Works

  • Provide the URL of the web application you want to test.
  • The E2E UI Test Generator analyzes the web application's content and structure.
  • It generates comprehensive Playwright test scripts covering various UI modules and user flows.
  • The generated scripts can be executed locally or integrated into a CI/CD pipeline.

E2E Test Generation Process

You can find an example here (opens in a new tab)

Usage Guide

Here's a detailed step-by-step guide on how to use the E2E UI Test Generator:

  1. Follow the initial setup guide here.

  2. Create a new Python file and import the E2ETestGenerator module:

    from kaizen.generator.e2e_tests import E2ETestGenerator
  3. Create an instance of the E2ETestGenerator:

    generator = E2ETestGenerator()
  4. Generate E2E tests for a specific URL:

    WEBPAGE_URL = "https://example.com"
    tests, * = generator.generate_e2e_tests(WEBPAGE_URL)
  5. Display the generated tests:

    for test in tests:
        print(f'Module Title: {test["module_title"]} || Importance: {test["importance"]}')
        for t in test["tests"]:
            print(f'Description: {t["test_description"]}')
            print(f'Code: \n{t["code"]}')
            print("-----------------------------------------------------------")
  6. Run the generated tests:

    results = generator.run_tests()
    print(f"Test Execution results: \n {results}")
  7. Review the generated tests and execution results, and integrate them into your development workflow.

Example

Here's a complete example to generate and run E2E UI tests:

from kaizen.generator.e2e_tests import E2ETestGenerator
import time
import sys
import traceback
 
# Create an instance of the E2E Test Generator
generator = E2ETestGenerator()
 
# Set the webpage URL to test
WEBPAGE_URL = "https://cloudcode.ai"
 
print(f"Generating UI tests for `{WEBPAGE_URL}`, please wait...")
start_time = time.time()
 
try:
    # Generate E2E tests
    tests, * = generator.generate_e2e_tests(WEBPAGE_URL)
except Exception as e:
    print(f"Error: {e}")
    print(traceback.format_exc())
    sys.exit(1)
 
end_time = time.time()
elapsed_time = end_time - start_time
print(f"\nUI tests generated in {elapsed_time:.2f} seconds.")
 
# Display generated tests
for test in tests:
    print(
        f'#### ======== Module Title: {test["module_title"]} || Importance: {test["importance"]} ========== ####'
    )
    for t in test["tests"]:
        print(f'Desc: {t["test_description"]}')
        print(f'Code: \n{t["code"]}')
        print("-----------------------------------------------------------")
 
# Run the generated tests
results = generator.run_tests()
print(f"Test Execution results: \n {results}")

To execute the generated tests:

import pytest
 
if __name__ == "__main__":
    test_dir = ".kaizen/tests"
    pytest.main(
        [
            "--timeout=60",
            "-v",
            test_dir,
        ]
    )

Supported Frameworks

  • Playwright

Benefits

  • Accelerated Test Development
  • Improved Test Coverage
  • Maintainability and Reusability
  • Continuous Quality Assurance
  • Visual Validation
  • Scalability

Limitations

  • Dynamic Content: May have limitations with highly dynamic or JavaScript-heavy applications.
  • Complex Interactions: Advanced user interactions might require manual scripting.
  • Test Data Management: Might need additional setup for managing test data across different environments.