Skip to content

Commit

Permalink
CDF Login
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipinofficial11 committed Aug 21, 2023
1 parent 574cdf3 commit 3bcdf98
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

/**
Expand Down Expand Up @@ -85,6 +86,15 @@ public static Boolean isRunning() {
return validatePipelineExpectedStatus(CdfPipelineRunLocators.runningStatus);
}

/**
* Check if the pipeline is in Starting Status
*
* @return Boolean
*/
public static Boolean isStarting() {
return validatePipelineExpectedStatus(CdfPipelineRunLocators.startingStatus);
}

/**
* Check if the pipeline is in Provisioning Status
*
Expand All @@ -109,7 +119,16 @@ public static void waitForPipelineToTransitionToStatus(String pipelineStatus, lo
* Wait till the Pipeline's status changes (from Running) to either Succeeded, Failed or Stopped within the
* Timeout: {@link ConstantsUtil#PIPELINE_RUN_TIMEOUT_SECONDS}
*/
public static void waitTillPipelineRunCompletes() {
public static void waitTillPipelineRunCompletes() throws InterruptedException, IOException {
// Adding a page refresh in case tests are running on CDF to update the pipeline status.
if (Boolean.parseBoolean(SeleniumHelper.readParameters(ConstantsUtil.TESTONCDF)) ||
Boolean.parseBoolean(SeleniumHelper.readParameters(ConstantsUtil.TESTONHDF))) {
do {
PageHelper.refreshCurrentPage();
SeleniumDriver.getWaitDriver(ConstantsUtil.PAGE_LOAD_TIMEOUT_SECONDS);
} while (isStarting() || isRunning() || isProvisioning());
}

SeleniumDriver.getWaitDriver(ConstantsUtil.PIPELINE_RUN_TIMEOUT_SECONDS).until(ExpectedConditions.or(
ExpectedConditions.visibilityOf(CdfPipelineRunLocators.succeededStatus),
ExpectedConditions.visibilityOf(CdfPipelineRunLocators.failedStatus),
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/io/cdap/e2e/pages/actions/CdfSignInActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.CdfSignInLocator;
import io.cdap.e2e.utils.ConstantsUtil;
import io.cdap.e2e.utils.ElementHelper;
import io.cdap.e2e.utils.PluginPropertyUtils;
import io.cdap.e2e.utils.SeleniumHelper;
import io.cdap.e2e.utils.WaitHelper;
import java.io.IOException;
import static io.cdap.e2e.utils.ConstantsUtil.CDFPASSWORD;
import static io.cdap.e2e.utils.ConstantsUtil.CDFUSERNAME;


/**
* Represents CdfSignInActions
*/
public class CdfSignInActions {
private static CdfSignInLocator cdfSignInLocator;
static {
cdfSignInLocator = SeleniumHelper.getPropertiesLocators(CdfSignInLocator.class);
}

public static void login() throws IOException {
ElementHelper.sendKeys(cdfSignInLocator.cdfUsername, SeleniumHelper.readParameters(CDFUSERNAME));
ElementHelper.clickOnElement(cdfSignInLocator.nextButton);
ElementHelper.sendKeys(cdfSignInLocator.cdfPassword, SeleniumHelper.readParameters(CDFPASSWORD));
ElementHelper.clickOnElement(cdfSignInLocator.nextButton);

// Adding optional operations here.

/*
Based on the observations in case of CDF test execution from local we encounter Allow Button
and in case of CDF test execution from Cloud Build we encounter Continue Button that's why we
are using 2 confirmation buttons here.
*/

String testAccountName = PluginPropertyUtils.pluginProp("testAccountName");
ElementHelper.clickIfDisplayed(cdfSignInLocator.selectTestAccount(testAccountName),
ConstantsUtil.MEDIUM_TIMEOUT_SECONDS, cdfSignInLocator.clickOnAllowButton());

ElementHelper.clickIfDisplayed(cdfSignInLocator.clickOnContinueButton(), ConstantsUtil.MEDIUM_TIMEOUT_SECONDS,
cdfSignInLocator.locatePluginNameInList(ConstantsUtil.FIRST_PLUGIN_IN_LIST, "Source"));

ElementHelper.clickIfDisplayed(cdfSignInLocator.clickOnAllowButton(), ConstantsUtil.MEDIUM_TIMEOUT_SECONDS,
cdfSignInLocator.locatePluginNameInList(ConstantsUtil.FIRST_PLUGIN_IN_LIST, "Source"));
}

public static boolean isUserLoggedInCDF() {
return !WaitHelper.waitForElementToBeOptionallyDisplayed(
CdfSignInLocator.locatorOfEmailTextBox(), ConstantsUtil.SMALL_TIMEOUT_SECONDS);
}
}
58 changes: 58 additions & 0 deletions src/main/java/io/cdap/e2e/pages/locators/CdfSignInLocator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

/**
* Represents CdfSignInLocators
*/
public class CdfSignInLocator {

@FindBy(how = How.XPATH, using = "//input[@name='identifier']")
public WebElement cdfUsername;

@FindBy(how = How.XPATH, using = "//input[@name='Passwd']")
public WebElement cdfPassword;

@FindBy(how = How.XPATH, using = "//*[contains(text(),'Next')]//parent::button")
public WebElement nextButton;

public static By locatorOfEmailTextBox() {
return By.xpath("//input[@name='identifier']");
}

public By selectTestAccount(String testAccountName) {
return By.xpath("//*[contains(text(),'" + testAccountName + "')]");
}

public By clickOnAllowButton() {
return By.xpath("//button[contains(text(),'Allow')]");
}

public By clickOnContinueButton() {
return By.xpath("//span[contains(text(),'Continue')]");
}

public static By locatePluginNameInList(String pluginName, String pluginGroupName) {
return By.xpath("//div[@data-cy='plugin-" + pluginGroupName + "-group']" +
"//div[contains(@class, 'PluginNameContainer')][normalize-space(text()) = '" + pluginName + "' " +
"or translate(normalize-space(text()),' ','') = '" + pluginName + "']");
}
}
8 changes: 8 additions & 0 deletions src/main/java/io/cdap/e2e/utils/CdfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.cdap.e2e.pages.actions.CdfGcsActions;
import io.cdap.e2e.pages.actions.CdfLogActions;
import io.cdap.e2e.pages.actions.CdfPipelineRunAction;
import io.cdap.e2e.pages.actions.CdfSignInActions;
import io.cdap.e2e.pages.actions.CdfStudioActions;
import io.cdap.e2e.pages.actions.HdfSignInActions;
import io.cdap.e2e.pages.locators.CdfGCSLocators;
Expand Down Expand Up @@ -55,6 +56,13 @@ default void openCdf() throws IOException, InterruptedException {
WaitHelper.waitForPageToLoad();
}

if (Boolean.parseBoolean(SeleniumHelper.readParameters(ConstantsUtil.TESTONCDF)) && !CdfSignInActions.
isUserLoggedInCDF()) {
CdfSignInActions.login();
PageHelper.acceptAlertIfPresent();
WaitHelper.waitForPageToLoad();
}

/* TODO: Remove below wait once https://cdap.atlassian.net/browse/CDAP-18862 is fixed */
WaitHelper.waitForElementToBeDisplayed(
CdfStudioLocators.locatePluginNameInList(ConstantsUtil.FIRST_PLUGIN_IN_LIST, "Source"));
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/cdap/e2e/utils/ConstantsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class ConstantsUtil {
public static final String GPAZWRD = "gPassword";
public static final String HDFUSERNAME = "hdfUsername";
public static final String HDFPAZWRD = "hdfPassword";
public static final String CDFUSERNAME = "cdfUsername";
public static final String CDFPASSWORD = "cdfPassword";
public static final String TESTONCDF = "testOnCdf";
public static final String CDFURL = "cdfurl";
public static final String WRANGLER_CONNECTIONS_URL = "cdfConnectionsUrl";
public static final String TESTONHDF = "testOnHdf";
Expand Down Expand Up @@ -93,4 +96,9 @@ public class ConstantsUtil {
* PIPELINE_RUN_TIMEOUT_SECONDS: To be used as a timeout for Pipeline Runs
*/
public static final int PIPELINE_RUN_TIMEOUT_SECONDS = 900;

/**
* MEDIUM_TIMEOUT_SECONDS: To be used as a wait for retry
*/
public static final int MEDIUM_TIMEOUT_SECONDS = 10;
}
25 changes: 25 additions & 0 deletions src/main/java/io/cdap/e2e/utils/ElementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ public static void clickIfDisplayed(By locator) {
clickIfDisplayed(locator, ConstantsUtil.SMALL_TIMEOUT_SECONDS);
}

/**
* Click on the WebElement if it was displayed within a small timeout: {@link ConstantsUtil#SMALL_TIMEOUT_SECONDS}
*
* If the next element which we are waiting for to be displayed is not displayed yet that means we were not able to
* click on the desired element, so we will retry to click on the element we wanted to click on.
*
* @param locatorToClick Locator of the WebElement we want to click on.
* @param timeOutInSeconds small timeout to wait before clicking.
* @param locatorToWaitFor Locator of the WebElement we want to be displayed next.
*/
public static void clickIfDisplayed(By locatorToClick, long timeOutInSeconds, By locatorToWaitFor) {
clickIfDisplayed(locatorToClick, timeOutInSeconds);

// If the next webElement is not displayed we will click on the desired element again.
if (!isElementDisplayed(locatorToWaitFor, timeOutInSeconds)) {
logger.info("Retry : Click on " + locatorToClick);
clickIfDisplayed(locatorToClick);

// Checking if the next webElement is displayed.
if (isElementDisplayed(locatorToWaitFor, timeOutInSeconds)) {
logger.info("Element " + locatorToWaitFor + " is displayed.");
}
}
}

/**
* Send keys to a WebElement
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/stepsdesign/PipelineSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void waitForPipelineToBeInStatus(String pipelineStatus, long timeoutInSec
}

@Then("Wait till pipeline is in running state")
public void waitTillPipelineIsInRunningState() {
public void waitTillPipelineIsInRunningState() throws InterruptedException, IOException {
CdfPipelineRunAction.waitTillPipelineRunCompletes();
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/connectionParameters.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ testOnHdf=false
hdfUsername=cdap
hdfPassword=cdap123

testOnCdf=false
cdfUsername=dummy
cdfPassword=dummy

screenshotForAllSteps=false
testAccountName=CloudDataFution Automation

# properties to be removed-start
Project-ID=cdf-athena
Expand Down

0 comments on commit 3bcdf98

Please sign in to comment.