diff --git a/src/main/java/io/cdap/e2e/pages/actions/CdfNameSpaceAdminActions.java b/src/main/java/io/cdap/e2e/pages/actions/CdfNameSpaceAdminActions.java new file mode 100644 index 000000000..75b511899 --- /dev/null +++ b/src/main/java/io/cdap/e2e/pages/actions/CdfNameSpaceAdminActions.java @@ -0,0 +1,119 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package io.cdap.e2e.pages.actions; + +import io.cdap.e2e.pages.locators.CdfNameSpaceAdminLocators; +import io.cdap.e2e.pages.locators.CdfSysAdminLocators; +import io.cdap.e2e.utils.AssertionHelper; +import io.cdap.e2e.utils.ConstantsUtil; +import io.cdap.e2e.utils.ElementHelper; +import io.cdap.e2e.utils.JsonUtils; +import io.cdap.e2e.utils.PluginPropertyUtils; +import io.cdap.e2e.utils.SeleniumHelper; +import io.cdap.e2e.utils.WaitHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.Map; + +/** + * Represents CdfNameSpaceAdminActions + */ +public class CdfNameSpaceAdminActions { + + private static final Logger logger = LoggerFactory.getLogger(CdfNameSpaceAdminActions.class); + public static CdfNameSpaceAdminLocators cdfNameSpaceAdminLocators; + + static { + cdfNameSpaceAdminLocators = SeleniumHelper.getPropertiesLocators( + CdfNameSpaceAdminLocators.class); + } + + public static void clickOnNameSpaceAdminTabs(String tabName, String nameSpaceName) { + ElementHelper.clickOnElement( + CdfNameSpaceAdminLocators.nameSpaceModules(tabName, nameSpaceName)); + } + + public static void openNamespaceAdminPage() { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.namespaceAdminMenu); + } + + public static void clickOnHamburgerMenu() { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.hamburgerMenu); + } + + public static void switchToNameSpace(String nameSpaceName) { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.switchNameSpace(nameSpaceName)); + } + + public static void createProfileForNamespace(String nameSpaceName) { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.createProfile(nameSpaceName)); + } + + public static void openNamespaceDropdown() { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.namespaceDropdown); + } + + public static void addNamespaceFromHamburgerMenu() { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.addNamespace); + } + + /** + * Enter KeyValue Pairs For Preference Property + * + * @param preferenceProperty @data-cy attribute value of preference Property. If + * preferenceProperty is present in + * {@link ConstantsUtil#DEFAULT_DATACY_ATTRIBUTES_FILE} then its data-cy + * is fetched from it else preferenceProperty is used as it is. + * @param keyValuePair Actual json KeyValue Pairs string is fetched from + * {@link ConstantsUtil#DEFAULT_PLUGIN_PROPERTIES_FILE} with + * keyValuePair as key + */ + public static void enterKeyValuePreferences(String preferenceProperty, String keyValuePair) { + String dataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute( + preferenceProperty); + if (dataCyAttribute == null) { + dataCyAttribute = preferenceProperty; + } + Map properties = + JsonUtils.convertKeyValueJsonArrayToMap(PluginPropertyUtils.pluginProp(keyValuePair)); + int index = 0; + for (Map.Entry entry : properties.entrySet()) { + if (index != 0) { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.locateAddRowButtonProperty( + dataCyAttribute, index - 1)); + } + ElementHelper.sendKeys(CdfNameSpaceAdminLocators.locateKeyProperty( + dataCyAttribute, index), entry.getKey()); + ElementHelper.sendKeys(CdfNameSpaceAdminLocators.locateValueProperty( + dataCyAttribute, index), entry.getValue()); + index++; + } + } + + public static void switchToNewNameSpace() { + ElementHelper.clickOnElement(CdfNameSpaceAdminLocators.switchToNameSpaceButton); + } + + public static void verifySwitchToNewNamespace(String value) { + String expectedNameSpace = PluginPropertyUtils.pluginProp(value); + AssertionHelper.verifyElementContainsText(CdfNameSpaceAdminLocators.namespaceText, + expectedNameSpace); + } + + public static void verifyElementIsDisplayed() { + ElementHelper.isElementDisplayed(CdfNameSpaceAdminLocators.pageHeaderNameSpaceAdmin); + } +} diff --git a/src/main/java/io/cdap/e2e/pages/locators/CdfNameSpaceAdminLocators.java b/src/main/java/io/cdap/e2e/pages/locators/CdfNameSpaceAdminLocators.java new file mode 100644 index 000000000..6f38f818d --- /dev/null +++ b/src/main/java/io/cdap/e2e/pages/locators/CdfNameSpaceAdminLocators.java @@ -0,0 +1,160 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package io.cdap.e2e.pages.locators; + +import io.cdap.e2e.utils.SeleniumDriver; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.How; + +/** + * Represents CdfNameSpaceAdminLocators + */ +public class CdfNameSpaceAdminLocators { + + @FindBy(how = How.XPATH, using = "//div[contains(text(),'Namespace Admin')]") + public static WebElement namespaceAdminMenu; + + @FindBy(how = How.XPATH, using = "//*[@data-cy='navbar-hamburger-icon']") + public static WebElement hamburgerMenu; + + public static WebElement nameSpaceModules(String module, String nameSpace) { + String path = "//*[@href=\"/cdap/ns/" + nameSpace + "/details/" + module + "\"]"; + return SeleniumDriver.getDriver().findElement(By.xpath(path)); + } + + public static WebElement createProfile(String nameSpace) { + String path = "//*[@href=\"/cdap/ns/" + nameSpace + "/profiles/create\"]"; + return SeleniumDriver.getDriver().findElement(By.xpath(path)); + } + + public static WebElement switchNameSpace(String nameSpace) { + String path = "//*[@href=\"/cdap/ns/'" + nameSpace + "'\"]"; + return SeleniumDriver.getDriver().findElement(By.xpath(path)); + } + + public static WebElement locateMenuLink(String menuLink) { + String xpath = "//*[@data-cy='navbar-" + menuLink + "-link']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + public static WebElement locateKeyProperty(String keyProperty, int row) { + String xpath = "//*[@data-cy='" + keyProperty + "" + row + "']//input[@placeholder='key']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + public static WebElement locateValueProperty(String valueProperty, int row) { + String xpath = "//*[@data-cy='" + valueProperty + "" + row + "']//input[@placeholder='value']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + public static WebElement locateAddRowButtonProperty(String addRowProperty, int row) { + String xpath = + "//*[@data-cy='" + addRowProperty + "" + row + "']//span" + + "//button[@type='submit' and @class='btn add-row-btn btn-link']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + @FindBy(how = How.XPATH, using = "//*[@class='namespace-dropdown']") + public static WebElement namespaceDropdown; + + @FindBy(how = How.XPATH, using = "//div[contains(text(),'Add Namespace')]") + public static WebElement addNamespace; + + @FindBy(how = How.XPATH, using = "//button[@data-cy='wizard-next-btn']") + public static WebElement clickOnNextButton; + + @FindBy(how = How.XPATH, using = "//button[@data-cy='wizard-finish-btn']") + public static WebElement clickOnFinishButton; + + public static WebElement locateKeyProperty(int row) { + String xpath = "//*[@data-cy= 'key-value-pair-" + row + "']//input[@placeholder='key']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + public static WebElement locateValueProperty(int row) { + String xpath = "//*[@data-cy= 'key-value-pair-" + row + "']//input[@placeholder='value']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + public static WebElement locateAddRowButtonProperty(int row) { + String xpath = "//*[@data-cy= 'key-value-pair-" + row + "']//span//button[@type='submit' and " + + "@class='btn add-row-btn btn-link']"; + return SeleniumDriver.getDriver().findElement(By.xpath(xpath)); + } + + public static WebElement locateProvisionerInList(String provisionerName) { + return SeleniumDriver.getDriver() + .findElement(By.xpath("//div[@data-cy='" + provisionerName + "']")); + } + + public static WebElement locateButtonType(String buttonType) { + return SeleniumDriver.getDriver() + .findElement(By.xpath("//button[@data-cy='" + buttonType + "']")); + } + + public static By profilePropertiesPage() { + return By.xpath("//h5[contains(text(), 'Create a profile')]"); + } + + public static By locateProfileTitle(String profileName) { + return By.xpath("//div[@title='" + profileName + "']"); + } + + @FindBy(how = How.XPATH, using = "//a[contains(text(),\"Switch to\")]") + public static WebElement switchToCreatedNamespace; + + @FindBy(how = How.XPATH, using = "//a[contains(text(),'Go to homepage')]") + public static WebElement goToHomepage; + + @FindBy(how = How.XPATH, using = "//*[@data-cy='wizard-result-icon-close-btn']") + public static WebElement closeAddNameSpaceWindow; + + @FindBy(how = How.XPATH, using = "//span[@id='setpreferences-fd']") + public static WebElement setPreferencesfromMainMenu; + + @FindBy(how = How.XPATH, using = "//span[contains(text(),'Upload Driver')]") + public static WebElement uploadDriverTab; + + @FindBy(how = How.XPATH, using = "//*[contains(@class,'close')]") + public static WebElement closeUploadDriverWindow; + + @FindBy(how = How.XPATH, using = "//span[contains(text(),'Link Repository')]") + public static WebElement linkRepositoryTab; + + @FindBy(how = How.XPATH, using = "//button[@class=\"MuiButtonBase-root MuiIconButton-root\"]") + public static WebElement closeExternalPage; + + @FindBy(how = How.XPATH, using = "//span[contains(text(),'Add Connection')]") + public static WebElement addConnectionTab; + + @FindBy(how = How.XPATH, using = "//span[contains(text(),'Import')]") + public static WebElement importConnectionTab; + + @FindBy(how = How.XPATH, using = "//span[contains(text(),'Create Profile')]") + public static WebElement createProfileInNamespaceAdmin; + + @FindBy(how = How.XPATH, using = "//a[contains(text(),\"Switch to\")]") + public static WebElement switchToNameSpaceButton; + + @FindBy(how = How.XPATH, using = "//div[@class=\"namespace-and-caret\"]") + public static WebElement namespaceText; + + @FindBy(how = How.XPATH, using = "//*[@data-cy='feature-heading'][//div[contains(text(),'Namespace')]]") + public static WebElement pageHeaderNameSpaceAdmin; +} + diff --git a/src/main/java/stepsdesign/NameSpaceadminSteps.java b/src/main/java/stepsdesign/NameSpaceadminSteps.java new file mode 100644 index 000000000..746754479 --- /dev/null +++ b/src/main/java/stepsdesign/NameSpaceadminSteps.java @@ -0,0 +1,88 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package stepsdesign; + +import io.cdap.e2e.pages.actions.CdfNameSpaceAdminActions; +import io.cdap.e2e.pages.actions.CdfPluginPropertiesActions; +import io.cdap.e2e.utils.CdfHelper; +import io.cucumber.java.en.Then; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Represents CdfNameSpaceAdminSteps + */ +public class NameSpaceadminSteps implements CdfHelper { + + private static final Logger logger = LoggerFactory.getLogger(NameSpaceadminSteps.class); + + @Then("Click on the Hamburger bar on the left panel") + public static void clickOnTheHamburgerIcon() { + CdfNameSpaceAdminActions.clickOnHamburgerMenu(); + } + + @Then("Click on NameSpace Admin link from the menu") + public void openNameSpaceAdminPage() { + CdfNameSpaceAdminActions.openNamespaceAdminPage(); + } + + @Then("Click on create profile button for {string} Namespace") + public void createProfileinsideNamespaceAdmin(String nameSpace) { + CdfNameSpaceAdminActions.createProfileForNamespace(nameSpace); + } + + @Then("Go to {string} tab from Configuration page for {string} Namespace") + public void openNameSpaceAdminPageTabs(String tabName, String nameSpace) { + CdfNameSpaceAdminActions.clickOnNameSpaceAdminTabs(tabName, nameSpace); + } + + @Then("Click on Namespace dropdown button") + public void openNameSpaceDropdown() { + CdfNameSpaceAdminActions.openNamespaceDropdown(); + } + + @Then("Click on the Add Namespace tab") + public void addNamespaceFromHamburgerMenu() { + CdfNameSpaceAdminActions.addNamespaceFromHamburgerMenu(); + } + + @Then("Set namespace preferences with key: {string} and value: {string}") + public void setNamespacePreferencesWithKeyAndValue(String keyProperty, String keyValuePairs) { + CdfNameSpaceAdminActions.enterKeyValuePreferences(keyProperty, keyValuePairs); + } + + @Then("Switch to the newly created Namespace") + public void switchToNewNameSpace() { + CdfNameSpaceAdminActions.switchToNewNameSpace(); + } + + @Then("Verify the namespace is switched to {string} successfully") + public void verifyNameSpaceSwitch(String newNameSpaceName) { + CdfNameSpaceAdminActions.verifySwitchToNewNamespace(newNameSpaceName); + } + + @Then("Add connection type as {string} and provide a {string}") + public void addConnectionInNameSpaceAdmin(String connectionType, String connectionName) { + CdfPluginPropertiesActions.clickPluginPropertyElement(connectionType); + CdfPluginPropertiesActions.enterValueInInputProperty("name", connectionName); + CdfPluginPropertiesActions.replaceValueInInputProperty("projectId", "projectId"); + } + + @Then("Verify if user successfully navigated to namespace admin page") + public void verifyThatNamespacePageIsSuccessfullyOpened() { + CdfNameSpaceAdminActions.verifyElementIsDisplayed(); + } +}