Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit bdb56281 authored by Mihai BOZ's avatar Mihai BOZ Committed by Ahmed GHOUILI
Browse files

Pull request #27: added classes required for test PROF-03 Password validation...

Pull request #27: added classes required for test PROF-03 Password validation is accord to the smp propeties values.

Merge in EDELIVERY/smp from EDELIVERY-11049-start_preparing_the_testing_framework_ to development

* commit 'b899bc1a':
  added classes required for test PROF-03 Password validation is accord to the smp propeties values.
parents 551478bf b899bc1a
No related branches found
No related tags found
No related merge requests found
Pipeline #69999 passed with warnings
Showing with 408 additions and 5 deletions
package ddsl.dcomponents;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ConfirmationDialog extends DComponent {
private final static Logger LOG = LoggerFactory.getLogger(ConfirmationDialog.class);
@FindBy(id = "yesbuttondialog_id")
private WebElement yesBtn;
@SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "nobuttondialog_id")
private WebElement noBtn;
public ConfirmationDialog(WebDriver driver) {
super(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this);
}
public void confirm() {
LOG.info("dialog .. confirm");
wait.forElementToBeClickable(yesBtn);
yesBtn.click();
wait.forElementToBeClickable(yesBtn);
}
public void cancel() {
LOG.info("dialog .. cancel");
wait.forElementToBeClickable(noBtn);
noBtn.click();
wait.forElementToBeGone(noBtn);
}
}
package ddsl.dcomponents.Grid;
import ddsl.dcomponents.DComponent;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
public class BasicGrid extends DComponent {
private final static Logger LOG = LoggerFactory.getLogger(BasicGrid.class);
@FindBy(css = "datatable-header div.datatable-row-center datatable-header-cell")
protected List<WebElement> gridHeaders;
@FindBy(css = "datatable-body-row > div.datatable-row-center.datatable-row-group")
protected List<WebElement> gridRows;
protected ArrayList<String> headerTxt = new ArrayList<String>();
public BasicGrid(WebDriver driver, WebElement container) {
super(driver);
LOG.info("Loading basic grid");
wait.forXMillis(500);
PageFactory.initElements(new DefaultElementLocatorFactory(container), this);
for (int i = 0; i < gridHeaders.size(); i++) {
headerTxt.add(gridHeaders.get(i).getText().trim());
}
}
public void selectRow(int rowNumber) {
LOG.info("selecting row with number ... " + rowNumber);
wait.forXMillis(500);
if (rowNumber >= gridRows.size()) {
return;
}
gridRows.get(rowNumber).click();
wait.forXMillis(500);
}
public void doubleClickRow(String propertyName) {
gridRows.forEach(row -> {
if (row.getText().startsWith(propertyName)) {
Actions action = new Actions(driver);
action.doubleClick(row).perform();
}
}
);
wait.forXMillis(500);
}
public void doubleClickRow(int rowNumber) {
LOG.info("double clicking row ... " + rowNumber);
wait.forXMillis(500);
if (rowNumber >= gridRows.size()) {
return;
}
Actions action = new Actions(driver);
action.doubleClick(gridRows.get(rowNumber)).perform();
}
public int getColumnsNo() {
LOG.info("getting number of columns");
return gridHeaders.size();
}
public int getRowsNo() {
return gridRows.size();
}
public void scrollRow(int index) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", gridRows.get(index));
wait.forXMillis(500);
}
}
package ddsl.dcomponents;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
public class SetChangePasswordDialog extends DComponent {
private final static Logger LOG = LoggerFactory.getLogger(SetChangePasswordDialog.class);
@FindBy(css = ".smp-field-error")
List<WebElement> fieldsError;
@FindBy(id = "cp_id")
private WebElement currentPasswordInput;
@SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "np_id")
private WebElement newPasswordInput;
@FindBy(id = "cnp_id")
private WebElement confirmationPasswordInput;
@FindBy(id = "cnp_id")
private WebElement setPasswordBtn;
@FindBy(id = "cnp_id")
private WebElement closeBtn;
public SetChangePasswordDialog(WebDriver driver) {
super(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this);
}
public boolean trySetPassword(String currentPassword, String newPassword) throws Exception {
LOG.info("Set new password");
weToDInput(currentPasswordInput).fill(currentPassword);
weToDInput(newPasswordInput).fill(newPassword);
weToDInput(confirmationPasswordInput).fill(newPassword);
Integer hasError;
if (weToDButton(setPasswordBtn).isEnabled() && fieldsError.size() < 1) {
weToDButton(setPasswordBtn).click();
return true;
}
{
getFieldErrorMessage().forEach(LOG::error);
return false;
}
}
public List<String> getFieldErrorMessage() {
ArrayList<String> fieldErrors = new ArrayList<>();
if (fieldsError.size() > 0) {
fieldsError.forEach(error -> {
fieldErrors.add(error.getText());
});
}
return fieldErrors;
}
}
......@@ -11,6 +11,7 @@ import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pages.ProfilePage;
import pages.PropertiesPage.PropertiesPage;
import java.util.Objects;
......@@ -125,9 +126,11 @@ public class SideNavigationComponent extends DomiSMPPage {
// case SYSTEM_SETTINGS_EXTENSIONS:
// expandSection(systemSettingsExpand);
// return new DLink(driver, extensionsLnk);
// case SYSTEM_SETTINGS_PROPERTIES:
// expandSection(systemSettingsExpand);
// return new DLink(driver, propertiesLnk);
if (page == Pages.SYSTEM_SETTINGS_PROPERTIES) {
openSubmenu(systemSettingsExpand, propertiesLnk);
return new PropertiesPage(driver);
}
// case SYSTEM_SETTINGS_ALERS:
// expandSection(systemSettingsExpand);
// return new DLink(driver, alersLnk);
......
package pages;
import ddsl.dcomponents.DomiSMPPage;
import ddsl.dcomponents.SetChangePasswordDialog;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
......@@ -26,6 +27,8 @@ public class ProfilePage extends DomiSMPPage {
private WebElement emailAddressInput;
@FindBy(id = "fullName_id")
private WebElement fullNameInput;
@FindBy(id = "changePassword_id")
private WebElement setChangePasswordBtn;
public ProfilePage(WebDriver driver) {
super(driver);
......@@ -66,6 +69,11 @@ public class ProfilePage extends DomiSMPPage {
}
public Boolean tryChangePassword(String currentPasssword, String newPassword) throws Exception {
weToDButton(setChangePasswordBtn).click();
SetChangePasswordDialog dialog = new SetChangePasswordDialog(driver);
return dialog.trySetPassword(currentPasssword, newPassword);
}
public String getSelectedTheme() {
return weToDSelect(themeSel).getCurrentValue();
......
package pages.PropertiesPage;
import ddsl.dcomponents.Grid.BasicGrid;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class PropGrid extends BasicGrid {
public PropGrid(WebDriver driver, WebElement container) {
super(driver, container);
}
public PropertyPopup selectValue(String propertyValue) {
this.doubleClickRow(propertyValue);
return new PropertyPopup(driver);
}
;
}
package pages.PropertiesPage;
import ddsl.dcomponents.ConfirmationDialog;
import ddsl.dcomponents.DomiSMPPage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PropertiesPage extends DomiSMPPage {
private final static Logger LOG = LoggerFactory.getLogger(PropertiesPage.class);
@FindBy(id = "searchTable")
private WebElement propertyTableContainer;
@FindBy(id = "cancelButton")
private WebElement cancelBtn;
@FindBy(id = "saveButton")
private WebElement saveBtn;
@FindBy(id = "editButton")
private WebElement editBtn;
@FindBy(id = "searchProperty")
private WebElement searchPropertyField;
@FindBy(id = "searchbutton_id")
private WebElement searchBtn;
public PropertiesPage(WebDriver driver) {
super(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this);
}
public PropGrid grid() {
return new PropGrid(driver, propertyTableContainer);
}
public void propertySearch(String propertyname) {
LOG.info("Search for property");
wait.forElementToBeVisible(searchPropertyField).sendKeys(propertyname);
wait.forElementToBeClickable(searchBtn).click();
}
public void setPropertyValue(String propertyName, String propertyValue) {
PropertyPopup popup = grid().selectValue(propertyName);
popup.editInputField(propertyValue);
try {
popup.clickOK();
} catch (Exception e) {
LOG.error("Cannot set value for property {1}", propertyName);
}
}
public void save() throws Exception {
weToDButton(saveBtn).click();
ConfirmationDialog confirmationDialog = new ConfirmationDialog(driver);
confirmationDialog.confirm();
}
}
package pages.PropertiesPage;
import ddsl.dcomponents.DComponent;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PropertyPopup extends DComponent {
private final static Logger LOG = LoggerFactory.getLogger(PropertiesPage.class);
@FindBy(id = "updatePropertyButton")
WebElement popupOkBtn;
@FindBy(css = "mat-dialog-actions button:nth-of-type(2)")
WebElement popupCancelBtn;
@FindBy(css = "span.mat-checkbox-inner-container input")
WebElement propertyCheckbox;
@FindBy(css = "property-details-dialog input")
WebElement propertryEditInput;
public PropertyPopup(WebDriver driver) {
super(driver);
PageFactory.initElements(driver, this);
}
public boolean isOKButtonActive() {
try {
return weToDButton(popupOkBtn).isEnabled();
} catch (Exception e) {
LOG.error("Element is not visible", e);
return false;
}
}
public boolean isCancelButtonActive() {
try {
return weToDButton(popupCancelBtn).isEnabled();
} catch (Exception e) {
LOG.error("Element is not visible", e);
return false;
}
}
public PropertiesPage clickOK() throws Exception {
LOG.info("click OK");
wait.forElementToBeClickable(popupOkBtn);
weToDButton(popupOkBtn).click();
wait.forElementToBeGone(popupOkBtn);
return new PropertiesPage(driver);
}
public PropertiesPage clickCancel() {
LOG.info("click cancel");
wait.forElementToBeClickable(popupCancelBtn);
popupCancelBtn.click();
wait.forElementToBeGone(popupCancelBtn);
return new PropertiesPage(driver);
}
public PropertiesPage enableCheckboxOfProperty() {
Boolean bool = propertyCheckbox.isSelected();
if (bool == false) {
propertyCheckbox.click();
popupOkBtn.click();
} else {
popupCancelBtn.click();
}
return new PropertiesPage(driver);
}
public PropertiesPage disableCheckboxOfProperty() {
Boolean bool = propertyCheckbox.isSelected();
if (bool == true) {
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", propertyCheckbox);
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
popupOkBtn.click();
} else {
popupCancelBtn.click();
}
return new PropertiesPage(driver);
}
public void editInputField(String string) {
propertryEditInput.clear();
propertryEditInput.sendKeys(string);
}
}
......@@ -7,6 +7,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import pages.LoginPage;
import pages.ProfilePage;
import pages.PropertiesPage.PropertiesPage;
import rest.models.UserModel;
......@@ -16,7 +17,7 @@ public class ProfilePgTests extends SeleniumTest {
* This class has the tests against Profile Page
*/
@Test(description = "PROF-01")
public void AllLoggedUsersAreAbleToSeeProfilePage() throws Exception {
public void AllLoggedUsersShouldAbleToSeeProfilePage() throws Exception {
UserModel normalUser = UserModel.createUserWithUSERrole();
rest.users().createUser(normalUser);
......@@ -52,7 +53,7 @@ public class ProfilePgTests extends SeleniumTest {
}
@Test(description = "PROF-02")
public void AllLoggedUsersAreAbleToUpdateProfilePage() throws Exception {
public void AllLoggedUsersShouldAbleToUpdateProfilePage() throws Exception {
UserModel normalUser = UserModel.createUserWithUSERrole();
rest.users().createUser(normalUser);
......@@ -101,4 +102,24 @@ public class ProfilePgTests extends SeleniumTest {
}
@Test(description = "PROF-03")
public void PasswordValidationsShouldBeAccordingToPropertiesValue() throws Exception {
UserModel adminUser = UserModel.createUserWithADMINrole();
rest.users().createUser(adminUser);
DomiSMPPage homePage = new DomiSMPPage(driver);
LoginPage loginPage = homePage.goToLoginPage();
loginPage.login(adminUser.getUsername(), data.getNewPassword());
PropertiesPage propertiesPage = (PropertiesPage) homePage.getSidebar().navigateTo(Pages.SYSTEM_SETTINGS_PROPERTIES);
propertiesPage.propertySearch("smp.passwordPolicy.validationRegex");
propertiesPage.setPropertyValue("smp.passwordPolicy.validationRegex", "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~`!@#$%^&+=\\-_<>.,?:;*/()|\\[\\]{}'\"\\\\]).{16,35}$");
propertiesPage.save();
ProfilePage profilePage = (ProfilePage) propertiesPage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
Boolean isPasswordChanged = profilePage.tryChangePassword(data.getNewPassword(), "Edeltest!23456789Edeltest!234567890");
Assert.assertTrue(isPasswordChanged);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment