From 52a159803e64cf5aaf8b541655c0b1a0999f2c40 Mon Sep 17 00:00:00 2001 From: AnkitCLI Date: Fri, 9 Aug 2024 15:32:38 +0530 Subject: [PATCH] wrangler common function --- .../e2e/pages/actions/WranglerActions.java | 193 ++++++++++++++---- .../e2e/pages/locators/WranglerLocators.java | 86 ++++++-- src/main/java/stepsdesign/WranglerSteps.java | 63 ++++-- 3 files changed, 265 insertions(+), 77 deletions(-) diff --git a/src/main/java/io/cdap/e2e/pages/actions/WranglerActions.java b/src/main/java/io/cdap/e2e/pages/actions/WranglerActions.java index 7213f6004..f8cf72dd5 100644 --- a/src/main/java/io/cdap/e2e/pages/actions/WranglerActions.java +++ b/src/main/java/io/cdap/e2e/pages/actions/WranglerActions.java @@ -15,11 +15,12 @@ */ package io.cdap.e2e.pages.actions; -import io.cdap.e2e.pages.locators.CdfHubLocators; import io.cdap.e2e.pages.locators.WranglerLocators; import io.cdap.e2e.utils.ElementHelper; +import io.cdap.e2e.utils.SeleniumDriver; import io.cdap.e2e.utils.SeleniumHelper; -import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.Select; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,89 +29,207 @@ * CDF wrangler related actions. */ public class WranglerActions { - private static final Logger logger = LoggerFactory.getLogger(CdfHubActions.class); + private static final Logger logger = LoggerFactory.getLogger(WranglerActions.class); static { - SeleniumHelper.getPropertiesLocators(CdfHubLocators.class); + SeleniumHelper.getPropertiesLocators(WranglerLocators.class); } public static void clickOnTransformationButton(String columnName) { ElementHelper.clickOnElement(WranglerLocators.locateTransformationButton(columnName)); } - public static void selectDirectiveType(String directive, String directiveType) throws InterruptedException { - ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + + public static void selectDirectiveTypeWithDropdownAndText(String directive, String directiveType, String text) throws + InterruptedException { + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + + if (directive.equals("Find and replace")) { + ElementHelper.sendKeys(WranglerLocators.enterOldValue, directiveType); + ElementHelper.sendKeys(WranglerLocators.enterNewValue, text); + ElementHelper.clickOnElement(WranglerLocators.replaceAllButton); + } else { + + switch (directiveType) { - case "value is empty": - ElementHelper.isElementDisplayed(WranglerLocators.selectDropdown); - ElementHelper.clickOnElement(WranglerLocators.selectDropdown); - ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(directiveType)); + + case "value contains": + case "value is": + case "value starts with": + case "value ends with": + case "value matches regex": + Select select = new Select(WranglerLocators.filterSelect); + select.selectByVisibleText(directiveType); + ElementHelper.sendKeysToTextarea(WranglerLocators.filterText, text); break; - default: - ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(directiveType)); + case "Custom condition": + Select selectCustom = new Select(WranglerLocators.filterSelect); + selectCustom.selectByVisibleText(directiveType); + ElementHelper.sendKeysToTextarea(WranglerLocators.filterTextArea, text); + break; } + } } public static void selectDirective(String directive) { ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); } - public static void selectDirectiveAndEnterValue(String directive, String text) throws InterruptedException { - ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); - Thread.sleep(5000); - ElementHelper.hoverOverElement(WranglerLocators.customTransform); - ElementHelper.clickOnElement(WranglerLocators.customTransform); -// ElementHelper.sendKeys(WranglerLocators.customTransform, text); - } + public static void selectDirectiveAndOption(String directive, String option) throws InterruptedException { + + switch (directive) { + + case "Custom transform": + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + ElementHelper.sendKeysToTextarea(WranglerLocators.filterTextArea, option); + break; + + case "Filter": + case "Send to error": + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + Select selectDropdown = new Select(WranglerLocators.filterSelect); + ElementHelper.scrollToElementUsingJsExecutor(WranglerLocators.selectDirectiveOption(option)); + selectDropdown.selectByVisibleText(option); + break; + + case "Fill null or empty cells": + case "Copy column": + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + ElementHelper.sendKeysToTextarea(WranglerLocators.filterText, option); + break; + + case "Hash": + ElementHelper.hoverOverElement(WranglerLocators.scrollButton); + Thread.sleep(3000); + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + Select select = new Select(WranglerLocators.filterSelect); + ElementHelper.scrollToElementUsingJsExecutor(WranglerLocators.selectDropDownOption(option)); + select.selectByVisibleText(option); + break; + + case "Decode": + ElementHelper.hoverOverElement(WranglerLocators.scrollButton); + Thread.sleep(3000); + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(option)); + break; + + default: + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(option)); + } - public static void clickOnScrollDownOption() throws InterruptedException { - // Thread.sleep(1000); - ElementHelper.clickIfDisplayed((By) WranglerLocators.scrollButton, 30); - Thread.sleep(100); - // ElementHelper.clickOnElement(WranglerLocators.scrollButton); - //WaitHelper.waitForElementToBeDisplayed(WranglerLocators.scrollButtonDisabled); } - public static void selectDirectiveTypeWithOption(String directive, String directiveType, String option) + public static void selectDirectiveTypeWithThreeOptions(String directive, String directiveType, String option) throws InterruptedException { ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(directiveType)); - Thread.sleep(5000); + switch (directiveType) { case "Decimal": ElementHelper.sendKeys(WranglerLocators.scaleText, option); - break; + break; case "Character count": - ElementHelper.replaceElementValue(WranglerLocators.destinationColumn, option); + ElementHelper.replaceElementValue(WranglerLocators.filterText, option); break; case "Fixed length": ElementHelper.sendKeys(WranglerLocators.columnWidths, option); break; + case "XML to JSON": case "JSON": ElementHelper.replaceElementValue(WranglerLocators.enterDepth, option); break; + + case "Excel": + ElementHelper.replaceElementValue(WranglerLocators.excelSheetNumber, option); + break; + + case "Using patterns": + ElementHelper.clickOnElement(WranglerLocators.selectPattern); + ElementHelper.clickOnElement(WranglerLocators.selectOption(option)); + ElementHelper.clickOnElement(WranglerLocators.extractButton); + break; + default: ElementHelper.clickOnElement(WranglerLocators.selectRadioButton(option)); } } - public static void selectDirectiveTypeWithMultipleOption(String directive, String directiveType, String text, - String option) + + public static void selectDirectiveTypeWithFourOption(String directive, String directiveType, String text, + String option) throws InterruptedException { ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); - ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(directiveType)); switch (directiveType) { case "Concatenate": - // ElementHelper.sendKeys(WranglerLocators.enterText, text); - Select select = new Select(WranglerLocators.selectDropdownConcatenate); - select.selectByVisibleText("at the end"); -// ElementHelper.clickOnElement(WranglerLocators.selectDropdownConcatenate); -// ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(option)); + ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(directiveType)); + ElementHelper.sendKeys(WranglerLocators.filterText, text); + ElementHelper.clickOnElement(WranglerLocators.filterSelect); + Thread.sleep(3000); + ElementHelper.clickOnElementUsingJsExecutor(WranglerLocators.selectDirectiveOption(option)); + break; + + case "Datetime": + case "Simple date": + if (option.equals("Custom format")) { + ElementHelper.clickOnElement(WranglerLocators.selectDirectiveOption(directiveType)); + ElementHelper.clickOnElement(WranglerLocators.selectRadioButton(option)); + ElementHelper.sendKeys(WranglerLocators.customDate, text); + } + break; + case "Always": + Select select = new Select(WranglerLocators.filterSelect); + select.selectByVisibleText(directiveType); + ElementHelper.sendKeysToTextarea(WranglerLocators.enterCounterName, text); + ElementHelper.replaceElementValue(WranglerLocators.incrementCount, option); break; } } + + public static void selectDirectiveTypeWithFiveOption(String directive, String option1, String option2, + String option3, String option4) + throws InterruptedException { + ElementHelper.clickOnElement(WranglerLocators.selectDirective(directive)); + switch (directive) { + case "Set counter": + Select select = new Select(WranglerLocators.filterSelect); + select.selectByVisibleText(option1); + ElementHelper.sendKeysToTextarea(WranglerLocators.filterTextArea, option2); + ElementHelper.sendKeysToTextarea(WranglerLocators.enterCounterName, option4); + ElementHelper.replaceElementValue(WranglerLocators.incrementCount, option3); + break; + + case "Define variable": + ElementHelper.sendKeysToTextarea(WranglerLocators.variableName, option4); + Select selectColumnName = new Select(WranglerLocators.selectColumn); + selectColumnName.selectByVisibleText(option3); + Select selectVar = new Select(WranglerLocators.selectRow); + selectVar.selectByVisibleText(option1); + if (option1.equals("Custom condition")) { + ElementHelper.sendKeysToTextarea(WranglerLocators.filterTextArea, option2); + } else { + ElementHelper.sendKeysToTextarea(WranglerLocators.variableValue, option2); + } + break; + } + } + + public static void createPipelineButton() { + ElementHelper.clickOnElement(WranglerLocators.createPipelineButton); } + public static void enterDirectiveFromCommandLine(String directive) { + ElementHelper.sendKeys(WranglerLocators.directiveCommandLine, directive); + Actions act = new Actions(SeleniumDriver.getDriver()); + act.sendKeys(new CharSequence[]{Keys.ENTER}).perform(); + } + + public static void selectCheckboxOnTwoColumns(String column1, String column2) { + ElementHelper.clickOnElement(WranglerLocators.locateCheckboxOfColumn(column1)); + ElementHelper.clickOnElement(WranglerLocators.locateCheckboxOfColumn(column2)); + } +} diff --git a/src/main/java/io/cdap/e2e/pages/locators/WranglerLocators.java b/src/main/java/io/cdap/e2e/pages/locators/WranglerLocators.java index 39cd12afe..1e00afc36 100644 --- a/src/main/java/io/cdap/e2e/pages/locators/WranglerLocators.java +++ b/src/main/java/io/cdap/e2e/pages/locators/WranglerLocators.java @@ -25,53 +25,99 @@ * CDF wrangler related locators. */ public class WranglerLocators { - @FindBy(how = How.XPATH, using = "//div[@class='scroll-down-container text-center']") + @FindBy(how = How.XPATH, using = "//div[@data-testid='common-components-scrollableList-scrollDownButton']") public static WebElement scrollButton; @FindBy(how = How.XPATH, using = "//input[@id='DataPrep-Directives-ChangeDataType-decimal-scaleInputId']") public static WebElement scaleText; - @FindBy(how = How.XPATH, using = "//input[@placeholder='Destination column']") - public static WebElement destinationColumn; + @FindBy(how = How.XPATH, using = "//button[contains(text(),'Extract')]") + public static WebElement extractButton; - @FindBy(how = How.XPATH, using = "//select[@class='form-control mousetrap']") - public static WebElement selectDropdown; + @FindBy(how = How.XPATH, using = "//button[contains(text(),'Replace All')]") + public static WebElement replaceAllButton; - @FindBy(how = How.XPATH, using = "//select[@class='form-control mousetrap']") - public static WebElement selectDropdownConcatenate; + @FindBy(how = How.XPATH, using = "//input[@data-testid='features-dataprep-workspace-cli-input']") + public static WebElement directiveCommandLine; + @FindBy(how = How.XPATH, using = " //button[@data-testid='features-dataprep-workspace-topPanel-actionButtons-" + + "createPipeline']") + public static WebElement createPipelineButton; + + @FindBy(how = How.XPATH, using = "//input[@placeholder='Enter variable_name']") + public static WebElement variableName; + + @FindBy(how = How.XPATH, using = " //div[@class='condition-text-input']//input") + public static WebElement variableValue; + + @FindBy(how = How.XPATH, using = "//input[@value='sheetnumber']/following::input") + public static WebElement excelSheetNumber; + @FindBy(how = How.XPATH, using = " //button[@class='dropdown-toggle btn btn-secondary']") + public static WebElement selectPattern; + @FindBy(how = How.XPATH, using = "//div[contains(@class, 'level-popover')]//input") + public static WebElement filterText; + + @FindBy(how = How.XPATH, using = "//input[@placeholder='Old value']") + public static WebElement enterOldValue; + + @FindBy(how = How.XPATH, using = "//input[@placeholder='New value']") + public static WebElement enterNewValue; + @FindBy(how = How.XPATH, using = "//div[contains(@class, 'level-popover')]//textarea") + public static WebElement filterTextArea; + + @FindBy(how = How.XPATH, using = "//div[contains(@class, 'level-popover')]//select") + public static WebElement filterSelect; - @FindBy(how = How.XPATH, using = "//input[@placeholder='Enter string']") - public static WebElement enterText; @FindBy(how = How.XPATH, using = "//*[contains(text(),'Column widths')]") public static WebElement columnWidths; + @FindBy(how = How.XPATH, using = "//*[contains(text(),'Select column in selected row')]" + + "/following-sibling::div//select") + public static WebElement selectColumn; - @FindBy(how = How.XPATH, using = "//textarea[@class='form-control mousetrap']") - public static WebElement customTransform; + @FindBy(how = How.XPATH, using = "//*[contains(text(),'Select row where')]/following-sibling::div//select") + public static WebElement selectRow; @FindBy(how = How.XPATH, using = "//input[@placeholder='Enter depth']") public static WebElement enterDepth; - @FindBy(how = How.XPATH, using = "//div[@class='scroll-down-container text-center-disabled']") - public static WebElement scrollButtonDisabled; - @FindBy(how = How.XPATH, using = "//select[@class='form-control mousetrap']") - public static WebElement locatePropertyElement; + @FindBy(how = How.XPATH, using = " //input[@placeholder=\"e.g. yyyy.MM.dd G 'at' HH:mm:ss z\"]") + public static WebElement customDate; + + @FindBy(how = How.XPATH, using = "//input[@placeholder='Enter counter name']") + public static WebElement enterCounterName; + + @FindBy(how = How.XPATH, using = "//*[contains(text(),'increment the count by')]/following-sibling::input") + public static WebElement incrementCount; + //option[@value='EMPTY'] - public static By locateDropdownListItem(String option) { - return By.xpath("//*[contains(text(),'" + option + "')]"); - } public static WebElement locateTransformationButton(String columnName) { return SeleniumDriver.getDriver() .findElement(By.xpath("//th[@id='column-" + columnName + "']/descendant::button")); } + + public static WebElement locateCheckboxOfColumn(String columnName) { + return SeleniumDriver.getDriver() + .findElement(By.xpath("//th[@id='column-" + columnName + "']/descendant::span[@data-testid='" + + "features-dataprep-workspace-dataTable-head-columnSelectToggle']")); + } + public static WebElement selectDirective(String directive) { return SeleniumDriver.getDriver() - .findElement(By.xpath("//*[contains(text(),'" + directive + "')]")); + .findElement(By.xpath("//*[text()='" + directive + "']")); + } + + public static WebElement selectDropDownOption(String dropdown) { + return SeleniumDriver.getDriver() + .findElement(By.xpath("//option[@value='" + dropdown + "']")); } public static WebElement selectDirectiveOption(String option) { - return SeleniumDriver.getDriver().findElement(By.xpath("//*[contains(text(),'" + option + "')]")); + return SeleniumDriver.getDriver().findElement(By.xpath("//*[text()='" + option + "']")); } public static WebElement selectRadioButton(String optionType) { return SeleniumDriver.getDriver().findElement(By.xpath("//span[contains(text(),'" + optionType + "')]")); } + + public static WebElement selectOption(String optionType) { + return SeleniumDriver.getDriver().findElement(By.xpath("//span[text()='" + optionType + "']")); + } } diff --git a/src/main/java/stepsdesign/WranglerSteps.java b/src/main/java/stepsdesign/WranglerSteps.java index 0674ff911..13ed51557 100644 --- a/src/main/java/stepsdesign/WranglerSteps.java +++ b/src/main/java/stepsdesign/WranglerSteps.java @@ -16,7 +16,6 @@ package stepsdesign; import io.cdap.e2e.pages.actions.WranglerActions; -import io.cdap.e2e.pages.locators.CdfHubLocators; import io.cdap.e2e.pages.locators.WranglerLocators; import io.cdap.e2e.utils.CdfHelper; import io.cdap.e2e.utils.SeleniumHelper; @@ -28,46 +27,70 @@ * CDF wrangler related steps. */ public class WranglerSteps implements CdfHelper { - private static final Logger logger = LoggerFactory.getLogger(CdfHubSteps.class); + private static final Logger logger = LoggerFactory.getLogger(WranglerSteps.class); + static { - SeleniumHelper.getPropertiesLocators(CdfHubLocators.class); + SeleniumHelper.getPropertiesLocators(WranglerLocators.class); } -@Then("Expand the dropdown to apply column transformations for column: {string}") -public static void expandButton(String columnName) { - WranglerActions.clickOnTransformationButton(columnName); + @Then("Expand the dropdown to apply column transformations for column: {string}") + public static void expandButton(String columnName) { + WranglerActions.clickOnTransformationButton(columnName); } - @Then("Apply directive: {string} as {string}") - public static void selectDirectiveAndOption(String directive, String option) throws InterruptedException { - WranglerActions.selectDirectiveType(directive, option); - } +// @Then("Apply directive: {string} as {string}") +// public static void selectDirectiveAndOption(String directive, String option) throws InterruptedException { +// WranglerActions.selectDirectiveType(directive, option); +// } @Then("Apply directive: {string}") public static void selectDirective(String directive) { WranglerActions.selectDirective(directive); } - @Then("Apply directive: {string} with value {string}") - public static void selectDirectiveAndEnterText(String directive, String text) throws InterruptedException { - WranglerActions.selectDirectiveAndEnterValue(directive, text); + @Then("Click on Create pipeline button") + public static void createPipelineButton() { + WranglerActions.createPipelineButton(); + } + + @Then("Apply directive: {string} as {string}") + public static void selectDirectiveAndEnterOption(String directive, String text) throws InterruptedException { + WranglerActions.selectDirectiveAndOption(directive, text); + } + + @Then("Enter directive from CLI {string}") + public static void enterDirectiveFromUserInput(String directive) throws InterruptedException { + WranglerActions.enterDirectiveFromCommandLine(directive); } @Then("Apply directive: {string} as {string} with {string} option") - public static void selectDirectiveAndOption(String directive, String option, String optionType) + public static void selectDirectiveWithThreeOption(String directive, String option, String optionType) throws InterruptedException { - WranglerActions.selectDirectiveTypeWithOption(directive, option, optionType); + WranglerActions.selectDirectiveTypeWithThreeOptions(directive, option, optionType); } - @Then("Click on scroll down option") - public static void clickOnScrollOption() throws InterruptedException { - WranglerActions.clickOnScrollDownOption(); + @Then("Select checkbox on two columns {string} and {string}") + public static void selectDirectiveOnTwoColumns(String column1, String column2) + throws InterruptedException { + WranglerActions.selectCheckboxOnTwoColumns(column1, column2); + } + + @Then("Apply directive: {string} and select: {string} and enter: {string}") + public static void selectDirectiveDropdownAndText(String directive, String option, String optionType) + throws InterruptedException { + WranglerActions.selectDirectiveTypeWithDropdownAndText(directive, option, optionType); } - @Then("Apply directive:{string} as {string} and enter {string} at {string}") + @Then("Apply directive:{string} with directive type: {string} and select {string} and enter {string}") public static void clickOnMultipleOption(String directive, String option, String text, String dropdown) throws InterruptedException { - WranglerActions.selectDirectiveTypeWithMultipleOption(directive, option, text, dropdown); + WranglerActions.selectDirectiveTypeWithFourOption(directive, option, text, dropdown); + } + + @Then("Apply directive:{string} and select {string} with condition {string} with option {string} and name {string}") + public static void clickOnFiveOption(String directive, String option1, String option2, String option3, String option4) + throws InterruptedException { + WranglerActions.selectDirectiveTypeWithFiveOption(directive, option1, option2, option3, option4); } }