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 037032d5 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC Committed by Mihai BOZ
Browse files

Pull request #35: Add keystore import test example with mat-select

Merge in EDELIVERY/smp from EDELIVERY-12010-mat-select to development

* commit 'bfc2c210':
  Add keystore import example with mat-select
parents 22e314eb bfc2c210
Branches EDELIVERY-12010-smp-automation-related-improvements
No related tags found
No related merge requests found
Pipeline #103223 failed
package ddsl.dcomponents;
import ddsl.dcomponents.mat.MatSelect;
import ddsl.dobjects.DButton;
import ddsl.dobjects.DInput;
import ddsl.dobjects.DSelect;
......@@ -11,7 +12,7 @@ import utils.TestRunData;
public class DComponent {
/**
* Generic component which which gives access of driver, wait and wrappers of elements. This should be inhered by each component class.
* Generic component which gives access of driver, wait and wrappers of elements. This should be inhered by each component class.
*/
public DWait wait;
......@@ -35,4 +36,8 @@ public class DComponent {
return new DSelect(driver, element);
}
protected MatSelect weToMatSelect(WebElement element) {
return new MatSelect(driver, element);
}
}
package ddsl.dcomponents.mat;
import ddsl.dobjects.DObject;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.UnexpectedTagNameException;
public class MatSelect extends DObject {
public MatSelect(WebDriver driver, WebElement element) {
super(driver, element);
String tagName = element.getTagName();
if (null != tagName && StringUtils.equalsIgnoreCase("mat-select", tagName)) {
this.element = element;
} else {
throw new UnexpectedTagNameException("mat-select", tagName);
}
}
public void selectByVisibleText(String value) {
element.click();
WebElement option = element.findElement(By.xpath("//mat-option/span[contains(text(),'" + value + "')]"));
wait.forElementToBeVisible(option);
option.click();
}
}
......@@ -9,10 +9,12 @@ import org.openqa.selenium.support.PageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the page object for the Keystore import dialog. It contains the WebElements and the methods specific to the dialog.
*
*/
public class KeyStoreImportDialog extends DComponent {
/**
* This is the page object for the Keystore import dialog. It contains the webelements and the methods specific to the dialog.
*/
private final static Logger LOG = LoggerFactory.getLogger(KeyStoreImportDialog.class);
@FindBy(id = "keystore-file-upload")
......@@ -29,13 +31,12 @@ public class KeyStoreImportDialog extends DComponent {
public KeyStoreImportDialog(WebDriver driver) {
super(driver);
PageFactory.initElements(driver, this);
}
public void addCertificate(String filepath, KeyStoreTypes keyStoreTypes, String password) {
try {
importKeyStoreInput.sendKeys(filepath);
weToDSelect(keyStoreTypeDdl).selectValue(keyStoreTypes.toString());
weToMatSelect(keyStoreTypeDdl).selectByVisibleText(keyStoreTypes.toString());
weToDInput(passwordIdInput).fill(password);
} catch (Exception e) {
......
package utils;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FileUtils {
private static final Path keystoreFolder = Paths.get("src", "main", "resources", "keystore");
public static String getAbsolutePath(String relativePath) {
return new File(relativePath).getAbsolutePath();
}
/**
* Returns the absolute path of the keystore file in the keystore folder
*
* @param keystoreFileName the name of the keystore file
* @return the absolute path of the keystore file
*/
public static String getAbsoluteKeystorePath(String keystoreFileName) {
return keystoreFolder.resolve(keystoreFileName).toAbsolutePath().toString();
}
}
package domiSMPTests.ui;
import ddsl.DomiSMPPage;
import ddsl.enums.KeyStoreTypes;
import ddsl.enums.Pages;
import domiSMPTests.SeleniumTest;
import org.testng.annotations.BeforeClass;
......@@ -35,16 +36,47 @@ public class KeystorePgTests extends SeleniumTest {
keystorePage = homePage.getSidebar().navigateTo(Pages.SYSTEM_SETTINGS_KEYSTORE);
}
//TODO: wait until the mat-select for certificate type is changed to select
@Test(description = "KEYS-02 System admin is able to import PKCS 12 Keystore")
public void SystemAdminIsAbleToImportPKCS12() throws Exception {
String path = FileUtils.getAbsolutePath("./src/main/resources/keystore/expired_keystore_JKS.jks");
@Test(description = "KEYS-02 System admin is able to import JKS Keystore")
public void systemAdminIsAbleToImportJKS() throws Exception {
String path = FileUtils.getAbsoluteKeystorePath("expired_keystore_JKS.jks");
KeyStoreImportDialog keyStoreImportDialog = keystorePage.clickImportkeyStoreBtn();
//keyStoreImportDialog.addCertificate(path, KeyStoreTypes.JKS, "test123");
//keyStoreImportDialog.clickImport();
keyStoreImportDialog.addCertificate(path, KeyStoreTypes.JKS, "test1234");
keyStoreImportDialog.clickImport();
String value = keystorePage.getAlertArea().getAlertMessage();
sofAssertThatContains("Certificates added [blue_gw", value);
soft.assertAll();
}
@Test(description = "KEYS-xx Wrong keystore type")
public void systemAdminImportFailedWithWrongKeystoreType() throws Exception {
String path = FileUtils.getAbsoluteKeystorePath("expired_keystore_JKS.jks");
KeyStoreImportDialog keyStoreImportDialog = keystorePage.clickImportkeyStoreBtn();
keyStoreImportDialog.addCertificate(path, KeyStoreTypes.PKCS12, "test1234");
keyStoreImportDialog.clickImport();
String value = keystorePage.getAlertArea().getAlertMessage();
sofAssertThatContains("Error occurred while importing keystore", value);
soft.assertAll();
}
@Test(description = "KEYS-xx Wrong keystore password")
public void systemAdminImportFailedWithWrongPassword() throws Exception {
String path = FileUtils.getAbsoluteKeystorePath("expired_keystore_JKS.jks");
KeyStoreImportDialog keyStoreImportDialog = keystorePage.clickImportkeyStoreBtn();
keyStoreImportDialog.addCertificate(path, KeyStoreTypes.JKS, "wrongPassword");
keyStoreImportDialog.clickImport();
String value = keystorePage.getAlertArea().getAlertMessage();
sofAssertThatContains("Error occurred while importing keystore", value);
soft.assertAll();
}
private void sofAssertThatContains(String contains, String value) {
soft.assertTrue(value.contains(contains), "Expected to contain: ["+contains+"] but the value was: ["+value+"]");
}
}
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