Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameSpace Admin page locators actions and step definition addition. #225

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions src/main/java/io/cdap/e2e/pages/actions/CdfNameSpaceAdminActions.java
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same method already exists here:

public static void enterKeyValuePairsForProperty(String pluginProperty, String jsonKeyValuePairs) {

Please avoid code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-08-31 at 19 10 56 Screenshot 2023-08-31 at 19 13 10

Ankit , here the locators are different . The method which is present inside cdfPluginPropertiesActions is pointing to setting runtime arguments for a deployed pipline whereas my method is pointing to setting preferences inside namespace admin . The key and value tabs which are present here does not work with the old locators .

String dataCyAttribute = PluginPropertyUtils.getPluginPropertyDataCyAttribute(
preferenceProperty);
if (dataCyAttribute == null) {
dataCyAttribute = preferenceProperty;
}
Map<String, String> properties =
JsonUtils.convertKeyValueJsonArrayToMap(PluginPropertyUtils.pluginProp(keyValuePair));
int index = 0;
for (Map.Entry<String, String> 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++;
}
Comment on lines +85 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data-cy attributes are specific to tests written using cypress. Prefer using using a custom data- attribute for this action.

}

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name seems to indicate that this method checks if any given element is displayed, where as it actually checks if the page header is displayed or not. Consider changing the method name to reflect its actual behavior.

ElementHelper.isElementDisplayed(CdfNameSpaceAdminLocators.pageHeaderNameSpaceAdmin);
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please get a review on locators class from @GnsP from UI team.


@FindBy(how = How.XPATH, using = "//div[contains(text(),'Namespace Admin')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding elements using text / copy is generally not a good idea, as copy may change based on product requirements and this may result in breaking tests across multiple projects (as this locator is in the e2e framework). Prefer using a data-testid for locating elements.

public static WebElement namespaceAdminMenu;

@FindBy(how = How.XPATH, using = "//*[@data-cy='navbar-hamburger-icon']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy

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']";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy

return SeleniumDriver.getDriver().findElement(By.xpath(xpath));
}

public static WebElement locateValueProperty(String valueProperty, int row) {
String xpath = "//*[@data-cy='" + valueProperty + "" + row + "']//input[@placeholder='value']";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy

return SeleniumDriver.getDriver().findElement(By.xpath(xpath));
}

public static WebElement locateAddRowButtonProperty(String addRowProperty, int row) {
String xpath =
"//*[@data-cy='" + addRowProperty + "" + row + "']//span"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy

+ "//button[@type='submit' and @class='btn add-row-btn btn-link']";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locating elements using class names is not a good idea, as it prevents the UI developers from changing the design / implementation of the specific UI elements. Prefer data-testids for locating elements.

return SeleniumDriver.getDriver().findElement(By.xpath(xpath));
}

@FindBy(how = How.XPATH, using = "//*[@class='namespace-dropdown']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locating elements using class names is not a good idea, as it prevents the UI developers from changing the design / implementation of the specific UI elements. Prefer data-testids for locating elements.

public static WebElement namespaceDropdown;

@FindBy(how = How.XPATH, using = "//div[contains(text(),'Add Namespace')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements using text content is not a good idea, as text can change based on product requirements.

public static WebElement addNamespace;

@FindBy(how = How.XPATH, using = "//button[@data-cy='wizard-next-btn']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.

public static WebElement clickOnNextButton;

@FindBy(how = How.XPATH, using = "//button[@data-cy='wizard-finish-btn']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.

public static WebElement clickOnFinishButton;

public static WebElement locateKeyProperty(int row) {
String xpath = "//*[@data-cy= 'key-value-pair-" + row + "']//input[@placeholder='key']";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.
Also locating elements based on the text of the placeholder value is not a good idea.

return SeleniumDriver.getDriver().findElement(By.xpath(xpath));
}

public static WebElement locateValueProperty(int row) {
String xpath = "//*[@data-cy= 'key-value-pair-" + row + "']//input[@placeholder='value']";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.
Also locating elements based on the text of the placeholder value is not a good idea.

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 " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using data-testid to locate the element. This locator is tightly coupled with the DOM structure, which prevents the UI developers from changing the UI without breaking tests.

"@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 + "']"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.

}

public static WebElement locateButtonType(String buttonType) {
return SeleniumDriver.getDriver()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.

.findElement(By.xpath("//button[@data-cy='" + buttonType + "']"));
}

public static By profilePropertiesPage() {
return By.xpath("//h5[contains(text(), 'Create a profile')]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

}

public static By locateProfileTitle(String profileName) {
return By.xpath("//div[@title='" + profileName + "']");
}

@FindBy(how = How.XPATH, using = "//a[contains(text(),\"Switch to\")]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement switchToCreatedNamespace;

@FindBy(how = How.XPATH, using = "//a[contains(text(),'Go to homepage')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement goToHomepage;

@FindBy(how = How.XPATH, using = "//*[@data-cy='wizard-result-icon-close-btn']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over data-cy.

public static WebElement closeAddNameSpaceWindow;

@FindBy(how = How.XPATH, using = "//span[@id='setpreferences-fd']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer data-testid over id, as it indicates that the testid is used in e2e tests and should not be changed.

public static WebElement setPreferencesfromMainMenu;

@FindBy(how = How.XPATH, using = "//span[contains(text(),'Upload Driver')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement uploadDriverTab;

@FindBy(how = How.XPATH, using = "//*[contains(@class,'close')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on css classes is not a good idea, as explained in other comments.

public static WebElement closeUploadDriverWindow;

@FindBy(how = How.XPATH, using = "//span[contains(text(),'Link Repository')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments. Also, this breaks with i18n.

public static WebElement linkRepositoryTab;

@FindBy(how = How.XPATH, using = "//button[@class=\"MuiButtonBase-root MuiIconButton-root\"]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on css classes is not a good idea, as explained in other comments.

public static WebElement closeExternalPage;

@FindBy(how = How.XPATH, using = "//span[contains(text(),'Add Connection')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement addConnectionTab;

@FindBy(how = How.XPATH, using = "//span[contains(text(),'Import')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement importConnectionTab;

@FindBy(how = How.XPATH, using = "//span[contains(text(),'Create Profile')]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement createProfileInNamespaceAdmin;

@FindBy(how = How.XPATH, using = "//a[contains(text(),\"Switch to\")]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement switchToNameSpaceButton;

@FindBy(how = How.XPATH, using = "//div[@class=\"namespace-and-caret\"]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on css classes is not a good idea, as explained in other comments.

public static WebElement namespaceText;

@FindBy(how = How.XPATH, using = "//*[@data-cy='feature-heading'][//div[contains(text(),'Namespace')]]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locating elements based on text content is not a good idea, as explained in other comments.

public static WebElement pageHeaderNameSpaceAdmin;
}

88 changes: 88 additions & 0 deletions src/main/java/stepsdesign/NameSpaceadminSteps.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading