Skip to content

| AI-Powered Playwright Script Generator | This project is a user-friendly web portal designed to accelerate the creation of end-to-end tests by leveraging the power of Generative AI.

Notifications You must be signed in to change notification settings

iklymchuk/ai-playwright-script-generator

Repository files navigation

AI-Powered Playwright Script Generator

Screenshot 2025-10-11 at 19 45 29

This project is a user-friendly web portal designed to accelerate the creation of end-to-end tests by leveraging the power of Generative AI. Users can input a web address and a natural language test scenario, and the application will automatically generate the necessary Python code, following the industry-standard Page Object Model (POM).


The Problem: The Manual Grind of Test Automation

In modern software development, end-to-end testing is crucial for ensuring quality. However, writing and maintaining these tests is often a time-consuming and repetitive process. QA Engineers and SDETs spend a significant amount of time on boilerplate tasks:

  • Manually inspecting the DOM to find stable element locators.
  • Writing locator definitions and interaction methods for a Page Object.
  • Structuring the test script to import the page object and execute the steps.

This manual effort slows down the development cycle and can be a barrier to achieving comprehensive test coverage, especially for teams under tight deadlines.

The Solution: Speeding Up QA with AI

This tool addresses the bottleneck by automating the most tedious parts of test script creation. By simply describing a test scenario in plain English, a QA engineer can get a complete, well-structured first draft of their test in seconds.

How AI Accelerates the QA Routine:

Screenshot 2025-10-11 at 19 50 32
  1. From Intent to Code: The AI acts as a translator, converting a high-level user story (e.g., "Add two items to the todo list and mark one as complete") into precise, executable Playwright code.
  2. Automated POM Generation: The AI analyzes the request and generates a clean Page Object class, complete with robust locators (prioritizing user-facing ones like get_by_role) and interaction methods. This saves significant time and promotes a maintainable, reusable test architecture from the start.
  3. Rapid Prototyping: Engineers can quickly generate tests for new features or bug fixes, getting immediate feedback and a solid foundation to build upon. This allows them to focus their expertise on more complex logic, edge cases, and overall test strategy rather than on repetitive coding.

Generation Analysis

Screenshot 2025-10-11 at 19 50 43

To provide immediate insight into the quality of the generated code, the application includes a "Generation Analysis" section that visualizes key metrics after each generation:

  • Code Breakdown (Doughnut Chart): This chart displays the ratio of code lines between the Page Object file and the Test Script file. It offers a quick overview of the code's structural balance.
  • Locator Strategy (Bar Chart): This chart analyzes and counts the different types of Playwright locators (e.g., get_by_role, get_by_text) used in the generated code. This provides an at-a-glance assessment of the selectors' quality and adherence to best practices, favoring more robust, user-facing locators.

These visualizations help engineers quickly evaluate the AI's output before diving into the code.

Disclaimer: This is a Prototype

It is crucial to understand that this project is a simple prototype and a proof-of-concept. It is not a production-ready product.

The goal is to demonstrate the potential of AI in the QA space. The generated code should be seen as a powerful starting point or a "smart assistant," but it always requires review, and potentially modification, by a qualified engineer before being integrated into a production test suite.

Tech Stack

  • Frontend: React, TypeScript, Tailwind CSS
  • AI Integration: Google Gemini API (gemini-2.5-flash), OpenAI API (gpt-4o)
  • Generated Code: Python, Playwright, Pytest

How to Run the Generated Scripts

Once you've generated and downloaded the page_object.py and test_script.py files:

  1. Setup Your Environment: Make sure you have Python installed, then install the necessary packages.

    # Install Playwright, Pytest, and the plugin
    pip install playwright pytest pytest-playwright
    
    # Download the necessary browser binaries
    playwright install
  2. Run the Test: Navigate to the directory where you saved the files and run Pytest.

    pytest test_script.py

About

| AI-Powered Playwright Script Generator | This project is a user-friendly web portal designed to accelerate the creation of end-to-end tests by leveraging the power of Generative AI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published