import { injectable , inject } from 'inversify' ; import { CLASSES } from '../../inversify.types' ; import { DriverHelper } from '../../utils/DriverHelper' ; import { By , error } from 'selenium-webdriver' ; import { Logger } from '../../utils/Logger' ; import { QuickOpenContainer } from './QuickOpenContainer' ; import { TimeoutConstants } from '../../TimeoutConstants' ; import { AnimationChecker } from '../../utils/AnimationChecker' ; /*********************************************************************
 * Copyright (c) 2019 Red Hat, Inc.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 **********************************************************************/ @ injectable ( ) export class TopMenu { private static readonly TOP_MENU_BUTTONS : string [ ] = [ 'File' , 'Edit' , 'Selection' , 'View' , 'Go' , 'Run' , 'Terminal' , 'Help' ] ; constructor ( @ inject ( CLASSES . DriverHelper ) private readonly driverHelper , @ inject ( CLASSES . QuickOpenContainer ) private readonly quickOpenContainer , @ inject ( CLASSES . AnimationChecker ) private readonly animationChecker ) { } public async waitTopMenu ( timeout = TimeoutConstants . TS_SELENIUM_TOOLBAR_TIMEOUT ) { Logger . debug ( 'TopMenu.waitTopMenu' ) ; for ( const buttonText of TopMenu . TOP_MENU_BUTTONS ) { const buttonLocator = this . getTopMenuButtonLocator ( buttonText ) ; await this . driverHelper . waitVisibility ( buttonLocator , timeout ) ; } } public async selectOption ( topMenuButtonText , submenuItemtext ) { Logger . debug ( `TopMenu.selectOption "${ topMenuButtonText }"` ) ; await this . clickOnTopMenuButton ( topMenuButtonText ) ; await this . clickOnSubmenuItem ( submenuItemtext ) ; } public async clickOnTopMenuButton ( buttonText , timeout = TimeoutConstants . TS_SELENIUM_CLICK_ON_VISIBLE_ITEM ) { Logger . debug ( `TopMenu.clickOnTopMenuButton "${ buttonText }"` ) ; const buttonLocator = this . getTopMenuButtonLocator ( buttonText ) ; await this . driverHelper . waitAndClick ( buttonLocator , timeout ) ; } public async clickOnSubmenuItem ( itemText , timeout = TimeoutConstants . TS_SELENIUM_CLICK_ON_VISIBLE_ITEM ) { Logger . debug ( `TopMenu.clickOnSubmenuItem "${ itemText }"` ) ; const submenuItemLocator = this . getSubmenuItemLocator ( itemText ) ; await this . animationChecker . waitDropDownAnimationEnd ( ) ; await this . driverHelper . waitAndClick ( submenuItemLocator , timeout ) ; } public async runTask ( task ) { await this . selectOption ( 'Terminal' , 'Run Task...' ) ; try { await this . quickOpenContainer . waitContainer ( ) ; } catch ( err ) { if ( err instanceof error . TimeoutError ) { console . log ( `After clicking to the "Terminal" -> "Run Task ..." the "Quick Open Container" has not been displayed, one more try` ) ; await this . selectOption ( 'Terminal' , 'Run Task...' ) ; await this . quickOpenContainer . waitContainer ( ) ; } } await this . quickOpenContainer . clickOnContainerItem ( task ) ; } public async openTerminalForSpecificContainer ( containerName ) { await this . selectOption ( 'Terminal' , 'Open Terminal in specific container' ) ; try { await this . quickOpenContainer . waitContainer ( ) ; } catch ( err ) { if ( err instanceof error . TimeoutError ) { Logger . info ( `After clicking to the "Terminal" -> "Open Terminal in specific container" the "Quick Open Container" has not been displayed, one more try` ) ; await this . selectOption ( 'Terminal' , 'Open Terminal in specific container' ) ; await this . quickOpenContainer . waitContainer ( ) ; } } await this . quickOpenContainer . clickOnContainerItem ( containerName ) ; } private getTopMenuButtonLocator ( buttonText ) { return By . xpath ( `//div[@id='theia:menubar']//div[@class='p-MenuBar-itemLabel' and text()='${ buttonText }']` ) ; } private getSubmenuItemLocator ( submenuItemtext ) { return By . xpath ( `//ul[@class='p-Menu-content']//li[@data-type='command']//div[text()='${ submenuItemtext }']` ) ; } }