github.com/argoproj/argo-cd/v3@v3.2.1/ui-test/src/application-create-panel/application-create-panel.ts (about) 1 import {By, until, WebDriver} from 'selenium-webdriver'; 2 import {Base} from '../base'; 3 import UiTestUtilities from '../UiTestUtilities'; 4 import * as Const from '../Constants'; 5 6 const CREATE_APPLICATION_BUTTON_CREATE: By = By.xpath('.//button[@qe-id="applications-list-button-create"]'); 7 const CREATE_APPLICATION_BUTTON_CANCEL: By = By.xpath('.//button[@qe-id="applications-list-button-cancel"]'); 8 9 const CREATE_APPLICATION_FIELD_APP_NAME: By = By.xpath('.//input[@qeid="application-create-field-app-name"]'); 10 const CREATE_APPLICATION_FIELD_PROJECT: By = By.xpath('.//input[@qe-id="application-create-field-project"]'); 11 const CREATE_APPLICATION_FIELD_REPOSITORY_URL: By = By.xpath('.//input[@qe-id="application-create-field-repository-url"]'); 12 const CREATE_APPLICATION_FIELD_REPOSITORY_PATH: By = By.xpath('.//input[@qe-id="application-create-field-path"]'); 13 14 const CREATE_APPLICATION_DROPDOWN_DESTINATION: By = By.xpath('.//div[@qe-id="application-create-dropdown-destination"]'); 15 const CREATE_APPLICATION_DROPDOWN_MENU_URL: By = By.xpath('.//li[@qe-id="application-create-dropdown-destination-URL"]'); 16 const CREATE_APPLICATION_DROPDOWN_MENU_NAME: By = By.xpath('.//li[@qe-id="application-create-dropdown-destination-NAME"]'); 17 18 export const DESTINATION_MENU_NAME: string = 'NAME'; 19 export const DESTINATION_MENU_URL: string = 'URL'; 20 21 const CREATE_APPLICATION_FIELD_CLUSTER_NAME: By = By.xpath('.//input[@qe-id="application-create-field-cluster-name"]'); 22 const CREATE_APPLICATION_FIELD_CLUSTER_NAMESPACE: By = By.xpath('.//input[@qeid="application-create-field-namespace"]'); 23 const CREATE_APPLICATION_FIELD_CLUSTER_URL: By = By.xpath('.//input[@qe-id="application-create-field-cluster-url"]'); 24 25 export class ApplicationCreatePanel extends Base { 26 public constructor(driver: WebDriver) { 27 super(driver); 28 } 29 30 public async setAppName(appName: string): Promise<void> { 31 try { 32 const appNameField = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_APP_NAME); 33 await appNameField.sendKeys(appName); 34 } catch (err: any) { 35 UiTestUtilities.log('Error caught while setting app name: ' + err); 36 throw new Error(err); 37 } 38 } 39 40 public async setProjectName(projectName: string): Promise<void> { 41 try { 42 const project = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_PROJECT); 43 await project.sendKeys(projectName); 44 } catch (err: any) { 45 UiTestUtilities.log('Error caught while setting project name: ' + err); 46 throw new Error(err); 47 } 48 } 49 50 public async setSourceRepoUrl(sourceRepoUrl: string): Promise<void> { 51 try { 52 const reposUrl = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_REPOSITORY_URL); 53 await reposUrl.sendKeys(sourceRepoUrl); 54 } catch (err: any) { 55 UiTestUtilities.log('Error caught while setting source repo URL: ' + err); 56 throw new Error(err); 57 } 58 } 59 60 public async setSourceRepoPath(sourceRepoPath: string): Promise<void> { 61 try { 62 const path = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_REPOSITORY_PATH); 63 await path.sendKeys(sourceRepoPath); 64 } catch (err: any) { 65 UiTestUtilities.log('Error caught while setting source repo path: ' + err); 66 throw new Error(err); 67 } 68 } 69 70 /** 71 * Convenience method to select the Destination Cluster URL menu and set the url field with destinationClusterFieldValue 72 * 73 * @param destinationClusterFieldValue 74 */ 75 public async selectDestinationClusterURLMenu(destinationClusterFieldValue: string): Promise<void> { 76 try { 77 const clusterCombo = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_DESTINATION); 78 // click() doesn't work. Use script 79 await UiTestUtilities.click(this.driver, clusterCombo); 80 const urlMenu = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_MENU_URL); 81 await urlMenu.click(); 82 if (destinationClusterFieldValue) { 83 await this.setDestinationClusterUrl(destinationClusterFieldValue); 84 } 85 } catch (err: any) { 86 UiTestUtilities.log('Error caught while selecting destination cluster URL menu: ' + err); 87 throw new Error(err); 88 } 89 } 90 91 /** 92 * Convenience method to select the Destination Cluster Name menu and set the namefield with destinationClusterFieldValue 93 * 94 * @param destinationClusterFieldValue 95 */ 96 public async selectDestinationClusterNameMenu(destinationClusterFieldValue: string): Promise<void> { 97 try { 98 const clusterCombo = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_DESTINATION); 99 // click() doesn't work. Use script 100 await UiTestUtilities.click(this.driver, clusterCombo); 101 const nameMenu = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_MENU_NAME); 102 await UiTestUtilities.click(this.driver, nameMenu); 103 if (destinationClusterFieldValue) { 104 await this.setDestinationClusterName(destinationClusterFieldValue); 105 } 106 } catch (err: any) { 107 UiTestUtilities.log('Error caught while selecting destination cluster name menu: ' + err); 108 throw new Error(err); 109 } 110 } 111 112 public async setDestinationClusterName(destinationClusterName: string): Promise<void> { 113 try { 114 const clusterName = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_NAME); 115 await clusterName.sendKeys(destinationClusterName); 116 // await clusterName.sendKeys('\r'); 117 } catch (err: any) { 118 UiTestUtilities.log('Error caught while setting destination cluster name: ' + err); 119 throw new Error(err); 120 } 121 } 122 123 public async setDestinationClusterUrl(destinationClusterUrl: string): Promise<void> { 124 try { 125 const clusterUrl = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_URL); 126 await clusterUrl.sendKeys(destinationClusterUrl); 127 } catch (err: any) { 128 UiTestUtilities.log('Error caught while setting destination cluster URL: ' + err); 129 throw new Error(err); 130 } 131 } 132 133 public async setDestinationNamespace(destinationNamespace: string): Promise<void> { 134 try { 135 const namespace = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_NAMESPACE); 136 await namespace.sendKeys(destinationNamespace); 137 } catch (err: any) { 138 UiTestUtilities.log('Error caught while setting destination namespace: ' + err); 139 throw new Error(err); 140 } 141 } 142 143 /** 144 * Click the Create button to create the app 145 */ 146 public async clickCreateButton(): Promise<void> { 147 try { 148 const createButton = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_BUTTON_CREATE); 149 await createButton.click(); 150 151 // Wait until the Create Application Sliding Panel disappears 152 await this.driver.wait(until.elementIsNotVisible(createButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch((e) => { 153 UiTestUtilities.logError('The Create Application Sliding Panel did not disappear'); 154 throw e; 155 }); 156 await this.driver.sleep(1000); 157 } catch (err: any) { 158 UiTestUtilities.log('Error caught while clicking Create button: ' + err); 159 throw new Error(err); 160 } 161 } 162 163 /** 164 * Click the Cancel Button. Do not create the app. 165 */ 166 public async clickCancelButton(): Promise<void> { 167 try { 168 const cancelButton = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_BUTTON_CANCEL); 169 await cancelButton.click(); 170 171 // Wait until the Create Application Sliding Panel disappears 172 await this.driver.wait(until.elementIsNotVisible(cancelButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch((e) => { 173 UiTestUtilities.logError('The Create Application Sliding Panel did not disappear'); 174 throw e; 175 }); 176 } catch (err: any) { 177 UiTestUtilities.log('Error caught while clicking Cancel button: ' + err); 178 throw new Error(err); 179 } 180 } 181 182 /** 183 * Convenience method to create an application given the following inputs to the dialog 184 * 185 * TODO add Sync Policy and Sync Options and setter methods above 186 * 187 * @param appName 188 * @param projectName 189 * @param sourceRepoUrl 190 * @param sourceRepoPath 191 * @param destinationMenu 192 * @param destinationClusterName 193 * @param destinationNamespace 194 */ 195 public async createApplication( 196 appName: string, 197 projectName: string, 198 sourceRepoUrl: string, 199 sourceRepoPath: string, 200 destinationClusterName: string, 201 destinationNamespace: string 202 ): Promise<void> { 203 UiTestUtilities.log('About to create application'); 204 try { 205 await this.setAppName(appName); 206 await this.setProjectName(projectName); 207 await this.setSourceRepoUrl(sourceRepoUrl); 208 await this.setSourceRepoPath(sourceRepoPath); 209 await this.selectDestinationClusterNameMenu(destinationClusterName); 210 await this.setDestinationNamespace(destinationNamespace); 211 await this.clickCreateButton(); 212 } catch (err: any) { 213 throw new Error(err); 214 } 215 } 216 }