Setting up QA testing agents using playwright and crewAI
AISquare Studio AutoQA
ai automation testing playwright github-action crewai openai qa test-generation multi-agent
AI-powered GitHub Action that converts natural language test descriptions in pull request bodies into fully automated Playwright tests. Write what you want to test in plain English β AutoQA generates, executes, and commits production-ready test code using CrewAI multi-agent orchestration and OpenAI GPT-4.
Features
- AI-Powered Test Generation β Natural language steps become executable Playwright Python tests
- Active Execution Mode β Iterative step-by-step generation with real-time browser context
- Smart Selector Discovery β Auto-discovers optimal selectors from live pages via DOMInspectorTool
- Intelligent Retry β Automatic error recovery with alternative selectors and failure analysis
- AST-Based Security Validation β Prevents unsafe code patterns before execution
- Cross-Repository Architecture β Deploys as a GitHub Action, runs in any repository
- Comprehensive Reporting β PR comments with screenshots, HTML reports, and JSON artifacts
- ETag-Based Idempotency β Prevents duplicate test generation for unchanged PR descriptions
- Multi-Tier Test Organization β Categorize tests into A/B/C tiers by criticality
- Caching Strategy β Pip and Playwright browser caching for fast CI runs
How It Works
PR Description AutoQA Action Your Repository
ββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
βautoqa β β 1. Parse PR body β β tests/autoqa/ β
β flow: login ββββββΆβ 2. Generate code ββββββΆβ A/auth/ β
β tier: A β β 3. Validate AST β β test_login.pyβ
β area: auth β β 4. Execute tests β ββββββββββββββββββββ
β β β 5. Commit on passβ
β β β 6. Comment on PR β
β 1. Go to / β ββββββββββββββββββββ
β 2. Login β
β 3. Verify β
ββββββββββββββββ
- A developer writes numbered test steps in the PR description inside a fenced
autoqablock - The GitHub Action triggers on PR open/edit/sync events
- AutoQA parses the PR body for metadata (
flow_name,tier,area) and test steps - CrewAI agents generate Playwright Python test code from the steps
- Generated code is validated via AST analysis and executed against your staging environment
- On success, the test file is committed to
tests/autoqa/{tier}/{area}/test{flowname}.py - Results and screenshots are posted as a PR comment
Quick Start
1. Add the workflow
Create .github/workflows/autoqa.yml in your repository:
name: AutoQA Test Generation
on: pull_request: types: [opened, synchronize, edited]
jobs: autoqa: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate and Execute Tests uses: AISquare-Studio/AISquare-Studio-QA@main with: openai-api-key: ${{ secrets.OPENAIAPIKEY }} staging-url: ${{ secrets.STAGING_URL }} staging-email: ${{ secrets.STAGING_EMAIL }} staging-password: ${{ secrets.STAGING_PASSWORD }}
2. Configure secrets
Add the following secrets in your repository's Settings β Secrets and variables β Actions:
| Secret | Description | | ------------------ | --------------------------------- | | OPENAIAPIKEY | OpenAI API key (GPT-4 access) | | STAGING_URL | Staging environment login URL | | STAGING_EMAIL | Test account email | | STAGING_PASSWORD | Test account password |
3. Write test steps in a PR
Include a fenced autoqa block in your pull request description:
markdown</code></pre>autoqa
flowname: userlogin_success
tier: A
area: auth
<pre><code class="lang-">1. Navigate to the login page
- Enter valid email address
- Enter valid password
- Click the login button
- Verify the dashboard appears</code></pre>
Open the PR and AutoQA takes care of the rest.
PR Format Reference
The autoqa code block defines metadata. Numbered steps below it describe the test scenario.
markdown</code></pre>autoqa
flowname: <snakecasetestname>
tier: <A|B|C>
area: <feature_area>
<pre><code class="lang-">1. First test step in plain English
- Second test step
- ...</code></pre>
| Field | Required | Description |
| ----------- | -------- | --------------------------------------------------------- |
| flow_name | Yes | Snake-case identifier used for the generated file name |
| tier | Yes | A (critical), B (important), or C (nice-to-have) |
| area | Yes | Feature area used as subdirectory (e.g., auth, billing) |
Configuration Reference
Action Inputs
| Input | Required | Default | Description | | ------------------- | -------- | ---------------- | ------------------------------------------------- | | openai-api-key | Yes | β | OpenAI API key
| openai-model | No | openai/gpt-4.1 | OpenAI model for test generation (e.g., openai/gpt-4.1, openai/gpt-4o) | | | staging-url | Yes | β | Staging environment URL | | qa-github-token | No | github.token | GitHub token (for private repo access) | | staging-email | No | test@example.com | Test account email | | staging-password | No | β | Test account password | | target-repo-path | No | . | Path to the target repository | | git-user-name | No | AutoQA Bot | Git user name for test commits | | git-user-email | No | β | Git user email for test commits | | pr-body | No | (auto-detected) | PR description text | | test-directory | No | tests/autoqa | Base directory for generated tests | | create-pr | No | false | Create a PR for tests instead of pushing directly | | execution-mode | No | generate | Execution mode: generate, suite, or all |
Action Outputs
| Output | Description | | --------------------- | --------------------------------------- | | test_generated | Whether a test was generated (true/false) | | testfilepath | Path to the generated test file | | test_results | JSON object with execution results | | generation_metadata | JSON object with generation metadata | | screenshot_path | Path to captured screenshots | | etag | Idempotency hash of the PR description | | flow_name | Parsed flow name | | tier | Parsed tier | | area | Parsed area | | error | Error message (if failed) |
Execution Modes
| Mode | Behavior | | ---------- | ----------------------------------------------------------------- | | generate | Parse PR, generate a new test, execute it, and commit on success | | suite | Run the existing test suite only (regression testing) | | all | Generate a new test and run the full existing suite |
Project Structure
AISquare-Studio-QA/
βββ action.yml # GitHub Action definition
βββ qa_runner.py # Local test runner entry point
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Python project configuration
βββ pytest.ini # Pytest configuration
βββ env.template # Environment variables template
βββ .github/
β βββ copilot-instructions.md # Copilot custom instructions (AI agent reference)
β βββ workflows/ # CI/CD workflows (lint, test, release)
βββ config/
β βββ autoqa_config.yaml # AutoQA policy and settings
β βββ test_data.yaml # Test scenarios and selectors
βββ src/
β βββ agents/
β β βββ planner_agent.py # Generates Playwright code via CrewAI
β β βββ executor_agent.py # Validates and executes code (AST safety)
β β βββ stepexecutoragent.py # Active execution step agent
β βββ autoqa/
β β βββ action_runner.py # Main GitHub Action orchestrator
β β βββ parser.py # PR body metadata parser
β β βββ action_reporter.py # PR comment generator
β β βββ crossrepomanager.py # Test file commits across repos
β βββ crews/
β β βββ qa_crew.py # CrewAI agent orchestration
β βββ execution/
β β βββ iterative_orchestrator.py # Step-by-step execution coordinator
β β βββ execution_context.py # State tracking between steps
β β βββ retry_handler.py # Failure analysis and retry logic
β βββ tools/
β β βββ playwright_executor.py # Test code execution engine
β β βββ dom_inspector.py # Live page selector discovery
β βββ templates/
β β βββ testexecutiontemplate.py # Execution template
β βββ utils/
β βββ logger.py # GitHub Actions-aware logging
β βββ githubcommentclient.py # GitHub API client
β βββ comment_builder.py # Markdown comment builder
β βββ screenshot_handler.py # Screenshot capture
β βββ screenshotembedmanager.py # Screenshot embedding
βββ tests/ # Pytest test suites
βββ docs/ # Documentation
βββ examples/ # Example workflows and configs
βββ reports/ # Generated test artifacts
βββ scripts/ # Utility scripts
Local Development
Prerequisites
- Python 3.11+
- An OpenAI API key with GPT-4 access
Setup
# Clone the repository
git clone https://github.com/AISquare-Studio/AISquare-Studio-QA.git
cd AISquare-Studio-QA
Install dependencies
pip install -r requirements.txt
playwright install --with-deps chromium
Configure environment
cp env.template .env
Edit .env with your staging URL, credentials, and OpenAI API key
Running locally
# Run the test runner
python qa_runner.py
Run with visible browser for debugging
HEADLESSMODE=false python qarunner.py
Show detailed help
python qa_runner.py --help-detailed
Running the test suite
pytest tests/ -v
Architecture
AutoQA uses a multi-agent architecture powered by CrewAI:
- Planner Agent β Converts natural language steps into Playwright Python code
- Executor Agent β Validates generated code via AST analysis and runs it in a sandboxed browser
- Step Executor Agent β Handles Active Execution Mode, processing one step at a time with live browser context
The Iterative Orchestrator coordinates step-by-step execution, maintaining state via ExecutionContext and handling failures through RetryHandler.
For a detailed architecture walkthrough, see docs/ARCHITECTURE.md.
Security
All AI-generated code is validated before execution:
- AST-based validation β Blocks dangerous constructs (
eval, exec, open, subprocess, file I/O)
- Restricted imports β Only
playwright.sync_api, time, datetime, and re are permitted
- Sandboxed execution β Tests run in isolated Playwright browser contexts
- Secret redaction β Sensitive values are masked in logs and reports
See the Security Model section in the architecture documentation for details.
Performance and Caching
AutoQA caches dependencies to minimize CI run times:
| Layer | Cache Key | Typical Size | | --------------------- | ------------------------------- | ------------ | | Python pip packages | Hash of requirements.txt | ~200 MB | | Playwright browsers | Playwright version | ~100 MB | | Action repository | Commit SHA | ~5 MB |
| Scenario | Approximate Time | | --------- | ---------------- | | Cold run | 3β4 minutes | | Warm run | 45β60 seconds |
Caches automatically invalidate when requirements.txt changes.
Code Quality and Linting
The project enforces consistent style via automated tooling:
| Tool | Purpose | Configuration | | --------- | ----------------------------- | ---------------------- | | black | Code formatting | Line length: 100 | | isort | Import sorting | Black-compatible profile | | flake8| PEP 8 compliance | Standard rules |
The lint.yml workflow runs on every push and pull request, auto-fixing formatting issues.
# Run locally
black . --line-length=100
isort . --profile=black --line-length=100
flake8 .
Roadmap
See docs/AUTOQAENHANCEMENTROADMAP.md for the full enhancement roadmap, including 16 feature proposals inspired by Lucent AI and Meticulous AI covering AI-generated test criteria from code diffs, visual regression detection, self-healing tests, automatic bug reports, and more.
For open-source readiness status, see docs/OPENSOURCE_ROADMAP.md.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Ensure linting passes (
black, isort, flake8)
- Submit a pull request
Please review the CODEOF_CONDUCT.md before contributing.
AI agent sessions: This repository includes a
.github/copilot-instructions.md file that
GitHub Copilot reads automatically. It contains architecture reference, version
tables, and a mandatory session checklist (update CHANGELOG, README, examples, etc.).
License
This project is licensed under the Apache License 2.0.
Copyright 2025 AISquare Studio
Contributors
| Avatar | Name | Role | | ------ | ---- | ---- | | π€ | AutoQA Bot | Automation | | π©βπ» | Zahwah | Contributor | | π©βπΌ | Rabia | Maintainer |
Built by AISquare Studio