Skip to content

Instantly share code, notes, and snippets.

@hoangsetup
Created June 19, 2021 08:27
Show Gist options
  • Save hoangsetup/af2a890f867e2b6fbfdb7522fc580788 to your computer and use it in GitHub Desktop.
Save hoangsetup/af2a890f867e2b6fbfdb7522fc580788 to your computer and use it in GitHub Desktop.
import { ElementHandle } from 'puppeteer';
export default abstract class BasePO {
protected readonly BASE_URL = 'https://www.saucedemo.com';
abstract go(): Promise<void>;
async navigate(url: string) {
await page.goto(`${this.BASE_URL}${url}`);
}
async getElementTextBySelector($selector: string): Promise<string> {
const element = await page.$($selector);
if (!element) {
return '';
}
return page.evaluate((ele: HTMLElement) => ele.textContent || '', element);
}
async getElementText($element: ElementHandle<Element>): Promise<string> {
return $element.evaluate((ele: HTMLElement) => ele.textContent || '');
}
async autoLogin(): Promise<void> {
page.type('#user-name', 'standard_user');
await page.type('#password', 'secret_sauce');
await page.click('#login-button');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment