|
| 1 | +/* |
| 2 | + * Copyright © 2023 Cask Data, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package io.cdap.e2e.pages.actions; |
| 17 | + |
| 18 | +import io.cdap.e2e.pages.locators.CdfNameSpaceAdminLocators; |
| 19 | +import io.cdap.e2e.utils.AssertionHelper; |
| 20 | +import io.cdap.e2e.utils.ConstantsUtil; |
| 21 | +import io.cdap.e2e.utils.ElementHelper; |
| 22 | +import io.cdap.e2e.utils.JsonUtils; |
| 23 | +import io.cdap.e2e.utils.PluginPropertyUtils; |
| 24 | +import io.cdap.e2e.utils.SeleniumHelper; |
| 25 | +import io.cdap.e2e.utils.WaitHelper; |
| 26 | +import org.slf4j.Logger; |
| 27 | +import org.slf4j.LoggerFactory; |
| 28 | +import java.util.Map; |
| 29 | + |
| 30 | +/** |
| 31 | + * Represents CdfNameSpaceAdminActions |
| 32 | + */ |
| 33 | +public class CdfNameSpaceAdminActions { |
| 34 | + |
| 35 | + private static final Logger logger = LoggerFactory.getLogger(CdfNameSpaceAdminActions.class); |
| 36 | + public static CdfNameSpaceAdminLocators cdfNameSpaceAdminLocators; |
| 37 | + |
| 38 | + static { |
| 39 | + cdfNameSpaceAdminLocators = SeleniumHelper.getPropertiesLocators( |
| 40 | + CdfNameSpaceAdminLocators.class); |
| 41 | + } |
| 42 | + |
| 43 | + public static void clickOnNameSpaceAdminTabs(String tabName, String nameSpaceName) { |
| 44 | + ElementHelper.clickOnElement( |
| 45 | + CdfNameSpaceAdminLocators.nameSpaceModules(tabName, nameSpaceName)); |
| 46 | + } |
| 47 | + |
| 48 | + public static void openNamespaceAdminPage() { |
| 49 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.namespaceAdminMenu); |
| 50 | + } |
| 51 | + |
| 52 | + public static void clickOnHamburgerMenu() { |
| 53 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.hamburgerMenu); |
| 54 | + } |
| 55 | + |
| 56 | + public static void clickOnEditPreference() { |
| 57 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.editPreferencesButton); |
| 58 | + } |
| 59 | + |
| 60 | + public static void switchToNameSpace(String nameSpaceName) { |
| 61 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.switchNameSpace(nameSpaceName)); |
| 62 | + } |
| 63 | + |
| 64 | + public static void createProfileForNamespace(String nameSpaceName) { |
| 65 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.createProfile(nameSpaceName)); |
| 66 | + } |
| 67 | + |
| 68 | + public static void openNamespaceDropdown() { |
| 69 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.namespaceDropdown); |
| 70 | + } |
| 71 | + |
| 72 | + public static void addNamespaceFromHamburgerMenu() { |
| 73 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.addNamespace); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Click on Save and Close button to save preference |
| 78 | + */ |
| 79 | + public static void clickOnSavePreference() { |
| 80 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.clickSaveClose); |
| 81 | + } |
| 82 | + |
| 83 | + public static void selectHamburgerMenuList(String listName) { |
| 84 | + String pluginPropertyDataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute( |
| 85 | + listName); |
| 86 | + if (pluginPropertyDataCyAttribute == null) { |
| 87 | + pluginPropertyDataCyAttribute = listName; |
| 88 | + } |
| 89 | + ElementHelper.clickOnElement( |
| 90 | + CdfNameSpaceAdminLocators.locateMenuLink(pluginPropertyDataCyAttribute)); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Enter KeyValue Pairs For Preference Property |
| 95 | + * |
| 96 | + * @param preferenceProperty @data-cy attribute value of preference Property. If |
| 97 | + * preferenceProperty is present in |
| 98 | + * {@link ConstantsUtil#DEFAULT_DATACY_ATTRIBUTES_FILE} then its data-cy |
| 99 | + * is fetched from it else preferenceProperty is used as it is. |
| 100 | + * @param keyValuePair Actual json KeyValue Pairs string is fetched from |
| 101 | + * {@link ConstantsUtil#DEFAULT_PLUGIN_PROPERTIES_FILE} with |
| 102 | + * keyValuePair as key |
| 103 | + */ |
| 104 | + public static void enterKeyValuePreferences(String preferenceProperty, String keyValuePair) { |
| 105 | + String pluginPropertyDataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute( |
| 106 | + preferenceProperty); |
| 107 | + if (pluginPropertyDataCyAttribute == null) { |
| 108 | + pluginPropertyDataCyAttribute = preferenceProperty; |
| 109 | + } |
| 110 | + Map<String, String> properties = |
| 111 | + JsonUtils.convertKeyValueJsonArrayToMap(PluginPropertyUtils.pluginProp(keyValuePair)); |
| 112 | + int index = 0; |
| 113 | + for (Map.Entry<String, String> entry : properties.entrySet()) { |
| 114 | + if (index != 0) { |
| 115 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.locateAddRowButtonProperty( |
| 116 | + pluginPropertyDataCyAttribute, index - 1)); |
| 117 | + } |
| 118 | + ElementHelper.sendKeys(CdfNameSpaceAdminLocators.locateKeyProperty( |
| 119 | + pluginPropertyDataCyAttribute, index), entry.getKey()); |
| 120 | + ElementHelper.sendKeys(CdfNameSpaceAdminLocators.locateValueProperty( |
| 121 | + pluginPropertyDataCyAttribute, index), entry.getValue()); |
| 122 | + index++; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Select on the type of Provisioner from list for Compute Profile in system admin |
| 128 | + * |
| 129 | + * @param provisionerName @data-cy attribute value of Provisioner. If Provisioner is present in |
| 130 | + * {@link ConstantsUtil#DEFAULT_DATACY_ATTRIBUTES_FILE} then its data-cy is |
| 131 | + * fetched from it else Provisioner is used as it is. |
| 132 | + */ |
| 133 | + public static void selectProvisioner(String provisionerName) { |
| 134 | + String pluginPropertyDataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute( |
| 135 | + provisionerName); |
| 136 | + if (pluginPropertyDataCyAttribute == null) { |
| 137 | + pluginPropertyDataCyAttribute = provisionerName; |
| 138 | + } |
| 139 | + ElementHelper.clickOnElement( |
| 140 | + CdfNameSpaceAdminLocators.locateProvisionerInList(pluginPropertyDataCyAttribute)); |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Click on the Close button in compute profile properties page |
| 145 | + */ |
| 146 | + public static void clickCloseButton() { |
| 147 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.closeButton); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Click on Delete to delete preference |
| 152 | + */ |
| 153 | + public static void deletePreference() { |
| 154 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.clickDelete); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Click on Reset button to reset preference |
| 159 | + */ |
| 160 | + public static void clickOnResetPreference() { |
| 161 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.clickReset); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Verify if the added Preferences reset is successful |
| 166 | + */ |
| 167 | + public static void verifyIfResetValidatedSuccessfully() { |
| 168 | + WaitHelper.waitForElementToBeDisplayed(CdfNameSpaceAdminLocators.resetSuccessMsg); |
| 169 | + String expectedMessage = PluginPropertyUtils.errorProp( |
| 170 | + ConstantsUtil.RESET_VALIDATION_SUCCESS_MESSAGE); |
| 171 | + AssertionHelper.verifyElementContainsText( |
| 172 | + CdfNameSpaceAdminLocators.resetSuccessMsg, expectedMessage); |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * Click on type of button to create Compute Profile in system admin |
| 177 | + * |
| 178 | + * @param buttonType @data-cy attribute value of button. If type of action is present in |
| 179 | + * {@link ConstantsUtil#DEFAULT_DATACY_ATTRIBUTES_FILE} then its data-cy is |
| 180 | + * fetched from it else type of action is used as it is. |
| 181 | + */ |
| 182 | + public static void clickCreateButtonComputeProfile(String buttonType) { |
| 183 | + String pluginPropertyDataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute( |
| 184 | + buttonType); |
| 185 | + if (pluginPropertyDataCyAttribute == null) { |
| 186 | + pluginPropertyDataCyAttribute = buttonType; |
| 187 | + } |
| 188 | + ElementHelper.clickOnElement( |
| 189 | + CdfNameSpaceAdminLocators.locateButtonType(pluginPropertyDataCyAttribute)); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * Verify Error message displayed on the footer/at the bottom of Compute Profile Properties page |
| 194 | + * using the Error message location in the .properties file |
| 195 | + * {@link ConstantsUtil#DEFAULT_ERROR_PROPERTIES_FILE} |
| 196 | + * |
| 197 | + * @param errorMessageLocation Expected error message location |
| 198 | + */ |
| 199 | + public static void verifyErrorMessageOnFooter(String errorMessageLocation) { |
| 200 | + String expectedErrorMessage = PluginPropertyUtils.errorProp(errorMessageLocation); |
| 201 | + AssertionHelper.verifyElementContainsText(CdfNameSpaceAdminLocators.errorMessageOnFooter, |
| 202 | + expectedErrorMessage); |
| 203 | + } |
| 204 | + |
| 205 | + /** |
| 206 | + * Enter NamespaceName value in Add namespace |
| 207 | + * |
| 208 | + * @param value If value is present in {@link ConstantsUtil#DEFAULT_PLUGIN_PROPERTIES_FILE} as a |
| 209 | + * key then its value is fetched from it else value is entered in the input as it |
| 210 | + * is. |
| 211 | + */ |
| 212 | + public static void enterNamespaceName(String value) { |
| 213 | + ElementHelper.sendKeys(CdfNameSpaceAdminLocators.namespaceName, |
| 214 | + PluginPropertyUtils.pluginProp(value)); |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * Enter NamespaceDescription value in Add namespace |
| 219 | + * |
| 220 | + * @param value If value is present in {@link ConstantsUtil#DEFAULT_PLUGIN_PROPERTIES_FILE} as a |
| 221 | + * key then its value is fetched from it else value is entered in the input as it |
| 222 | + * is. |
| 223 | + */ |
| 224 | + public static void enterNamespaceDescription(String value) { |
| 225 | + ElementHelper.sendKeys(CdfNameSpaceAdminLocators.namespaceDescription, |
| 226 | + PluginPropertyUtils.pluginProp(value)); |
| 227 | + } |
| 228 | + |
| 229 | + /** |
| 230 | + * Verify Error message displayed on the dialog box using the Error message location in the |
| 231 | + * .properties file {@link ConstantsUtil#DEFAULT_ERROR_PROPERTIES_FILE} |
| 232 | + * |
| 233 | + * @param errorMessageLocation Expected error message location |
| 234 | + */ |
| 235 | + public static void verifyFailedErrorMessageOnDialogBox(String errorMessageLocation) { |
| 236 | + String expectedErrorMessage = PluginPropertyUtils.errorProp(errorMessageLocation); |
| 237 | + AssertionHelper.verifyElementContainsText(CdfNameSpaceAdminLocators.failMessage, |
| 238 | + expectedErrorMessage); |
| 239 | + } |
| 240 | + |
| 241 | + public static void switchToNewNameSpace() { |
| 242 | + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.switchToNameSpaceButton); |
| 243 | + } |
| 244 | + |
| 245 | + public static void verifySwitchToNewNamespace(String value) { |
| 246 | + String expectedNameSpace = PluginPropertyUtils.pluginProp(value); |
| 247 | + AssertionHelper.verifyElementContainsText(CdfNameSpaceAdminLocators.namespaceText, |
| 248 | + expectedNameSpace); |
| 249 | + } |
| 250 | + |
| 251 | + public static void verifyElementIsDisplayed() { |
| 252 | + ElementHelper.isElementDisplayed(CdfNameSpaceAdminLocators.pageHeaderNameSpaceAdmin); |
| 253 | + } |
| 254 | + |
| 255 | + /** |
| 256 | + * Check whether Create Profile Properties Page is loaded |
| 257 | + */ |
| 258 | + public static void verifyCreateProfilePageLoaded() { |
| 259 | + WaitHelper.waitForElementToBeOptionallyDisplayed(CdfNameSpaceAdminLocators.profilePropertiesPage(), |
| 260 | + ConstantsUtil.DEFAULT_TIMEOUT_SECONDS); |
| 261 | + } |
| 262 | + |
| 263 | + /** |
| 264 | + * Check whether Profile created is present in System Compute Profile tab |
| 265 | + * |
| 266 | + * @param profileTitle any specific title created |
| 267 | + */ |
| 268 | + public static void verifyProvisionerPresentComputeProfile(String profileTitle) { |
| 269 | + WaitHelper.waitForElementToBeOptionallyDisplayed(CdfNameSpaceAdminLocators. |
| 270 | + locateProfileTitle(PluginPropertyUtils.pluginProp(profileTitle)), |
| 271 | + ConstantsUtil.DEFAULT_TIMEOUT_SECONDS); |
| 272 | + } |
| 273 | +} |
0 commit comments