File size: 3,665 Bytes
15cc04e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
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}}
}
```