import { browser , ExpectedConditions } from 'protractor' ; import * as mixins from '../mixins' ; import * as support from '../support' ; export enum PageOpenMode { AlreadyOpened , RefreshBrowser } export abstract class BasePage { name : string = '...' ; log ! : ( action : string , ... msg : string [ ] ) => void ; debug ! : ( context : string , ... msg : string [ ] ) => void ; protected url : string | undefined ; constructor ( url ? ) { this . url = url ; this . debug ( `url: '${ url }'` ) ; } async ready ( ) { } async open ( mode = PageOpenMode . AlreadyOpened ) { if ( mode === PageOpenMode . RefreshBrowser ) { await this . openInBrowser ( ) ; } await this . ready ( ) ; this . log ( 'Opened' ) ; return this ; } async openInBrowser ( ) { if ( this . url === undefined ) { throw Error ( 'Trying to open an undefined url' ) ; } this . log ( 'Authenticating with Auth and Refresh token' ) ; await support . loginWithTokens ( ) ; this . log ( 'Opening' , this . url ) ; let currentUrl = await browser . getCurrentUrl ( ) ; this . debug ( 'at  :' , currentUrl ) ; this . debug ( `goto: '${ this . url }'` ) ; await browser . get ( this . url ) ; let urlNow = await browser . getCurrentUrl ( ) ; this . debug ( 'now :' , urlNow ) ; await this . waitUntilUrlContains ( 'typegroup' ) ; await this . waitUntilTitleContains ( 'Plan' ) ; } async waitUntilUrlContains ( text , timeout ? ) { await browser . wait ( ExpectedConditions . urlContains ( text ) , timeout ) ; } async waitUntilTitleContains ( title ) { await browser . wait ( ExpectedConditions . titleContains ( 'Plan' ) ) ; } } mixins . applyMixins ( BasePage , [ mixins . Logging ] ) ;