github.com/argoproj/argo-cd/v2@v2.10.9/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) { 35 throw new Error(err); 36 } 37 } 38 39 public async setProjectName(projectName: string): Promise<void> { 40 try { 41 const project = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_PROJECT); 42 await project.sendKeys(projectName); 43 } catch (err) { 44 throw new Error(err); 45 } 46 } 47 48 public async setSourceRepoUrl(sourceRepoUrl: string): Promise<void> { 49 try { 50 const reposUrl = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_REPOSITORY_URL); 51 await reposUrl.sendKeys(sourceRepoUrl); 52 } catch (err) { 53 throw new Error(err); 54 } 55 } 56 57 public async setSourceRepoPath(sourceRepoPath: string): Promise<void> { 58 try { 59 const path = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_REPOSITORY_PATH); 60 await path.sendKeys(sourceRepoPath); 61 } catch (err) { 62 throw new Error(err); 63 } 64 } 65 66 /** 67 * Convenience method to select the Destination Cluster URL menu and set the url field with destinationClusterFieldValue 68 * 69 * @param destinationClusterFieldValue 70 */ 71 public async selectDestinationClusterURLMenu(destinationClusterFieldValue: string): Promise<void> { 72 try { 73 const clusterCombo = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_DESTINATION); 74 // click() doesn't work. Use script 75 await UiTestUtilities.click(this.driver, clusterCombo); 76 const urlMenu = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_MENU_URL); 77 await urlMenu.click(); 78 if (destinationClusterFieldValue) { 79 await this.setDestinationClusterUrl(destinationClusterFieldValue); 80 } 81 } catch (err) { 82 throw new Error(err); 83 } 84 } 85 86 /** 87 * Convenience method to select the Destination Cluster Name menu and set the namefield with destinationClusterFieldValue 88 * 89 * @param destinationClusterFieldValue 90 */ 91 public async selectDestinationClusterNameMenu(destinationClusterFieldValue: string): Promise<void> { 92 try { 93 const clusterCombo = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_DESTINATION); 94 // click() doesn't work. Use script 95 await UiTestUtilities.click(this.driver, clusterCombo); 96 const nameMenu = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_DROPDOWN_MENU_NAME); 97 await UiTestUtilities.click(this.driver, nameMenu); 98 if (destinationClusterFieldValue) { 99 await this.setDestinationClusterName(destinationClusterFieldValue); 100 } 101 } catch (err) { 102 throw new Error(err); 103 } 104 } 105 106 public async setDestinationClusterName(destinationClusterName: string): Promise<void> { 107 try { 108 const clusterName = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_NAME); 109 await clusterName.sendKeys(destinationClusterName); 110 // await clusterName.sendKeys('\r'); 111 } catch (err) { 112 throw new Error(err); 113 } 114 } 115 116 public async setDestinationClusterUrl(destinationClusterUrl: string): Promise<void> { 117 try { 118 const clusterUrl = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_URL); 119 await clusterUrl.sendKeys(destinationClusterUrl); 120 } catch (err) { 121 throw new Error(err); 122 } 123 } 124 125 public async setDestinationNamespace(destinationNamespace: string): Promise<void> { 126 try { 127 const namespace = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_NAMESPACE); 128 await namespace.sendKeys(destinationNamespace); 129 } catch (err) { 130 throw new Error(err); 131 } 132 } 133 134 /** 135 * Click the Create button to create the app 136 */ 137 public async clickCreateButton(): Promise<void> { 138 try { 139 const createButton = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_BUTTON_CREATE); 140 await createButton.click(); 141 142 // Wait until the Create Application Sliding Panel disappears 143 await this.driver.wait(until.elementIsNotVisible(createButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch(e => { 144 UiTestUtilities.logError('The Create Application Sliding Panel did not disappear'); 145 throw e; 146 }); 147 await this.driver.sleep(1000); 148 } catch (err) { 149 throw new Error(err); 150 } 151 } 152 153 /** 154 * Click the Cancel Button. Do not create the app. 155 */ 156 public async clickCancelButton(): Promise<void> { 157 try { 158 const cancelButton = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_BUTTON_CANCEL); 159 await cancelButton.click(); 160 161 // Wait until the Create Application Sliding Panel disappears 162 await this.driver.wait(until.elementIsNotVisible(cancelButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch(e => { 163 UiTestUtilities.logError('The Create Application Sliding Panel did not disappear'); 164 throw e; 165 }); 166 } catch (err) { 167 throw new Error(err); 168 } 169 } 170 171 /** 172 * Convenience method to create an application given the following inputs to the dialog 173 * 174 * TODO add Sync Policy and Sync Options and setter methods above 175 * 176 * @param appName 177 * @param projectName 178 * @param sourceRepoUrl 179 * @param sourceRepoPath 180 * @param destinationMenu 181 * @param destinationClusterName 182 * @param destinationNamespace 183 */ 184 public async createApplication( 185 appName: string, 186 projectName: string, 187 sourceRepoUrl: string, 188 sourceRepoPath: string, 189 destinationClusterName: string, 190 destinationNamespace: string 191 ): Promise<void> { 192 UiTestUtilities.log('About to create application'); 193 try { 194 await this.setAppName(appName); 195 await this.setProjectName(projectName); 196 await this.setSourceRepoUrl(sourceRepoUrl); 197 await this.setSourceRepoPath(sourceRepoPath); 198 await this.selectDestinationClusterNameMenu(destinationClusterName); 199 await this.setDestinationNamespace(destinationNamespace); 200 await this.clickCreateButton(); 201 } catch (err) { 202 throw new Error(err); 203 } 204 } 205 }