import { ElementHandle , Page } from 'puppeteer' ; export abstract class Base { protected static readonly DEFAULT_LOCATE_TIMEOUT = 20000 ; protected static readonly DEFAULT_PAGE_LOAD_TIMEOUT = 60000 ; protected readonly page : Page ; constructor ( page ) { this . page = page ; } param baseUrl param path protected async goto ( { baseUrl , path } ) { const fullPath = path ? `${ baseUrl }/${ path }` : baseUrl ; await this . page . goto ( fullPath , { waitUntil : 'load' , timeout : 60000 } ) ; } param element param elementName protected async getText ( element , elementName ) { const text = await element . evaluate ( ( el ) => el . textContent ) ; if ( ! text ) { throw new Error ( `${ elementName } does not contain any text` ) ; } return text ; } param selector param elementName param timeout protected async elementVisible ( seletor , elementName , timeout = Base . DEFAULT_LOCATE_TIMEOUT ) { const waitOptions = { timeout } ; const element = seletor . startsWith ( '//' ) ? await this . page . waitForXPath ( seletor , waitOptions ) : await this . page . waitForSelector ( seletor , waitOptions ) ; if ( ! element ) { throw new Error ( `Element: ${ elementName } is not visible in the UI` ) ; } return element ; } }