UNPKG

playwright-salad

Version:

A utility package for Playwright automation testing

61 lines (52 loc) 1.66 kB
const { chromium } = require('playwright'); class PlaywrightSalad { constructor() { this.browser = null; this.context = null; this.page = null; } async init() { this.browser = await chromium.launch(); this.context = await this.browser.newContext(); this.page = await this.context.newPage(); } async navigate(url) { if (!this.page) { throw new Error('Browser not initialized. Call init() first.'); } await this.page.goto(url); } async waitForSelector(selector, options = {}) { if (!this.page) { throw new Error('Browser not initialized. Call init() first.'); } await this.page.waitForSelector(selector, options); } async click(selector) { if (!this.page) { throw new Error('Browser not initialized. Call init() first.'); } await this.page.click(selector); } async type(selector, text) { if (!this.page) { throw new Error('Browser not initialized. Call init() first.'); } await this.page.fill(selector, text); } async getText(selector) { if (!this.page) { throw new Error('Browser not initialized. Call init() first.'); } return await this.page.textContent(selector); } async close() { if (this.browser) { await this.browser.close(); this.browser = null; this.context = null; this.page = null; } } } module.exports = { PlaywrightSalad };