Skip to content

Commit

Permalink
wrangler common function
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitCLI committed Aug 9, 2024
1 parent e0d9ff6 commit 52a1598
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 77 deletions.
193 changes: 156 additions & 37 deletions src/main/java/io/cdap/e2e/pages/actions/WranglerActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
86 changes: 66 additions & 20 deletions src/main/java/io/cdap/e2e/pages/locators/WranglerLocators.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "']"));
}
}
Loading

0 comments on commit 52a1598

Please sign in to comment.