|
--- |
|
language: en |
|
tags: |
|
- playwright |
|
- test-automation |
|
- qa |
|
- e2e-testing |
|
- rag |
|
license: apache-2.0 |
|
datasets: |
|
- web-test-examples |
|
--- |
|
|
|
# Playwright Test Automator |
|
|
|
A specialized model for automated generation of Playwright E2E test scripts based on web application crawl data. |
|
|
|
## Overview |
|
|
|
Playwright Test Automator is built on a RAG-based architecture that combines AI-powered test generation with Playwright's robust browser automation capabilities. The model is designed to generate reliable, maintainable, and efficient end-to-end tests with minimal human intervention. |
|
|
|
## Features |
|
|
|
- **Automated Crawling**: Intelligently crawls web applications to discover interactive elements and page structures |
|
- **Smart Login Detection**: Automatically identifies login forms and credentials fields |
|
- **Robust Selector Generation**: Creates resilient selectors that withstand minor UI changes |
|
- **Error Handling**: Implements comprehensive error handling for reliable test execution |
|
- **Validation Framework**: Integrated with Giskard for model validation and continuous improvement |
|
|
|
## Use Cases |
|
|
|
- Generating regression test suites for web applications |
|
- Automating QA workflows for small to large web projects |
|
- Creating test scripts for complex user journeys |
|
- Validating forms and interactive elements across browsers |
|
|
|
## Requirements |
|
|
|
- Python 3.11+ |
|
- Playwright |
|
- OpenAI API access |
|
- Supabase for knowledge retrieval (optional) |
|
|
|
## Example Usage |
|
|
|
```python |
|
from services.crawler_service import crawler_service |
|
|
|
# Crawl a website and generate tests |
|
test_result = await crawler_service.crawl_with_login( |
|
url="https://example.com/login", |
|
username="test_user", |
|
password="password123" |
|
) |
|
|
|
# Generate a Playwright test from the crawl data |
|
test_code = await crawler_service.generate_test_from_crawl_data(test_result) |
|
|
|
# Write the test to a file |
|
with open("example_test.spec.js", "w") as f: |
|
f.write(test_code["code"]) |
|
``` |
|
|
|
## Sample Generated Test |
|
|
|
```javascript |
|
// Example E2E Test |
|
// Automated test for Example Application |
|
// Auto-generated by Playwright Test Automator |
|
|
|
import { test, expect } from '@playwright/test'; |
|
|
|
test('Example E2E Test', async ({ page }) => { |
|
// Configure viewport for better element visibility |
|
await page.setViewportSize({ width: 1280, height: 800 }); |
|
|
|
// Helper function for safer element interactions |
|
async function safeClick(selector, description) { |
|
// Implementation details... |
|
} |
|
|
|
// Navigate to the application |
|
await page.goto('https://example.com/login'); |
|
|
|
// Login process |
|
await page.fill("input[type='text'][name='username']", "test_user"); |
|
await page.fill("input[type='password']", "password123"); |
|
await safeClick("button[type='submit']", "login button"); |
|
|
|
// Verify successful login |
|
await expect(page).toHaveURL(/dashboard/); |
|
}); |
|
``` |
|
|
|
## Limitations |
|
|
|
- Best performance on standard web forms and common UI patterns |
|
- May require adjustments for highly dynamic or custom UI frameworks |
|
- Requires valid credentials for protected areas of applications |
|
|
|
## Training Methodology |
|
|
|
This model was trained on a diverse set of web applications using a specialized dataset of high-quality test scripts. The training process included: |
|
|
|
1. Web crawling of various application types |
|
2. Test generation with OpenAI integration |
|
3. Validation using Giskard framework |
|
4. Iterative improvements based on execution results |
|
|
|
## Citation |
|
|
|
``` |
|
@misc{playwright-test-automator, |
|
author = {QA RAG App Team}, |
|
title = {Playwright Test Automator}, |
|
year = {2025}, |
|
publisher = {Hugging Face}, |
|
journal = {HuggingFace Hub}, |
|
howpublished = {\url{https://huggingface.co/playwright-test-automator}} |
|
} |
|
``` |
|
|