From 107421dd567795757354cd894c449e97420875ba Mon Sep 17 00:00:00 2001 From: AnkitCLI Date: Tue, 17 Oct 2023 14:47:39 +0530 Subject: [PATCH] Hub framework steps --- .../cdap/e2e/pages/actions/CdfHubActions.java | 85 +++++++++++++++++++ .../e2e/pages/locators/CdfHubLocators.java | 66 ++++++++++++++ src/main/java/stepsdesign/CdfHubSteps.java | 81 ++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 src/main/java/io/cdap/e2e/pages/actions/CdfHubActions.java create mode 100644 src/main/java/io/cdap/e2e/pages/locators/CdfHubLocators.java create mode 100644 src/main/java/stepsdesign/CdfHubSteps.java diff --git a/src/main/java/io/cdap/e2e/pages/actions/CdfHubActions.java b/src/main/java/io/cdap/e2e/pages/actions/CdfHubActions.java new file mode 100644 index 000000000..2d975a378 --- /dev/null +++ b/src/main/java/io/cdap/e2e/pages/actions/CdfHubActions.java @@ -0,0 +1,85 @@ +/* + * 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.CdfHubLocators; +import io.cdap.e2e.utils.AssertionHelper; +import io.cdap.e2e.utils.ElementHelper; +import io.cdap.e2e.utils.PluginPropertyUtils; +import io.cdap.e2e.utils.SeleniumHelper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CDF hub related actions. + */ +public class CdfHubActions { + + private static final Logger logger = LoggerFactory.getLogger(CdfHubActions.class); + static { + SeleniumHelper.getPropertiesLocators(CdfHubLocators.class); + } + + public static void clickOnHub() { + ElementHelper.clickOnElement(CdfHubLocators.hubPage); + } + public static void clickOnPlugin(String pluginName) { + ElementHelper.clickOnElement(CdfHubLocators.locatePlugin(pluginName)); + } + public static void clickOnHomePage() { + ElementHelper.clickOnElement(CdfHubLocators.toHomePage); + } + public static void clickOnDeploy() { + ElementHelper.clickOnElement(CdfHubLocators.deployButton); + } + public static void clickOnFinish() { + ElementHelper.clickOnElement(CdfHubLocators.finishButton); + } + public static void clickOnOptions(String option) { + ElementHelper.clickOnElement(CdfHubLocators.locateOptions(option)); + } + public static void clickOnCLoseButton() { + ElementHelper.clickOnElement(CdfHubLocators.closeButton); + } + public static void clickOnSearchTab(String message) { + ElementHelper.sendKeys(CdfHubLocators.searchTab, message); + } + public static void clickOnSearch(String pluginName) { + ElementHelper.sendKeys(CdfHubLocators.searchTabControlCenter, pluginName); + } + public static void verifyErrorMessageOnHeader(String errorMessageLocation) { + String expectedErrorMessage = PluginPropertyUtils.errorProp(errorMessageLocation); + AssertionHelper.verifyElementContainsText(CdfHubLocators.errorMessage, expectedErrorMessage); + } + public static void verifyElementIsDisplayed() { + ElementHelper.isElementDisplayed(CdfHubLocators.locateHub); + } + public static void clickOnDeleteButton() { + ElementHelper.clickIfDisplayed(CdfHubLocators.clickOnDeleteButton()); + } + public static void deletePluginControlCenter() { + ElementHelper.clickOnElement(CdfHubLocators.deleteIconControlCenter); + clickOnDeleteButton(); + } + public static void verifyPluginIsDeployed(String pluginName) { + String pluginPropertyDataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute(pluginName); + if (pluginPropertyDataCyAttribute == null) { + pluginPropertyDataCyAttribute = pluginName; + } + ElementHelper.isElementDisplayed(CdfHubLocators.locatePluginName(pluginPropertyDataCyAttribute)); + } +} diff --git a/src/main/java/io/cdap/e2e/pages/locators/CdfHubLocators.java b/src/main/java/io/cdap/e2e/pages/locators/CdfHubLocators.java new file mode 100644 index 000000000..236767c7a --- /dev/null +++ b/src/main/java/io/cdap/e2e/pages/locators/CdfHubLocators.java @@ -0,0 +1,66 @@ +/* + * 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; + +/** + * CDF hub related locators. + */ +public class CdfHubLocators { + + @FindBy(how = How.XPATH, using = "//input[@class='search-input form-control'][@placeholder='Search by name']") + public static WebElement searchTab; + @FindBy(how = How.XPATH, using = "//input[@class='search-input form-control'][@placeholder='Search']") + public static WebElement searchTabControlCenter; + @FindBy(how = How.XPATH, using = "//div[@data-cy='hub-close-btn']") + public static WebElement closeButton; + @FindBy(how = How.XPATH, using = "//button[@data-cy='one_step_deploy_plugin-btn']") + public static WebElement deployButton; + @FindBy(how = How.XPATH, using = "//button[@data-cy='wizard-finish-btn']") + public static WebElement finishButton; + @FindBy(how = How.XPATH, using = "//*[contains(text(),'No entities found')]") + public static WebElement errorMessage; + @FindBy(how = How.XPATH, using = "//span[contains(text(),'Hub')]") + public static WebElement locateHub; + @FindBy(how = How.XPATH, using = "//*[contains(text(),'Go to homepage')]") + public static WebElement toHomePage; + @FindBy(how = How.XPATH, using = "//button[@id='navbar-hub']") + public static WebElement hubPage; + @FindBy(how = How.XPATH, using = "//div[@class='just-added-entities-list']//button[@class='btn btn-link']" + + "//*[@class='icon-svg icon-trash']") + public static WebElement deleteIconControlCenter; + + public static WebElement locatePlugin(String pluginName) { + return SeleniumDriver.getDriver() + .findElement(By.xpath("//*[contains(text(),'" + pluginName + "')]")); + } + + public static WebElement locateOptions(String featureName) { + return SeleniumDriver.getDriver().findElement(By.xpath("//span[@title='" + featureName + "']")); + } + public static WebElement locatePluginName(String pluginName) { + return SeleniumDriver.getDriver().findElement(By.xpath("//*[contains(text(),'" + pluginName + "')]")); + } + + public static By clickOnDeleteButton() { + return By.xpath("//button[@class='btn btn-primary'][//button[@data-cy='Delete']]"); + } +} diff --git a/src/main/java/stepsdesign/CdfHubSteps.java b/src/main/java/stepsdesign/CdfHubSteps.java new file mode 100644 index 000000000..97782a68f --- /dev/null +++ b/src/main/java/stepsdesign/CdfHubSteps.java @@ -0,0 +1,81 @@ +/* + * 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.CdfHubActions; +import io.cdap.e2e.pages.locators.CdfHubLocators; +import io.cdap.e2e.utils.CdfHelper; +import io.cdap.e2e.utils.SeleniumHelper; +import io.cucumber.java.en.Then; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CDF hub related step design. + */ +public class CdfHubSteps implements CdfHelper { + private static final Logger logger = LoggerFactory.getLogger(CdfHubSteps.class); + static { + SeleniumHelper.getPropertiesLocators(CdfHubLocators.class); + } + + @Then("Click on Hub button") + public static void openHub() { + CdfHubActions.clickOnHub(); + } + @Then("Click on {string} plugin") + public static void openPlugin(String pluginName) { + CdfHubActions.clickOnPlugin(pluginName); + } + @Then("Click on {string} option") + public static void openOptions(String option) { + CdfHubActions.clickOnOptions(option); + } + @Then("Click on close button") + public static void closeButton() { + CdfHubActions.clickOnCLoseButton(); + } + @Then("Deploy the plugin") + public static void deployPlugin() { + CdfHubActions.clickOnDeploy(); + CdfHubActions.clickOnFinish(); + CdfHubActions.clickOnHomePage(); + } + @Then("Enter the text in search tab {string}") + public static void openSearch(String value) { + CdfHubActions.clickOnSearchTab(value); + } + @Then("Enter the text in search tab in control center {string}") + public static void openSearchControlCenter(String value) { + CdfHubActions.clickOnSearch(value); + } + @Then("Verify that search displaying an error message: {string} on the header") + public void verifyErrorMessageDisplayedOnPluginHeader(String errorMessageLocation) { + CdfHubActions.verifyErrorMessageOnHeader(errorMessageLocation); + } + @Then("Verify that user is navigated to hub page successfully") + public void verifyThatHubPageIsSuccessfullyOpened() { + CdfHubActions.verifyElementIsDisplayed(); + } + @Then("Verify that {string} plugin is successfully deployed") + public void verifyThatPluginIsSuccessfullyDeployed(String pluginName) { + CdfHubActions.verifyPluginIsDeployed(pluginName); + } + @Then("Verify user can click on the delete icon of the plugin and plugin gets deleted successfully") + public void deleteControlCenterPlugin() { + CdfHubActions.deletePluginControlCenter(); + } +}