import 'chromedriver' ; import { Builder , ThenableWebDriver , WebElement , By , WebElementPromise } from 'selenium-webdriver' ; import { Page , NewablePage , WebComponent , WaitCondition } from './' ; export class Browser { private driver : ThenableWebDriver ; public constructor ( private browserName ) { this . driver = new Builder ( ) . forBrowser ( browserName ) . build ( ) ; } public async navigate ( url ) { await this . driver . navigate ( ) . to ( url ) ; } public findElement ( selector ) { return this . driver . findElement ( By . css ( selector ) ) ; } public async clearCookies ( url ? ) { if ( url ) { const currentUrl = await this . driver . getCurrentUrl ( ) ; await this . navigate ( url ) ; await this . driver . manage ( ) . deleteAllCookies ( ) ; await this . navigate ( currentUrl ) ; } else { await this . driver . manage ( ) . deleteAllCookies ( ) ; } } public async wait ( condition ) { await this . waitAny ( condition ) ; } public async waitAny ( conditions ) { const all = ( ! ( conditions instanceof Array ) ) ? [ conditions ] : conditions ; await this . driver . wait ( async ( ) => { for ( const condition of all ) { try { if ( await condition ( this ) === true ) { return true ; } continue ; } catch ( ex ) { continue ; } } } ) ; } public async close ( ) { await this . driver . quit ( ) ; } }