import { browser , by , ElementFinder } from 'protractor' ; import { BrowserActions , BrowserVisibility , Logger } from '@alfresco/adf-testing' ; import { APP_ROUTES , USE_HASH_STRATEGY } from './../configs' ; import { Utils , waitElement , waitForPresence , isPresentAndDisplayed } from '../utilities/utils' ; import { Header } from '../components' ; export abstract class Page { appRoot = 'app-root' ; layout = this . byCss ( 'app-layout' ) ; overlay = this . byCss ( '.cdk-overlay-container' ) ; snackBar = this . byCss ( '.mat-simple-snackbar-action button' ) ; dialogContainer = this . byCss ( '.mat-dialog-container' ) ; snackBarContainer = this . byCss ( '.mat-snack-bar-container' ) ; snackBarAction = this . byCss ( '.mat-simple-snackbar-action button' ) ; genericError = this . byCss ( 'aca-generic-error' ) ; genericErrorIcon = this . byCss ( 'aca-generic-error .mat-icon' ) ; genericErrorTitle = this . byCss ( '.generic-error__title' ) ; uploadDialog = this . byCss ( '.adf-upload-dialog' ) ; closeUploadButton = this . byCss ( '.adf-upload-dialog [id="adf-upload-dialog-close"]' ) ; constructor ( public url = '' ) { } protected byCss ( css ) { return browser . element ( by . css ( css ) ) ; } async load ( relativeUrl = '' ) { const hash = USE_HASH_STRATEGY ? '#' : '' ; const path = `${ browser . baseUrl }${ hash }${ this . url }${ relativeUrl }` ; return browser . get ( path ) ; } async waitForApp ( ) { await waitForPresence ( this . layout ) ; } async signOut ( ) { await new Header ( ) . openMoreMenu ( ) ; await new Header ( ) . menu . clickMenuItem ( 'Sign out' ) ; await BrowserVisibility . waitUntilElementIsPresent ( browser . element ( by . css ( '[class*="login-content"] input#username' ) ) ) ; } async waitForDialog ( ) { await BrowserVisibility . waitUntilElementIsVisible ( this . dialogContainer ) ; } async isDialogOpen ( ) { return isPresentAndDisplayed ( this . dialogContainer ) ; } async closeOpenDialogs ( ) { while ( await this . isDialogOpen ( ) ) { await Utils . pressEscape ( ) ; } } async isUploadDialogOpen ( ) { return isPresentAndDisplayed ( this . uploadDialog ) ; } async closeUploadDialog ( ) { if ( await this . isUploadDialogOpen ( ) ) { await BrowserActions . click ( this . closeUploadButton ) ; } } async refresh ( ) { await browser . refresh ( ) ; await this . waitForApp ( ) ; } async getSnackBarMessage ( ) { const elem = await waitElement ( '.mat-snack-bar-container' ) ; const attributeValue = await browser . executeScript ( `return arguments[0].innerText` , elem ) ; return attributeValue || '' ; } async clickSnackBarAction ( ) { try { const action = await waitElement ( '.mat-simple-snackbar-action button' ) ; await action . click ( ) ; } catch ( e ) { Logger . error ( e , '.......failed on click snack bar action.........' ) ; } } async isLoggedIn ( ) { const url = await browser . driver . getCurrentUrl ( ) ; return ! url . includes ( APP_ROUTES . LOGIN ) ; } }