import { WebElementPromise } from 'selenium-webdriver' ; import { WebComponent , Button , TextInput } from './' ; class WebComponentEnsurer { constructor ( private component ) { } public async textIs ( expected ) { const text = await this . component . getText ( ) ; if ( expected . trim ( ) !== text . trim ( ) ) { throw new Error ( `Element ${ this . component . selector } text is '${ text }'. Expected value is '${ expected }'` ) ; } } public async isVisible ( ) { if ( ! await this . component . isDisplayed ( ) ) { throw new Error ( `Element ${ this . component . selector } is visible` ) ; } } public async isNotVisible ( ) { if ( await this . component . isDisplayed ( ) ) { throw new Error ( `Element ${ this . component . selector } is visible` ) ; } } } class ButtonEnsurer extends WebComponentEnsurer { protected button : Button ; constructor ( button ) { super ( button ) ; this . button = button ; } public async isNotDisabled ( ) { if ( await this . button . isDisabled ( ) ) { throw new Error ( `Button ${ this . button . selector } is disabled` ) ; } } } class TextInputEnsurer extends WebComponentEnsurer { constructor ( element ) { super ( element ) ; } } export function ensure ( component ) ; export function ensure ( component ) ; export function ensure ( component ) ; export function ensure ( component ) { if ( component instanceof Button ) { return new ButtonEnsurer ( component ) ; } else if ( component instanceof WebComponent ) { return new WebComponentEnsurer ( component ) ; } }