Created
June 19, 2021 08:27
-
-
Save hoangsetup/af2a890f867e2b6fbfdb7522fc580788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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