playwright-ai-codegen-lib
Version:
A utility to auto-generate Playwright PageObjects and test scripts using OpenAI and DOM extraction.
31 lines (30 loc) • 1.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const openAiHelper_1 = require("./openAiHelper");
async function run() {
// Read selectors from file
const selectorsPath = path_1.default.resolve(process.cwd(), 'selectors.json');
const selectors = JSON.parse(fs_1.default.readFileSync(selectorsPath, 'utf-8'));
if (!selectors || selectors.length === 0) {
console.error('❌ No selectors found. Please run Step 1 first.');
process.exit(1);
}
// Get title from command line argument
const inputTitle = process.argv[2];
const title = inputTitle ? inputTitle : 'ProvidePageName';
// Generate the page object class code
const functionsCode = await (0, openAiHelper_1.generateFunctions)(selectors, title);
// Save the final output
const outputDir = path_1.default.resolve(process.cwd(), 'pageObjects');
if (!fs_1.default.existsSync(outputDir))
fs_1.default.mkdirSync(outputDir);
const filePath = path_1.default.join(outputDir, `${title}Page.ts`);
fs_1.default.writeFileSync(filePath, functionsCode, 'utf-8');
console.log(`✅ Page object with functions saved to: ${filePath}`);
}
run();