import { browser , by , element , ElementFinder } from 'protractor' ; import { By , ILocation , promise } from 'selenium-webdriver' ; export abstract class AppPage { abstract getPath ( ) ; navigateTo ( ) { return browser . get ( this . getPath ( ) ) as promise . Promise < any > ; } scrollToElement ( elm ) { return elm . getLocation ( ) . then ( ( loc ) => { return browser . driver . executeScript ( 'window.scrollTo(0,arguments[0]);' , loc . y ) ; } ) ; } protected triggerAButton ( selector ) { return element ( selector ) . click ( ) ; } protected getOffsetTop ( selector ) { return browser . driver . executeScript ( 'return (arguments[0].offsetTop);' , element ( selector ) . getWebElement ( ) ) ; } protected getScrollTop ( selector ) { return browser . driver . executeScript ( 'return (arguments[0].scrollTop);' , element ( selector ) . getWebElement ( ) ) ; } protected getScrollHeight ( selector ) { return browser . driver . executeScript ( 'return (arguments[0].scrollHeight);' , element ( selector ) . getWebElement ( ) ) ; } protected getVerticalPosition ( selector ) { return element ( selector ) . getLocation ( ) . then ( ( headingLocation ) => { return headingLocation . y ; } ) ; } getScrollPos ( ) { return browser . driver . executeScript ( 'return Math.round(window.pageYOffset);' ) ; } scrollTo ( scrollPos ) { return browser . driver . executeScript ( 'window.scrollTo(0,arguments[0]);' , scrollPos ) ; } getBodyScrollHeight ( ) { return this . getScrollHeight ( by . css ( 'body' ) ) ; } getWindowInnerHeight ( ) { return browser . driver . executeScript ( 'return window.innerHeight;' ) ; } getSnackBarText ( ) { const snackbar = element ( by . css ( 'simple-snack-bar' ) ) ; return snackbar . getText ( ) ; } closeSnackBar ( ) { const snackbar = element ( by . css ( 'simple-snack-bar' ) ) ; const snackbarButton = snackbar . element ( by . css ( 'button' ) ) ; return snackbarButton . click ( ) ; } }