1111import { inject , injectable } from 'inversify' ;
1212import { CLASSES } from '../../configs/inversify.types' ;
1313import { DriverHelper } from '../../utils/DriverHelper' ;
14- import { By , Key } from 'selenium-webdriver' ;
14+ import { By , Key , WebElement } from 'selenium-webdriver' ;
1515import { Logger } from '../../utils/Logger' ;
1616import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS' ;
1717import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS' ;
@@ -24,6 +24,8 @@ export class CreateWorkspace {
2424 private static readonly GIT_BRANCH_NAME : By = By . xpath ( '//input[@aria-label="Git Branch"]' ) ;
2525 private static readonly PATH_TO_DEVFILE : By = By . xpath ( '//input[@aria-label="Path to Devfile"]' ) ;
2626 private static readonly CREATE_AND_OPEN_BUTTON : By = By . xpath ( '//button[@id="create-and-open-button"]' ) ;
27+ private static readonly CREATE_NEW_WORKPACE_CHECKBOX : By = By . xpath ( '//label[@for="create-new-if-exist-switch"]' ) ;
28+ private static readonly CREATE_NEW_WORKPACE_CHECKBOX_VALUE : By = By . xpath ( '//input[@id="create-new-if-exist-switch"]' ) ;
2729
2830 constructor (
2931 @inject ( CLASSES . DriverHelper )
@@ -109,6 +111,40 @@ export class CreateWorkspace {
109111 }
110112 }
111113
114+ async isCreateNewWorkspaceCheckboxChecked ( timeout : number = TIMEOUT_CONSTANTS . TS_SELENIUM_WAIT_FOR_URL ) : Promise < boolean > {
115+ Logger . debug ( ) ;
116+
117+ const element : WebElement = await this . driverHelper . waitPresence ( CreateWorkspace . CREATE_NEW_WORKPACE_CHECKBOX_VALUE , timeout ) ;
118+ return await element . isSelected ( ) ;
119+ }
120+
121+ async clickOnCreateNewWorkspaceCheckbox ( timeout : number = TIMEOUT_CONSTANTS . TS_SELENIUM_WAIT_FOR_URL ) : Promise < void > {
122+ Logger . debug ( ) ;
123+
124+ await this . driverHelper . waitAndClick ( CreateWorkspace . CREATE_NEW_WORKPACE_CHECKBOX , timeout ) ;
125+ }
126+
127+ async setCreateNewWorkspaceCheckbox (
128+ checked : boolean = true ,
129+ timeout : number = TIMEOUT_CONSTANTS . TS_SELENIUM_WAIT_FOR_URL
130+ ) : Promise < void > {
131+ Logger . debug ( `checked: ${ checked } ` ) ;
132+
133+ // check current state
134+ const isCurrentlyChecked : boolean = await this . isCreateNewWorkspaceCheckboxChecked ( timeout ) ;
135+
136+ // if already in desired state, do nothing
137+ if ( isCurrentlyChecked === checked ) {
138+ Logger . debug ( `Checkbox is already ${ checked ? 'set' : 'unset' } , no action needed` ) ;
139+ return ;
140+ }
141+
142+ // click to change state
143+ Logger . debug ( `Checkbox is ${ isCurrentlyChecked ? 'set' : 'unset' } , ${ checked ? 'setting' : 'unsetting' } it now` ) ;
144+ await this . driverHelper . waitAndClick ( CreateWorkspace . CREATE_NEW_WORKPACE_CHECKBOX , timeout ) ;
145+ await this . driverHelper . wait ( 1000 ) ;
146+ }
147+
112148 private getEditorsDropdownListLocator ( sampleName : string ) : By {
113149 return By . xpath ( `//div[text()=\'${ sampleName } \']//parent::article//button` ) ;
114150 }
0 commit comments