|
| 1 | +# AI Test Generator (OpenAI-powered) |
| 2 | + |
| 3 | +This module enables AI-driven Playwright test generation using OpenAI's API and prompt templates. |
| 4 | + |
| 5 | +## Features |
| 6 | +- Generates Playwright tests from prompt templates and config data |
| 7 | +- Supports CSV-driven test data, API endpoints, and DB config |
| 8 | +- Uses OpenAI API for intelligent test creation |
| 9 | +- Secure API key management via `.env` |
| 10 | + |
| 11 | +## Usage |
| 12 | +1. **Set up OpenAI API Key:** |
| 13 | + - Copy `.env.example` to `.env` and add your OpenAI API key: |
| 14 | + ``` |
| 15 | + OPENAI_API_KEY=your-openai-api-key-here |
| 16 | + ``` |
| 17 | +2. **Install dependencies:** |
| 18 | + - Run: |
| 19 | + ``` |
| 20 | + npm install |
| 21 | + ``` |
| 22 | +3. **Configure appConfig:** |
| 23 | + - Edit `config/appConfig.js` to set paths for test data, API endpoints, and DB config. |
| 24 | +4. **Edit prompt templates:** |
| 25 | + - Update or create prompt files in `prompts/` (e.g., `playwright_login_test_generation.txt`). |
| 26 | +5. **Run the generator:** |
| 27 | + - Execute: |
| 28 | + ``` |
| 29 | + node ai/generate_generic_tests_ai.js |
| 30 | + ``` |
| 31 | + - The generated test will be saved to `tests/mab/AI_GeneratedTest.spec.js`. |
| 32 | +
|
| 33 | +## Customization |
| 34 | +- Add new prompt templates for different test scenarios. |
| 35 | +- Update `ai/generate_generic_tests_ai.js` to use your desired prompt file. |
| 36 | +
|
| 37 | +## Security |
| 38 | +- `.env` is gitignored by default. |
| 39 | +- Never commit your API key. |
| 40 | +
|
| 41 | +## Troubleshooting |
| 42 | +- Ensure your OpenAI API key is valid and set in `.env`. |
| 43 | +- If you see `Missing credentials` errors, check your `.env` setup. |
| 44 | +- For OpenAI API errors, verify your network and API quota. |
| 45 | +
|
| 46 | +## Example Prompt Template |
| 47 | +See `prompts/playwright_login_test_generation.txt` for a sample login test prompt. |
| 48 | +
|
| 49 | +## License |
| 50 | +MIT |
| 51 | +
|
| 52 | +**Experimental Stage:** |
| 53 | +This AI test generator is currently in an experimental phase. Features and workflows may change, and reliability is not guaranteed for production use. Feedback and contributions are welcome! |
| 54 | +
|
| 55 | +## Future Enhancements Planned |
| 56 | +
|
| 57 | +- Support for Playwright API and DB test generation |
| 58 | +- Multi-prompt scenario chaining |
| 59 | +- Improved error handling and reporting |
| 60 | +- Integration with CI/CD pipelines |
| 61 | +- Customizable output file locations |
| 62 | +- Enhanced prompt templating and variable injection |
| 63 | +- Support for other AI providers (Azure, Anthropic, etc.) |
| 64 | +- Automated test validation and coverage analysis |
0 commit comments