playwright-sit-converter
Version:
Convert Playwright test scripts to SIT (System Integration Testing) documentation
67 lines (57 loc) • 3.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BobTheBuilder = void 0;
const genai_1 = require("@google/genai"); // Updated import statement
class BobTheBuilder {
constructor(apiKey) {
this.genAI = new genai_1.GoogleGenAI({ apiKey: apiKey });
this.generationConfig = {
response_mime_type: 'text/plain',
};
this.systemInstruction = `You are an AI that converts Playwright test scripts into a structured table format for System Integration Testing (SIT). For each test step in the Playwright script, create a table with the following columns:
1. **No**: Step number.
2. **Test Case ID**: A unique identifier for the test case.
3. **Case**: A brief description of the test case.
4. **Sub Case**: Detailed action for each step in the test case.
5. **Pre Condition**: Conditions that must be met before executing the step.
6. **Expected Result**: The expected outcome after performing the action.
### Input Format:
- The input will be a Playwright script containing test steps.
### Output Format:
- A table structured as per the columns mentioned above.
### Example:
**Input:**
\`\`\`javascript
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('https://example.com/login');
await page.getByText('Login').click();
await page.getByRole('textbox', { name: 'username' }).fill('admin');
await page.getByRole('textbox', { name: 'password' }).fill('password123');
await expect(page.getByRole('button', { name: 'Submit' })).toBeVisible();
await page.getByRole('button', { name: 'Submit' }).click();
});
\`\`\`
**Expected Output:**
| No | Test Case ID | Case | Sub Case | Pre Condition | Expected Result |
|----|--------------|---------------------|-------------------------------------|-----------------------|-------------------------------------------------|
| 1 | TC-001 | User Login | Access login page | User is not logged in | The login page is displayed. |
| 2 | TC-001 | User Login | Click on 'Login' | Login page is shown | The login form is displayed. |
| 3 | TC-001 | User Login | Fill Username Field | Login form is displayed| The username textbox shows the input value. |
| 4 | TC-001 | User Login | Fill Password Field | Username is filled | The password textbox shows the input value. |
| 5 | TC-001 | User Login | Check Submit Button Visibility | Username and password filled | The 'Submit' button is visible. |
| 6 | TC-001 | User Login | Click Submit Button | Submit button is visible | User is logged in and redirected to the dashboard. |
ALWAYS RETURN CSV FORMAT INCLUDING TABLE HEADER AND DONT MAKE OUTPUT INSIDE A CODEBLOCK
`;
}
async generateResponse(playwrightScript) {
const result = await this.genAI.models.generateContent({
model: "gemini-2.0-flash",
contents: `${this.systemInstruction} + ${playwrightScript}`,
});
return result.text ?? '';
}
}
exports.BobTheBuilder = BobTheBuilder;