diff --git a/smp-ui-tests/pom.xml b/smp-ui-tests/pom.xml index a4fb20c3e49ea18e52b967a527395bb508fd9bce..5b67a087a2eac1036139030774bfb29ec5d0fcbe 100644 --- a/smp-ui-tests/pom.xml +++ b/smp-ui-tests/pom.xml @@ -1,138 +1,142 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <groupId>com.test.smp</groupId> - <artifactId>SMPUIAutomation</artifactId> - <version>1.0-SNAPSHOT</version> + <groupId>com.test.smp</groupId> + <artifactId>SMPUIAutomation</artifactId> + <version>1.0-SNAPSHOT</version> - <properties> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> - <url>http://localhost:8080/smp</url> - <gecko.driver.path>drivers/geckodriver.exe</gecko.driver.path> - <chrome.driver.path>drivers/chromedriver.exe</chrome.driver.path> - </properties> + <properties> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + <url>http://localhost:8982/smp</url> + <gecko.driver.path>drivers/geckodriver</gecko.driver.path> + <chrome.driver.path>drivers/chromedriver</chrome.driver.path> + </properties> - <dependencies> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.17</version> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>7.0.0-beta1</version> - </dependency> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>selenium-java</artifactId> - <version>3.14.0</version> - </dependency> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi-ooxml</artifactId> - <version>3.17</version> - </dependency> - <dependency> - <groupId>org.reflections</groupId> - <artifactId>reflections</artifactId> - <version>0.9.11</version> - </dependency> - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <version>20080701</version> - </dependency> + <dependencies> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.17</version> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>7.0.0-beta1</version> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-java</artifactId> + <version>3.14.0</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml</artifactId> + <version>3.17</version> + </dependency> + <dependency> + <groupId>org.reflections</groupId> + <artifactId>reflections</artifactId> + <version>0.9.11</version> + </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20080701</version> + </dependency> - <dependency> - <groupId>com.thoughtworks.xstream</groupId> - <artifactId>xstream</artifactId> - <version>1.4.10</version> - </dependency> + <dependency> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.4.10</version> + </dependency> - <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-client</artifactId> - <version>1.19.4</version> - </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-client</artifactId> + <version>1.19.4</version> + </dependency> + <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.11.0</version> + </dependency> - </dependencies> - <profiles> - <profile> - <id>smp_e5</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <build> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.22.1</version> - <configuration> - <failIfNoTests>true</failIfNoTests> - <systemPropertyVariables> - <webdriver.chrome.driver>${chrome.driver.path}</webdriver.chrome.driver> - <webdriver.gecko.driver>chromedriver.exe</webdriver.gecko.driver> - <reports.folder>./target/</reports.folder> - <data.folder>.\src\main\resources\</data.folder> - <testdata.file>testData.json</testdata.file> - <LONG_TIMEOUT>30</LONG_TIMEOUT> - <SHORT_TIMEOUT>5</SHORT_TIMEOUT> - <UI_BASE_URL>${url}/ui/</UI_BASE_URL> - </systemPropertyVariables> - <properties> - <property> - <name>usedefaultlisteners</name> - <value>true</value> - </property> - </properties> - </configuration> - </plugin> - </plugins> - </build> - </profile> - <profile> - <id>ubuntu</id> - <activation> - <activeByDefault>false</activeByDefault> - </activation> - <build> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.22.1</version> - <configuration> - <failIfNoTests>true</failIfNoTests> - - <systemPropertyVariables> - <webdriver.chrome.driver>${chrome.driver.path}</webdriver.chrome.driver> - <reports.folder>./target/</reports.folder> - <data.folder>./src/main/resources/</data.folder> - <testdata.file>testData.json</testdata.file> - <LONG_TIMEOUT>30</LONG_TIMEOUT> - <SHORT_TIMEOUT>15</SHORT_TIMEOUT> - <UI_BASE_URL>${url}/ui/</UI_BASE_URL> - </systemPropertyVariables> - <properties> - <property> - <name>usedefaultlisteners</name> - <value>true</value> - </property> - </properties> - </configuration> - </plugin> - </plugins> - </build> - </profile> - - </profiles> + </dependencies> + <profiles> + <profile> + <id>smp_e5</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.1</version> + <configuration> + <failIfNoTests>true</failIfNoTests> + <systemPropertyVariables> + <webdriver.chrome.driver>${chrome.driver.path}</webdriver.chrome.driver> + <webdriver.gecko.driver>chromedriver.exe</webdriver.gecko.driver> + <reports.folder>./target/</reports.folder> + <data.folder>./src/main/resources/</data.folder> + <testdata.file>testData.json</testdata.file> + <LONG_TIMEOUT>30</LONG_TIMEOUT> + <SHORT_TIMEOUT>5</SHORT_TIMEOUT> + <UI_BASE_URL>${url}/ui/</UI_BASE_URL> + </systemPropertyVariables> + <properties> + <property> + <name>usedefaultlisteners</name> + <value>true</value> + </property> + </properties> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>ubuntu</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.1</version> + <configuration> + <failIfNoTests>true</failIfNoTests> + <systemPropertyVariables> + <webdriver.chrome.driver>${chrome.driver.path}</webdriver.chrome.driver> + <reports.folder>./target/</reports.folder> + <data.folder>./src/main/resources/</data.folder> + <testdata.file>testData.json</testdata.file> + <LONG_TIMEOUT>30</LONG_TIMEOUT> + <SHORT_TIMEOUT>15</SHORT_TIMEOUT> + <UI_BASE_URL>${url}/ui/</UI_BASE_URL> + </systemPropertyVariables> + <properties> + <property> + <name>usedefaultlisteners</name> + <value>true</value> + </property> + </properties> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> \ No newline at end of file diff --git a/smp-ui-tests/src/main/java/pages/components/ConfirmationDialog.java b/smp-ui-tests/src/main/java/pages/components/ConfirmationDialog.java index c3f5c709ad733c94c8c8ca0b4f6f92dad9a4a605..8a14f470c27c0edeffedc6f5195c9883c0abf383 100644 --- a/smp-ui-tests/src/main/java/pages/components/ConfirmationDialog.java +++ b/smp-ui-tests/src/main/java/pages/components/ConfirmationDialog.java @@ -1,9 +1,7 @@ package pages.components; -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.AjaxElementLocatorFactory; @@ -13,32 +11,28 @@ import utils.PROPERTIES; public class ConfirmationDialog extends PageComponent { - public ConfirmationDialog(WebDriver driver) { - super(driver); - PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - } - @SuppressWarnings("SpellCheckingInspection") @FindBy(id = "yesbuttondialog_id") private WebElement yesBtn; - @SuppressWarnings("SpellCheckingInspection") @FindBy(id = "nobuttondialog_id") private WebElement noBtn; - public void confirm(){ + public ConfirmationDialog(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + } + + public void confirm() { log.info("dialog .. confirm"); waitForElementToBeClickable(yesBtn); yesBtn.click(); waitForElementToBeGone(yesBtn); } - public void cancel(){ + public void cancel() { log.info("dialog .. cancel"); waitForElementToBeClickable(noBtn); -/* Actions actions = new Actions(driver); - actions.moveToElement(noBtn).click().build().perform();*/ - //((JavascriptExecutor) driver).executeScript("arguments[0].click();", noBtn); noBtn.click(); waitForElementToBeGone(noBtn); } diff --git a/smp-ui-tests/src/main/java/pages/components/GenericSelect.java b/smp-ui-tests/src/main/java/pages/components/GenericSelect.java index 8382a2b76219f1e5213aa678fbc6330d8270c8d0..2075bc26f27148bfd47f14d82d71a7c07602a1ac 100644 --- a/smp-ui-tests/src/main/java/pages/components/GenericSelect.java +++ b/smp-ui-tests/src/main/java/pages/components/GenericSelect.java @@ -14,38 +14,36 @@ import java.util.List; public class GenericSelect extends PageComponent { + @FindBy(className = "mat-select-arrow") + WebElement expandoButton; + @FindBy(css = "div.mat-select-value span") + WebElement currentValueElement; + private WebElement container; + private By optionSelector = By.tagName("mat-option"); + public GenericSelect(WebDriver driver, WebElement container) { super(driver); log.info("select init"); this.container = container; - + PageFactory.initElements(new DefaultElementLocatorFactory(container), this); } - private WebElement container; - - @FindBy(className = "mat-select-arrow") - WebElement expandoButton; - - @FindBy(css = "div.mat-select-value span") - WebElement currentValueElement; - - private By optionSelector = By.tagName("mat-option"); - - - private void expandSelect(){ + private void expandSelect() { log.info("expand select"); - waitForElementToBeClickable(expandoButton).click(); + waitForElementToBeClickable(expandoButton); + waitForXMillis(500); + expandoButton.click(); } - private List<WebElement> getOptions(){ + private List<WebElement> getOptions() { expandSelect(); log.info("getting options"); return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(optionSelector)); } - public List<String> getOptionTexts(){ + public List<String> getOptionTexts() { log.info("get displayed option texts"); List<WebElement> options = getOptions(); List<String> optionTexts = new ArrayList<>(); @@ -56,13 +54,13 @@ public class GenericSelect extends PageComponent { return optionTexts; } - public boolean selectOptionWithText(String text){ + public boolean selectOptionWithText(String text) { log.info("selecting option with text" + text); List<WebElement> options = getOptions(); for (WebElement option : options) { - if(option.getText().trim().equalsIgnoreCase(text)){ + if (option.getText().trim().equalsIgnoreCase(text)) { waitForElementToBeClickable(option).click(); waitForElementToBeGone(option); log.info("return type is True"); @@ -73,7 +71,7 @@ public class GenericSelect extends PageComponent { return false; } - public boolean selectFirstOption(){ + public boolean selectFirstOption() { log.info("selecting first option"); List<WebElement> options = getOptions(); @@ -82,7 +80,8 @@ public class GenericSelect extends PageComponent { waitForElementToBeGone(option); return true; } - public boolean selectWithIndex(int index){ + + public boolean selectWithIndex(int index) { log.info("selecting the required option"); List<WebElement> options = getOptions(); @@ -93,7 +92,6 @@ public class GenericSelect extends PageComponent { } - public String getSelectedValue() { log.info("getting current selected value"); return currentValueElement.getText().trim(); @@ -107,20 +105,22 @@ public class GenericSelect extends PageComponent { List<WebElement> options = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(optionSelector)); for (WebElement option : options) { String optionDomain = option.getText().trim(); - if(optionDomain.equalsIgnoreCase(text)){ + if (optionDomain.equalsIgnoreCase(text)) { option.click(); waitForElementToBeGone(option); return true; } } - log.info(text + " option not found, could not select it (2)" ); + log.info(text + " option not found, could not select it (2)"); return false; } public boolean isLoaded() { log.info("assert loaded state"); waitForElementToBeVisible(expandoButton); - if(!expandoButton.isDisplayed()){ return false;} + if (!expandoButton.isDisplayed()) { + return false; + } return currentValueElement.isDisplayed(); } } diff --git a/smp-ui-tests/src/main/java/pages/components/Sidebar.java b/smp-ui-tests/src/main/java/pages/components/Sidebar.java index 4364cdc909b4adf4de7070ee24f16092a9846b06..a4a7ba5b21bb62c76f4c5a627f6ee17d4ed57ee0 100644 --- a/smp-ui-tests/src/main/java/pages/components/Sidebar.java +++ b/smp-ui-tests/src/main/java/pages/components/Sidebar.java @@ -7,52 +7,40 @@ import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import pages.components.baseComponents.Header; -import pages.components.baseComponents.SMPPage; import pages.components.baseComponents.PageComponent; -import pages.service_groups.search.SearchPage; +import pages.components.baseComponents.SMPPage; import utils.PROPERTIES; -import java.security.PublicKey; -import java.util.List; - public class Sidebar extends PageComponent { - public Sidebar(WebDriver driver) { - super(driver); - PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - } - @SuppressWarnings("SpellCheckingInspection") @FindBy(tagName = "mat-sidenav") private WebElement sideBar; - private WebElement topLogo; private WebElement topLogoText; - @FindBy(id = "sidebar_search_id") private WebElement searchLnk; - @FindBy(id = "sidebar_edit_id") private WebElement editLnk; - @FindBy(id = "sidebar_domain_id") private WebElement domainLnk; - @FindBy(id = "sidebar_user_id") private WebElement userLnk; - @FindBy(id = "sidebar_property_id") private WebElement propertyLnk; - @FindBy(css = "mat-icon[role=img][mattooltip=Collapse]") private WebElement collapseButton; - @FindBy(xpath = "//button[@id='sidebar_search_id']//span[text()='Search']") private WebElement sidebarSearchText; + public Sidebar(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + } + /* Receives the Page object class as parameter and based on the class name it navigates to the appropriate page and returns an instance of that class */ - public <T extends SMPPage> T goToPage(Class<T> expect){ + public <T extends SMPPage> T goToPage(Class<T> expect) { log.info("Navigating to " + expect.getSimpleName()); switch (expect.getSimpleName()) { @@ -82,25 +70,31 @@ public class Sidebar extends PageComponent { return PageFactory.initElements(driver, expect); } - public boolean isSearchLnkEnabled(){ + public boolean isSearchLnkEnabled() { return isVisible(searchLnk) && isEnabled(searchLnk); } - public boolean isEditLnkEnabled(){ + + public boolean isEditLnkEnabled() { return isVisible(editLnk) && isEnabled(editLnk); } - public boolean isDomainLnkEnabled(){ + + public boolean isDomainLnkEnabled() { return isVisible(domainLnk) && isEnabled(domainLnk); } - public boolean isUsersLnkEnabled(){ + + public boolean isUsersLnkEnabled() { return isVisible(userLnk) && isEnabled(userLnk); } - public boolean isSidebarSearchTextEnable(){ + + public boolean isSidebarSearchTextEnable() { return isVisible(sidebarSearchText) && isEnabled(sidebarSearchText); } - public void collapsingSideBar(){ + + public void collapsingSideBar() { collapseButton.click(); } - public void expandingSideBar(){ + + public void expandingSideBar() { driver.findElement(By.cssSelector("mat-icon[role=img][mattooltip=Expand]")).click(); } } diff --git a/smp-ui-tests/src/main/java/pages/components/baseComponents/PageComponent.java b/smp-ui-tests/src/main/java/pages/components/baseComponents/PageComponent.java index 909709e0cdf23ceff53e5fe804d5c75101efeb46..91bda2be35a31286f8cf355e488c8648af370dd6 100644 --- a/smp-ui-tests/src/main/java/pages/components/baseComponents/PageComponent.java +++ b/smp-ui-tests/src/main/java/pages/components/baseComponents/PageComponent.java @@ -1,6 +1,7 @@ package pages.components.baseComponents; +import com.google.common.base.Stopwatch; import org.apache.log4j.Logger; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -17,7 +18,7 @@ public class PageComponent { protected WebDriver driver; protected WebDriverWait wait; protected Logger log = Logger.getLogger(this.getClass()); - protected By loadingBar = By.className("mat-ripple-element"); + protected By loadingBar = By.cssSelector(".container .bar"); public PageComponent(WebDriver driver) { @@ -41,8 +42,8 @@ public class PageComponent { int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000; int waitedSoFar = 0; while ((null != element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) { - waitedSoFar += 300; - waitForXMillis(300); + waitedSoFar += 100; + waitForXMillis(100); } } @@ -50,63 +51,15 @@ public class PageComponent { int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000; int waitedSoFar = 0; while ((null == element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) { - waitedSoFar += 300; - waitForXMillis(300); + waitedSoFar += 100; + waitForXMillis(100); } } public void waitForElementToBeGone(WebElement element) { - WebDriverWait myWait = new WebDriverWait(driver, 1); - - try { - myWait.until(ExpectedConditions.visibilityOf(element)); - myWait.until(ExpectedConditions.invisibilityOf(element)); - } catch (Exception e) { - return; - } - - int waitTime = PROPERTIES.SHORT_UI_TIMEOUT * 1000; - while (waitTime > 0) { - - try { - if (!element.isDisplayed()) { - return; - } - } catch (Exception e) { - return; - } - waitForXMillis(500); - waitTime = waitTime - 500; - } + waitForXMillis(1000); } - public void waitForElementToBeGone(By locator) { - WebDriverWait myWait = new WebDriverWait(driver, PROPERTIES.SHORT_UI_TIMEOUT); - - try { - myWait.until(ExpectedConditions.visibilityOfElementLocated(locator)); - } catch (Exception e) { - return; - } - - int waitTime = PROPERTIES.SHORT_UI_TIMEOUT * 1000; - while (waitTime > 0) { - boolean displayed = true; - - try { - displayed = driver.findElement(locator).isDisplayed(); - } catch (Exception e) { - return; - } - - if (!displayed) { - return; - } - - waitForXMillis(500); - waitTime = waitTime - 500; - } - } public void waitForNumberOfWindowsToBe(int noOfWindows) { try { @@ -163,12 +116,13 @@ public class PageComponent { public void waitForElementToBe(WebElement element) { - wait.until(new ExpectedCondition<Boolean>() { - @Override - public Boolean apply(WebDriver driver) { - return element.getLocation() != null; - } - }); + wait.until(ExpectedConditions.visibilityOf(element)); +// wait.until(new ExpectedCondition<Boolean>() { +// @Override +// public Boolean apply(WebDriver driver) { +// return element.getLocation() != null; +// } +// }); } @@ -221,12 +175,23 @@ public class PageComponent { } public void waitForRowsToLoad() { + log.info("waiting for rows to load"); try { - waitForElementToBeGone(loadingBar); + waitForXMillis(100); + int bars = 1; + int waits = 0; + while (bars > 0 && waits < 30) { + Object tmp = ((JavascriptExecutor) driver).executeScript("return document.querySelectorAll('.container .bar').length;"); + bars = Integer.valueOf(tmp.toString()); + waits++; + waitForXMillis(200); + } + log.debug("waited for rows to load for ms = 200*" + waits); + waitForXMillis(200); } catch (Exception e) { } - waitForXMillis(500); + } diff --git a/smp-ui-tests/src/main/java/pages/domain/DomainPopup.java b/smp-ui-tests/src/main/java/pages/domain/DomainPopup.java index 8e67f7efbd1ed41bf74f9a2c45fe409e97e3c333..4f6eeb4cce58acbb902a5d47d762826388888459 100644 --- a/smp-ui-tests/src/main/java/pages/domain/DomainPopup.java +++ b/smp-ui-tests/src/main/java/pages/domain/DomainPopup.java @@ -46,12 +46,6 @@ public class DomainPopup extends PageComponent { @FindBy(css = "#smlClientCertHeaderAuth_id-input") WebElement userClientCertHeaderToggleInput; - /*@FindBy(css = "div.mat-form-field-infix > div.ng-star-inserted") - WebElement invalidSmlSmpIdErrorMsg;*/ - -// @FindBy(css = "#smlClientHeader_id") -// WebElement smlClientHeaderInput; - @FindBy(css = "div.mat-form-field-infix > div.ng-star-inserted") WebElement domainCodeValidationError; @@ -65,6 +59,7 @@ public class DomainPopup extends PageComponent { public void clickOK() { waitForElementToBeClickable(okBtn).click(); + waitForXMillis(500); waitForElementToBeGone(okBtn); } diff --git a/smp-ui-tests/src/main/java/pages/keystore/KeyStoreEditDialog.java b/smp-ui-tests/src/main/java/pages/keystore/KeyStoreEditDialog.java index a0ecc98ea26b0484136756d746ed106aaaf7ea09..7b2c1ead8078f78c7ae956fad86ac93126fcce0c 100644 --- a/smp-ui-tests/src/main/java/pages/keystore/KeyStoreEditDialog.java +++ b/smp-ui-tests/src/main/java/pages/keystore/KeyStoreEditDialog.java @@ -1,50 +1,46 @@ package pages.keystore; + 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.AjaxElementLocatorFactory; import pages.components.baseComponents.PageComponent; -import pages.domain.DomainGrid; import pages.domain.DomainPage; import utils.PROPERTIES; public class KeyStoreEditDialog extends PageComponent { - public KeyStoreEditDialog(WebDriver driver){ - super(driver); - PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - - } - - @FindBy(css = "#keystoreTable_id") - private WebElement keystoreTable; - - @FindBy(xpath = "//span[text()='Import keystore']") - private WebElement importKeystore; - - @FindBy(css = "button[mat-dialog-close]") - private WebElement closeBtn; - - public KeyStoreImportDialog clickImportKeystore() - { - log.info("clicking import keystore"); - waitForElementToBeClickable(importKeystore).click(); - waitForElementToBeGone(importKeystore); - return new KeyStoreImportDialog(driver); - } - - public DomainPage clickCloseInKeystore(){ - log.info("clicking close btn in keystore edit dialog"); - waitForElementToBeClickable(closeBtn).click(); - waitForElementToBeGone(closeBtn); - return new DomainPage(driver); - } - - public KeyStoreGrid grid(){ - return new KeyStoreGrid(driver, keystoreTable); - } + @FindBy(css = "#keystoreTable_id") + private WebElement keystoreTable; + @FindBy(xpath = "//span[text()='Import keystore']") + private WebElement importKeystore; + @FindBy(css = "button[mat-dialog-close]") + private WebElement closeBtn; + + public KeyStoreEditDialog(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + + } + + public KeyStoreImportDialog clickImportKeystore() { + log.info("clicking import keystore"); + waitForElementToBeClickable(importKeystore).click(); + waitForElementToBeGone(importKeystore); + return new KeyStoreImportDialog(driver); + } + + public DomainPage clickCloseInKeystore() { + log.info("clicking close btn in keystore edit dialog"); + waitForElementToBeClickable(closeBtn).click(); + waitForElementToBeGone(closeBtn); + return new DomainPage(driver); + } + + public KeyStoreGrid grid() { + return new KeyStoreGrid(driver, keystoreTable); + } } diff --git a/smp-ui-tests/src/main/java/pages/login/LoginPage.java b/smp-ui-tests/src/main/java/pages/login/LoginPage.java index cebeb3568617e8899976fb4c9821e200f6f21288..5f8ac28fad970197551d33ea50ec21630e9b310d 100644 --- a/smp-ui-tests/src/main/java/pages/login/LoginPage.java +++ b/smp-ui-tests/src/main/java/pages/login/LoginPage.java @@ -5,7 +5,6 @@ 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 pages.components.ConfirmationDialog; import pages.components.baseComponents.SMPPage; import pages.service_groups.search.SearchPage; import utils.PROPERTIES; @@ -15,48 +14,44 @@ import java.util.HashMap; public class LoginPage extends SMPPage { - public LoginPage(WebDriver driver) { - super(driver); - - log.info(".... init"); - PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - } - @FindBy(id = "username_id") private WebElement username; - @FindBy(id = "password_id") private WebElement password; - @SuppressWarnings("SpellCheckingInspection") @FindBy(id = "loginbutton_id") private WebElement loginBtn; - @SuppressWarnings("SpellCheckingInspection") @FindBy(id = "okbuttondialog_id") private WebElement dialogOKBtn; - @FindBy(className = "smpVersion") private WebElement smpVersion; - public boolean isLoaded(){ - + public LoginPage(WebDriver driver) { + super(driver); + + log.info(".... init"); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + } + + public boolean isLoaded() { + log.info("check if Login page is loaded"); - - if(!isEnabled(username)){ + + if (!isEnabled(username)) { log.error("Could not find username input!"); return false; } - if(!isEnabled(password)){ + if (!isEnabled(password)) { log.error("Could not find password input!"); return false; } - if(!isVisible(loginBtn)){ + if (!isVisible(loginBtn)) { log.error("Could not find login button!"); return false; } - if(!isVisible(smpVersion)){ + if (!isVisible(smpVersion)) { log.error("Could not find version text!"); return false; } @@ -64,7 +59,7 @@ public class LoginPage extends SMPPage { return true; } - public <T extends SMPPage> T login(String user, String pass, Class<T> expect){ + public <T extends SMPPage> T login(String user, String pass, Class<T> expect) { log.info("Login started!!"); clearAndFillInput(username, user); @@ -79,8 +74,8 @@ public class LoginPage extends SMPPage { return PageFactory.initElements(driver, expect); } - - public SearchPage login(String user, String pass){ + + public SearchPage login(String user, String pass) { log.info("Login started!!"); clearAndFillInput(username, user); @@ -95,7 +90,7 @@ public class LoginPage extends SMPPage { return new SearchPage(driver); } - public void invalidLogin(String user, String pass){ + public void invalidLogin(String user, String pass) { log.info("Invalid login started!!"); clearAndFillInput(username, user); @@ -105,7 +100,7 @@ public class LoginPage extends SMPPage { loginBtn.click(); } - public SearchPage login(String role){ + public SearchPage login(String role) { log.info("Login started!!"); HashMap<String, String> user = new TestDataProvider().getUserWithRole(role); @@ -124,27 +119,28 @@ public class LoginPage extends SMPPage { } - public String getListedSMPVersion(){ + public String getListedSMPVersion() { log.info("getting listed version"); return waitForElementToBeVisible(smpVersion).getText().trim(); } - public String getTextInUsernameInput(){ + public String getTextInUsernameInput() { log.info("getting text in username input"); return waitForElementToBeVisible(username).getText().trim(); } - public String getTextInPasswordInput(){ + public String getTextInPasswordInput() { log.info("getting text in pass input"); return waitForElementToBeVisible(password).getText().trim(); } - private void closeChangePassModal(){ + private void closeChangePassModal() { log.info("Closing Change password modal"); - try{ + try { waitForElementToBeClickable(dialogOKBtn).click(); waitForElementToBeGone(dialogOKBtn); - }catch (Exception e){} + } catch (Exception e) { + } } public void loginWithoutUserAndPassword() { diff --git a/smp-ui-tests/src/main/java/pages/properties/PropertiesPage.java b/smp-ui-tests/src/main/java/pages/properties/PropertiesPage.java index c954988a319f50eaec1881d6bbf8438507343c49..cd798bc143b4c1994d9783e36276b47bd0ac2ec3 100644 --- a/smp-ui-tests/src/main/java/pages/properties/PropertiesPage.java +++ b/smp-ui-tests/src/main/java/pages/properties/PropertiesPage.java @@ -9,88 +9,82 @@ import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import pages.components.ConfirmationDialog; import pages.components.baseComponents.PaginationControls; import pages.components.baseComponents.SMPPage; -import pages.users.UserPopup; -import pages.users.UsersGrid; import utils.PROPERTIES; public class PropertiesPage extends SMPPage { - public PropertiesPage(WebDriver driver) { - super(driver); - this.pageHeader.waitForTitleToBe("Properties"); - PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - } - public PaginationControls pagination = new PaginationControls(driver); - - @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 String getErrorMessage() - { - return driver.findElement(By.cssSelector(".alert-message-error")).getText(); - } - - - - public boolean isLoaded(){ - log.info("checking if Property page is loaded"); - return isVisible(cancelBtn) - && isVisible(saveBtn) - && isVisible(editBtn); - } - - public boolean isCancelButtonEnabled() { - log.info("checking cancel button is enabled"); - return isEnabled(cancelBtn); - } - - public boolean isSaveButtonEnabled() { - log.info("checking save button is enabled"); - return isEnabled(saveBtn); - } - public ConfirmationDialog clickCancel() { - log.info("click cancel button"); - waitForElementToBeClickable(cancelBtn).click(); - return new ConfirmationDialog(driver); - } - public boolean isEditButtonEnabled() { - log.info("checking edit button is enabled"); - return isEnabled(editBtn); - } - - - - public ConfirmationDialog clickSave() { - log.info("click save button"); - waitForElementToBeClickable(saveBtn).click(); - return new ConfirmationDialog(driver); - } - public PropertyPopup clickEdit() { - log.info("click edit button"); - waitForElementToBeClickable(editBtn).click(); - return new PropertyPopup(driver); - } - public void propertySearch(String propertyname) - { - log.info("Search for property"); - waitForElementToBeVisible(searchPropertyField).sendKeys(propertyname); - waitForElementToBeClickable(searchBtn).click(); - } - public PropertiesGrid grid() { - return new PropertiesGrid(driver, propertyTableContainer); - } + public PaginationControls pagination = new PaginationControls(driver); + @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); + this.pageHeader.waitForTitleToBe("Properties"); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + } + + public String getErrorMessage() { + return driver.findElement(By.cssSelector(".alert-message-error")).getText(); + } + + + public boolean isLoaded() { + log.info("checking if Property page is loaded"); + return isVisible(cancelBtn) + && isVisible(saveBtn) + && isVisible(editBtn); + } + + public boolean isCancelButtonEnabled() { + log.info("checking cancel button is enabled"); + return isEnabled(cancelBtn); + } + + public boolean isSaveButtonEnabled() { + log.info("checking save button is enabled"); + return isEnabled(saveBtn); + } + + public ConfirmationDialog clickCancel() { + log.info("click cancel button"); + waitForElementToBeClickable(cancelBtn).click(); + return new ConfirmationDialog(driver); + } + + public boolean isEditButtonEnabled() { + log.info("checking edit button is enabled"); + return isEnabled(editBtn); + } + + + public ConfirmationDialog clickSave() { + log.info("click save button"); + waitForElementToBeClickable(saveBtn).click(); + return new ConfirmationDialog(driver); + } + + public PropertyPopup clickEdit() { + log.info("click edit button"); + waitForElementToBeClickable(editBtn).click(); + return new PropertyPopup(driver); + } + + public void propertySearch(String propertyname) { + log.info("Search for property"); + waitForElementToBeVisible(searchPropertyField).sendKeys(propertyname); + waitForElementToBeClickable(searchBtn).click(); + } + + public PropertiesGrid grid() { + return new PropertiesGrid(driver, propertyTableContainer); + } } diff --git a/smp-ui-tests/src/main/java/pages/service_groups/FilterArea.java b/smp-ui-tests/src/main/java/pages/service_groups/FilterArea.java index 719a42903c1a94cf8843e2f0df1b89a3d433b19a..66576364739508399c0ef1e71119f6eb03d1e7ac 100644 --- a/smp-ui-tests/src/main/java/pages/service_groups/FilterArea.java +++ b/smp-ui-tests/src/main/java/pages/service_groups/FilterArea.java @@ -5,21 +5,12 @@ 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.openqa.selenium.support.ui.ExpectedConditions; import pages.components.GenericSelect; import pages.components.baseComponents.PageComponent; import utils.PROPERTIES; public class FilterArea extends PageComponent { - public FilterArea(WebDriver driver) { - super(driver); - PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - - domainSelect = new GenericSelect(driver, domainSelectContainer); - - } - - + public GenericSelect domainSelect; @FindBy(id = "participantIdentifier") private WebElement participantIdentifierInput; @@ -28,13 +19,17 @@ public class FilterArea extends PageComponent { @FindBy(id = "domain_id") private WebElement domainSelectContainer; - public GenericSelect domainSelect; - @SuppressWarnings("SpellCheckingInspection") @FindBy(id = "searchbutton_id") private WebElement searchButton; + public FilterArea(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + domainSelect = new GenericSelect(driver, domainSelectContainer); + + } public String getParticipantIdentifierInputValue() { log.info("getting text in participant Identifier Input"); @@ -48,23 +43,23 @@ public class FilterArea extends PageComponent { return participantSchemeInput.getText().trim(); } - public boolean isLoaded(){ + public boolean isLoaded() { log.info("checking filter area is properly loaded"); - if(!isVisible(participantIdentifierInput)){ + if (!isVisible(participantIdentifierInput)) { return false; } - if(!isVisible(participantSchemeInput)){ + if (!isVisible(participantSchemeInput)) { return false; } return domainSelect.isLoaded(); } - public void filter(String identifier, String scheme, String domain){ + public void filter(String identifier, String scheme, String domain) { log.info(String.format("filtering by %s, %s, %s", identifier, scheme, domain)); clearAndFillInput(participantIdentifierInput, identifier); clearAndFillInput(participantSchemeInput, scheme); - if(null != domain && !domain.isEmpty()){ + if (null != domain && !domain.isEmpty()) { domainSelect.selectOptionByText(domain); } @@ -73,21 +68,19 @@ public class FilterArea extends PageComponent { waitForXMillis(1000); } - public boolean isSearchButtonVisible(){ - try{ + public boolean isSearchButtonVisible() { + try { return searchButton.isDisplayed(); - } - catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); return false; } } - public boolean isSearchButtonEnable(){ - try{ + public boolean isSearchButtonEnable() { + try { return searchButton.isEnabled(); - } - catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); return false; } diff --git a/smp-ui-tests/src/main/java/pages/service_groups/edit/EditPage.java b/smp-ui-tests/src/main/java/pages/service_groups/edit/EditPage.java index 7792f9a4c820339a7eec5cb76b9421df876a939a..2681efd43e02c296f72cb6577ac64a8f0d09f4e6 100644 --- a/smp-ui-tests/src/main/java/pages/service_groups/edit/EditPage.java +++ b/smp-ui-tests/src/main/java/pages/service_groups/edit/EditPage.java @@ -1,6 +1,5 @@ package pages.service_groups.edit; -import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -16,16 +15,8 @@ import utils.PROPERTIES; import java.util.List; public class EditPage extends SMPPage { - public EditPage(WebDriver driver) { - super(driver); - this.pageHeader.waitForTitleToBe("Edit"); - PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - filterArea = new FilterArea(driver); - } - - public FilterArea filterArea; - + public PaginationControls pagination = new PaginationControls(driver); @FindBy(id = "searchTable") private WebElement searchTable; @@ -47,7 +38,12 @@ public class EditPage extends SMPPage { @FindBy(id = "deleteButton") private WebElement deleteButton; - public PaginationControls pagination = new PaginationControls(driver); + public EditPage(WebDriver driver) { + super(driver); + this.pageHeader.waitForTitleToBe("Edit"); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + filterArea = new FilterArea(driver); + } public boolean isCancelButtonEnabled() { log.info("cancel button"); @@ -104,6 +100,7 @@ public class EditPage extends SMPPage { waitForElementToBeClickable(cancelButton).click(); return new ConfirmationDialog(driver); } + public ConfirmationDialog clickOk() { log.info("canceling ..."); waitForElementToBeClickable(okButton).click(); diff --git a/smp-ui-tests/src/main/java/pages/service_groups/edit/ServiceGroupPopup.java b/smp-ui-tests/src/main/java/pages/service_groups/edit/ServiceGroupPopup.java index 5844a1dedb6032b665ac794464664dfe4360795e..18f711888695fac98a6c28de97b92b9fa4b9dabc 100644 --- a/smp-ui-tests/src/main/java/pages/service_groups/edit/ServiceGroupPopup.java +++ b/smp-ui-tests/src/main/java/pages/service_groups/edit/ServiceGroupPopup.java @@ -5,127 +5,119 @@ 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.openqa.selenium.support.ui.ExpectedConditions; import pages.components.baseComponents.PageComponent; import utils.PROPERTIES; import java.util.List; public class ServiceGroupPopup extends PageComponent { - public ServiceGroupPopup(WebDriver driver) { - super(driver); - PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); - - try { - ownersPanel = new AccordionSection(driver, ownersPanelContainer); - } catch (Exception e) { - - } - domainsPanel = new AccordionSection(driver, domainsPanelContainer); - - } - + public AccordionSection ownersPanel; + public AccordionSection domainsPanel; @FindBy(css = "#owner_expansion_panel_id") private WebElement ownersPanelContainer; - public AccordionSection ownersPanel; - @FindBy(css = "#domain_expansion_panel_id") private WebElement domainsPanelContainer; - public AccordionSection domainsPanel; - @FindBy(css = "mat-dialog-actions button:nth-child(1)") private WebElement okButton; - @FindBy(css = "mat-dialog-actions button:nth-child(2)") private WebElement cancelButton; - @FindBy(css = "#participantIdentifier_id") private WebElement participantIdentifierInput; - @FindBy(css = "#participantScheme_id") private WebElement participantSchemeInput; - @FindBy(css = "#extensionTextArea") private WebElement extensionTextArea; - @FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(1)") private WebElement clearExtensionButton; - @FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(2)") private WebElement extensionWizardButton; - @FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(3)") private WebElement validateExtensionButton; - @FindBy(css = "mat-card-content > div.ng-star-inserted") private WebElement errorContainer; + public ServiceGroupPopup(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); + + try { + ownersPanel = new AccordionSection(driver, ownersPanelContainer); + } catch (Exception e) { + + } + domainsPanel = new AccordionSection(driver, domainsPanelContainer); + + } - public boolean isOKButtonPresent(){ + public boolean isOKButtonPresent() { log.info("is ok button visible"); return isVisible(okButton); } - public boolean isCancelButtonPresent(){ + + public boolean isCancelButtonPresent() { log.info("is cancel button visible"); return isVisible(cancelButton); } - public boolean isOKButtonEnable(){ + + public boolean isOKButtonEnable() { log.info("is ok button visible"); return isEnabled(okButton); } - public boolean isCancelButtonEnable(){ + + public boolean isCancelButtonEnable() { log.info("is cancel button visible"); return isEnabled(cancelButton); } - public boolean isExtensionAreaEditable(){ + public boolean isExtensionAreaEditable() { log.info("is Extension Area Editable"); - return isEnabled( extensionTextArea); + return isEnabled(extensionTextArea); } - public boolean isParticipantIdentifierInputEnabled(){ + + public boolean isParticipantIdentifierInputEnabled() { log.info("is Participant Identifier Input Enabled"); - return isEnabled( participantIdentifierInput); + return isEnabled(participantIdentifierInput); } - public boolean isParticipantSchemeInputEnabled(){ + public boolean isParticipantSchemeInputEnabled() { log.info("is Participant Scheme Input Enabled"); - return isEnabled( participantSchemeInput); + return isEnabled(participantSchemeInput); } - public boolean isOwnersPanelEnabled(){ + public boolean isOwnersPanelEnabled() { log.info("check owner panel is enabled"); return ownersPanel.optionsEnabled(); } - public boolean isOwnersPanelPresent(){ + public boolean isOwnersPanelPresent() { log.info("check owner panel is present"); return null == ownersPanel; } - public boolean isDomainsPanelEnabled(){ + public boolean isDomainsPanelEnabled() { log.info("check domains panel is enabled"); return domainsPanel.optionsEnabled(); } - public void clickOK(){ + public void clickOK() { log.info("click ok.."); waitForElementToBeClickable(okButton).click(); waitForElementToBeGone(okButton); } - public void clickClear(){ + public void clickClear() { log.info("click clear.."); waitForElementToBeClickable(clearExtensionButton).click(); waitForXMillis(100); } - public void clickCancel(){ + public void clickCancel() { log.info("click cancel.."); waitForElementToBeClickable(cancelButton).click(); waitForElementToBeGone(cancelButton); } - public void fillForm(String identifier, String scheme, List<String> owners, List<String> domains, String extension){ + public void fillForm(String identifier, String scheme, List<String> owners, List<String> domains, String extension) { log.info("filling form.."); waitForElementToBeVisible(participantIdentifierInput); @@ -147,19 +139,19 @@ public class ServiceGroupPopup extends PageComponent { } - public String getParticipantIdentifierValue(){ + public String getParticipantIdentifierValue() { return waitForElementToBeVisible(participantIdentifierInput).getAttribute("value").trim(); } - public String getParticipantSchemeValue(){ + public String getParticipantSchemeValue() { return participantSchemeInput.getAttribute("value").trim(); } - public String getErrorMessage(){ + public String getErrorMessage() { return errorContainer.getText().trim(); } - public String getExtensionAreaContent(){ + public String getExtensionAreaContent() { log.info("getting Extension Area Content"); waitForElementToBeVisible(extensionTextArea); @@ -167,38 +159,44 @@ public class ServiceGroupPopup extends PageComponent { return extensionTextArea.getAttribute("value").trim(); } - public void enterDataInExtensionTextArea(String text){ + public void enterDataInExtensionTextArea(String text) { waitForElementToBeVisible(extensionTextArea).clear(); extensionTextArea.sendKeys(text); waitForXMillis(1000); } - public void fillParticipantIdentifier(String participantIdentifier){ + public void fillParticipantIdentifier(String participantIdentifier) { clearAndFillInput(participantIdentifierInput, participantIdentifier); } - public void fillParticipantScheme(String participantScheme){ + + public void fillParticipantScheme(String participantScheme) { clearAndFillInput(participantSchemeInput, participantScheme); } - public void chooseFirstOwner(){ - if(!ownersPanel.isExpanded()){ ownersPanel.expandSection();} + + public void chooseFirstOwner() { + if (!ownersPanel.isExpanded()) { + ownersPanel.expandSection(); + } ownersPanel.selectOptionWithIndex(0); } - public void chooseFirstDomain(){ - if(!domainsPanel.isExpanded()){ domainsPanel.expandSection();} + + public void chooseFirstDomain() { + if (!domainsPanel.isExpanded()) { + domainsPanel.expandSection(); + } domainsPanel.selectOptionWithIndex(0); } - public void fillExtensionArea(String extension){ + + public void fillExtensionArea(String extension) { clearAndFillInput(extensionTextArea, extension); } - public void generateRndExtension(){ + public void generateRndExtension() { extensionWizardButton.click(); new SGExtensionWizzard(driver).fillWithRndStrings(); } - - } diff --git a/smp-ui-tests/src/main/java/utils/DriverManager.java b/smp-ui-tests/src/main/java/utils/DriverManager.java index 07371e6ebe39a9566f50a612d289322e0be3cef1..e16a0469e905b50cd0a9bbf3fc25fe4a6afe2965 100644 --- a/smp-ui-tests/src/main/java/utils/DriverManager.java +++ b/smp-ui-tests/src/main/java/utils/DriverManager.java @@ -2,6 +2,7 @@ package utils; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; @@ -21,15 +22,24 @@ public class DriverManager { // } public static WebDriver getDriver() { - WebDriver driver = new ChromeDriver(); - driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); - driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); - driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); + ChromeOptions options = new ChromeOptions(); + options.setHeadless(Boolean.valueOf(PROPERTIES.HEADLESS)); + options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems + options.addArguments("--no-sandbox"); // Bypass OS security model + + options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems + options.addArguments("--window-size=1920,1080"); + + + WebDriver driver = new ChromeDriver(options); + driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); driver.manage().window().maximize(); - return driver; - } + return driver; + } + + } diff --git a/smp-ui-tests/src/main/java/utils/PROPERTIES.java b/smp-ui-tests/src/main/java/utils/PROPERTIES.java index 99ca0cd44bc2c9d46823bf37b9042d1df5095fcc..40690a6aba5be9942cb05a72bced99f0f2a8eb57 100644 --- a/smp-ui-tests/src/main/java/utils/PROPERTIES.java +++ b/smp-ui-tests/src/main/java/utils/PROPERTIES.java @@ -6,7 +6,8 @@ public class PROPERTIES { public static final String UI_BASE_URL = System.getProperty("UI_BASE_URL"); public static final int SHORT_UI_TIMEOUT = 5; public static final int TIMEOUT = Integer.valueOf(System.getProperty("SHORT_TIMEOUT")); - public static final int LONG_WAIT = Integer.valueOf(System.getProperty("LONG_TIMEOUT")); + + public static final String HEADLESS = "true"; public static final String REPORTS_FOLDER = System.getProperty("reports.folder"); public static final String TESTDATAFILE = System.getProperty("data.folder") + System.getProperty("testdata.file"); diff --git a/smp-ui-tests/src/main/java/utils/TestDataProvider.java b/smp-ui-tests/src/main/java/utils/TestDataProvider.java index 3b567c1d8371f497efaa2bc48b0f023d9da81690..71a232cab45887f8bb2bbe8882b66471599ff2ce 100644 --- a/smp-ui-tests/src/main/java/utils/TestDataProvider.java +++ b/smp-ui-tests/src/main/java/utils/TestDataProvider.java @@ -20,7 +20,7 @@ public class TestDataProvider { content = new String(Files.readAllBytes(Paths.get(PROPERTIES.TESTDATAFILE))); testData = new JSONObject(content); } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException("Error reading test data file: " + PROPERTIES.TESTDATAFILE); } } diff --git a/smp-ui-tests/src/main/java/utils/enums/SMPMessages.java b/smp-ui-tests/src/main/java/utils/enums/SMPMessages.java index 059b4b88bbd4962ca7349fdb44b50caab6a0930f..f34c534e769ccc0105f57232800fe1c5f9ee8c58 100644 --- a/smp-ui-tests/src/main/java/utils/enums/SMPMessages.java +++ b/smp-ui-tests/src/main/java/utils/enums/SMPMessages.java @@ -1,64 +1,60 @@ package utils.enums; -import utils.TestDataProvider; - -import java.util.Map; - public class SMPMessages { public static final String MSG_1 = "Login failed; Invalid userID or password"; public static final String MSG_2 = "Too many invalid attempts to log in. Access has been temporarily\n" + - "suspended. Please try again later with the right credentials."; + "suspended. Please try again later with the right credentials."; public static final String MSG_3 = "To abandon all changes performed since last save, click on the \"Cancel\" button.\n" + - "Click on the \"Ok\" button keep your changes and come back to the current\n" + - "window unchanged."; + "Click on the \"Ok\" button keep your changes and come back to the current\n" + + "window unchanged."; public static final String MSG_4 = "Please confirm by clicking on the \"Save\" button that you want to save all changes.\n" + - "If you don't want to save these changes now, please click on the \"Don't\n" + - "save now\" button"; + "If you don't want to save these changes now, please click on the \"Don't\n" + + "save now\" button"; public static final String MSG_5 = "To delete the current item(s) click on the \"Ok\" button.\n" + - "Click on the \"Cancel\" button to keep this item and come back to the\n" + - "current window unchanged"; + "Click on the \"Cancel\" button to keep this item and come back to the\n" + + "current window unchanged"; public static final String MSG_6 = "The system detected a concurrent access.\n" + - "Your changes are irremediably lost, and the data were reverted to what\n" + - "the concurrent user saved before you."; + "Your changes are irremediably lost, and the data were reverted to what\n" + + "the concurrent user saved before you."; public static final String MSG_7 = "Component ${COMPONENT} is not accessible. Administration console is\n" + - "disabled."; + "disabled."; public static final String MSG_8 = "You are about to leave the edition of the current ${OBJECT_TYPE} which\n" + - "modifications were not saved yet.\n" + - "Click on \"Abandon\" to abandon your changes.\n" + - "Click \"Keep\" to stay on the current screen and keep your changes without\n" + - "saving them now"+ - "Click \"Save\" to save your changes and move to the selected screen."; + "modifications were not saved yet.\n" + + "Click on \"Abandon\" to abandon your changes.\n" + + "Click \"Keep\" to stay on the current screen and keep your changes without\n" + + "saving them now" + + "Click \"Save\" to save your changes and move to the selected screen."; public static final String MSG_9 = "The selection criteria you provided are too restrictive, no result matches\n" + - "these criteria. Please enter less selective criteria to obtain some results"; + "these criteria. Please enter less selective criteria to obtain some results"; public static final String MSG_10 = "A value must be provided for the plugin and at least for one of the other\n" + - "column for the filter to be applicable."; + "column for the filter to be applicable."; public static final String MSG_11 = "You are about to delete ServiceGroup: ${ServiceGroup} and its ServiceMetadata.\n" + - "Click on \"Delete\" to confirm the deletion.\n" + - "Click on \"Keep\" to keep the ServiceMetadata."; + "Click on \"Delete\" to confirm the deletion.\n" + + "Click on \"Keep\" to keep the ServiceMetadata."; public static final String MSG_12 = "You are about to delete ServiceMetadata: ${ServiceMetadata}.\n" + - "Click on \"Delete\" to confirm the deletion.\n" + - "Click on \"Keep\" to keep the ServiceMetadata"; + "Click on \"Delete\" to confirm the deletion.\n" + + "Click on \"Keep\" to keep the ServiceMetadata"; public static final String MSG_13 = "You are about to delete User: ${User}.\n" + - "Click on \"Delete\" to confirm the deletion.\n" + - "Click on \"Keep\" to keep the user.\n"; + "Click on \"Delete\" to confirm the deletion.\n" + + "Click on \"Keep\" to keep the user.\n"; public static final String MSG_14 = "You are about to create an SMP Domain: ${SMP_BDMSL_ID}. Action will\n" + - "register new user SMP user to SML for domain ${ BDMSL _DOMAIN}.\n" + - "Domain will be saved to SMP. Action is not recoverable.\n" + - "Click on \"Register\" to confirm the registration and saving.\n" + - "Click on \"Cancel\" to cancel the registration."; + "register new user SMP user to SML for domain ${ BDMSL _DOMAIN}.\n" + + "Domain will be saved to SMP. Action is not recoverable.\n" + + "Click on \"Register\" to confirm the registration and saving.\n" + + "Click on \"Cancel\" to cancel the registration."; @SuppressWarnings("SpellCheckingInspection") public static final String MSG_15 = "You are about to delete an SMP Domain: ${SMP_DOMAIN_ID}. Action\n" + - "will unregister SMP domain user ${SMP_SML_ID}. from SML for domain\n" + - "${ BDMSL _DOMAIN}. Action is not recoverable.\n" + - "Click on \"Delete\" to confirm the deleting and unregistration of domain.\n" + - "Click on \"Keep\" to keep the domain."; + "will unregister SMP domain user ${SMP_SML_ID}. from SML for domain\n" + + "${ BDMSL _DOMAIN}. Action is not recoverable.\n" + + "Click on \"Delete\" to confirm the deleting and unregistration of domain.\n" + + "Click on \"Keep\" to keep the domain."; public static final String MSG_16 = "You are about to delete an X509 private key: ${Key }. Action is not recoverable.\n" + - "Click on \"Delete\" to confirm the deleting the key.\n" + - "Click on \"Keep\" to keep the key."; + "Click on \"Delete\" to confirm the deleting the key.\n" + + "Click on \"Keep\" to keep the key."; public static final String MSG_17 = "You are about to delete Domain: ${SMP_DOMAIN_ID}.\n" + - "Click on \"Delete\" to confirm the deletion.\n" + - "Click on \"Keep\" to keep the domain."; + "Click on \"Delete\" to confirm the deletion.\n" + + "Click on \"Keep\" to keep the domain."; public static final String MSG_18 = "The operation 'update' completed successfully."; public static final String USER_OWN_DELETE_ERR = "Delete validation error Could not delete logged user!"; @@ -78,7 +74,7 @@ public class SMPMessages { public static final String KEYSTORE_IMPORTED_MSG = "Keystore %s imported!"; public static final String KEYSTORE_DELETION_MSG = "Certificate %s deleted!"; public static final String SMLSMPID_VALIDATION_MESSAGE = "SML SMP ID should be up to 63 characters long, should only contain alphanumeric and hyphen characters, should not start with a digit nor a hyphen and should not end with a hyphen."; - public static final String USER_EMAIL_VALIDATION_MESSAGE ="Email is invalid!"; + public static final String USER_EMAIL_VALIDATION_MESSAGE = "Email is invalid!"; public static final String DOMAINCODE_VALIDATION_MESSAGE = "Domain code must contain only chars and numbers and must be less than 63 chars long."; public static final String VALID_XML_MESSAGE = "Servicemetadata is valid!"; public static final String INVALID_XML_MESSAGE1 = "SAXParseException: XML document structures must start and end within the same entity."; diff --git a/smp-ui-tests/src/main/java/utils/rest/SMPPaths.java b/smp-ui-tests/src/main/java/utils/rest/SMPPaths.java index de66f5615f4564af7f6f59ce59456424fa11eef0..8d622544556016d7209b12a18cb305e2172dfd0a 100644 --- a/smp-ui-tests/src/main/java/utils/rest/SMPPaths.java +++ b/smp-ui-tests/src/main/java/utils/rest/SMPPaths.java @@ -1,7 +1,5 @@ package utils.rest; -import utils.PROPERTIES; - @SuppressWarnings("SpellCheckingInspection") public class SMPPaths { @@ -11,5 +9,6 @@ public class SMPPaths { public static final String USER_LIST = "internal/rest/user"; public static final String SERVICE_GROUP = "public/rest/service-group"; public static final String KEYSTORE = "internal/rest/keystore"; + public static final String SYS_INFO = "public/rest/application/info"; } diff --git a/smp-ui-tests/src/main/java/utils/rest/SMPRestClient.java b/smp-ui-tests/src/main/java/utils/rest/SMPRestClient.java index f70c1ed253f46c861be23dd5da4958e33cbf12de..68b8e3de2af2c7fb02b7eb27ed7939fcbed79cdc 100644 --- a/smp-ui-tests/src/main/java/utils/rest/SMPRestClient.java +++ b/smp-ui-tests/src/main/java/utils/rest/SMPRestClient.java @@ -17,8 +17,6 @@ import utils.TestDataProvider; import javax.ws.rs.core.Cookie; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.NewCookie; -import java.net.HttpCookie; -import java.net.URLDecoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,165 +24,165 @@ import java.util.Map; public class SMPRestClient { - protected static Logger log = Logger.getLogger(SMPRestClient.class); - private static Client client = Client.create(); - private static WebResource resource = client.resource(PROPERTIES.UI_BASE_URL); + protected static Logger log = Logger.getLogger(SMPRestClient.class); + private static Client client = Client.create(); + private static WebResource resource = client.resource(PROPERTIES.UI_BASE_URL); - public static ServiceGroup getServiceGroup(String url) { + public static ServiceGroup getServiceGroup(String url) { // downloading XML and parsing - XStream xstream = new XStream(new StaxDriver()); - xstream.ignoreUnknownElements(); - xstream.processAnnotations(ServiceGroup.class); - ServiceGroup serviceGroup = null; - try { - String tmp = client.resource(url).get(String.class); - serviceGroup = (ServiceGroup) xstream.fromXML(tmp); - } catch (Exception e) { - e.printStackTrace(); - } - return serviceGroup; - } - - public static HashMap<String, String> getCookies(List<NewCookie> cookies) { - HashMap<String, String> map = new HashMap<String, String>(); - int count = 0; - for (NewCookie cookie : cookies) { - if ("XSRF-TOKEN".equals(cookie.getName())) { - map.put("XSRF-TOKEN", cookie.getValue()); - count++; - } - if ("JSESSIONID".equals(cookie.getName())) { - map.put("JSESSIONID", cookie.getValue()); - count++; - } - if (count == 2) - break; - } - return map; - } - - - public static List<String> getDomainAndSubdomains() { - List<String> domainList = new ArrayList<>(); - try { - String responseRaw = resource.path(SMPPaths.REST_DOMAIN_LIST) - .queryParam("page", "-1") - .queryParam("pageSize", "-1") - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .get(String.class); - JSONArray restDomains = new JSONObject(responseRaw).getJSONArray("serviceEntities"); - - for (int i = 0; i < restDomains.length(); i++) { - JSONObject currentDomain = restDomains.getJSONObject(i); - String currentDomainStr = currentDomain.getString("domainCode").trim(); - String currentSubdomainStr = "" + currentDomain.getString("smlSubdomain").trim().replaceAll("null", ""); - - String tmp = String.format("%s (%s)", currentDomainStr, currentSubdomainStr); - - domainList.add(tmp); - } - } catch (Exception e) { - } - return domainList; - } - - public static String getDomainSubDomainCombo(String domainCode) { - List<String> allDomains = getDomainAndSubdomains(); - for (String allDomain : allDomains) { - if (allDomain.startsWith(domainCode + " ")) { - return allDomain; - } - } - return domainCode; - } - - - public static List<NewCookie> login(String role) { - String authTemplate = "{\"username\": \"%s\", \"password\": \"%s\"}"; - TestDataProvider tdp = new TestDataProvider(); - Map<String, String> user = tdp.getUserWithRole(role); - String auth = String.format(authTemplate, user.get("username"), user.get("password")); - - List<NewCookie> session = resource.path(SMPPaths.LOGIN_PATH).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, auth).getCookies();//.getCookies(); - return session; - } - - public static List<String> getSysAdmins() { - List<NewCookie> cookies = login("SYS_ADMIN"); - HashMap<String, String> map = getCookies(cookies); - String xsrf = map.get("XSRF-TOKEN"); - String jsessionID = map.get("JSESSIONID"); - try { - String responseRaw = resource.path(SMPPaths.USER_LIST) - .queryParam("page", "-1") - .queryParam("pageSize", "-1") - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .get(String.class); - JSONArray users = new JSONObject(responseRaw).getJSONArray("serviceEntities"); - - List<String> sysadmins = new ArrayList<>(); - - for (int i = 0; i < users.length(); i++) { - JSONObject usr = users.getJSONObject(i); - if (usr.getString("role").equalsIgnoreCase("SYSTEM_ADMIN")) { - sysadmins.add(usr.getString("username")); - } - } - return sysadmins; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static List<String> getKeyStoreEntries() { - List<NewCookie> cookies = login("SYS_ADMIN"); - HashMap<String, String> map = getCookies(cookies); - String xsrf = map.get("XSRF-TOKEN"); - String jsessionID = map.get("JSESSIONID"); - try { - String responseRaw = resource.path(SMPPaths.KEYSTORE) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .get(String.class); - JSONArray entries = new JSONObject(responseRaw).getJSONArray("serviceEntities"); - - List<String> entryList = new ArrayList<>(); - - for (int i = 0; i < entries.length(); i++) { - - - String id = entries.getJSONObject(i).getString("certificateId"); - String alias = entries.getJSONObject(i).getString("alias"); - entryList.add(String.format("%s (%s)", alias, id)); - } - return entryList; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - - public static boolean createDomain(String domainCode) { - List<NewCookie> cookies = login("SYS_ADMIN"); + XStream xstream = new XStream(new StaxDriver()); + xstream.ignoreUnknownElements(); + xstream.processAnnotations(ServiceGroup.class); + ServiceGroup serviceGroup = null; + try { + String tmp = client.resource(url).get(String.class); + serviceGroup = (ServiceGroup) xstream.fromXML(tmp); + } catch (Exception e) { + e.printStackTrace(); + } + return serviceGroup; + } + + public static HashMap<String, String> getCookies(List<NewCookie> cookies) { + HashMap<String, String> map = new HashMap<String, String>(); + int count = 0; + for (NewCookie cookie : cookies) { + if ("XSRF-TOKEN".equals(cookie.getName())) { + map.put("XSRF-TOKEN", cookie.getValue()); + count++; + } + if ("JSESSIONID".equals(cookie.getName())) { + map.put("JSESSIONID", cookie.getValue()); + count++; + } + if (count == 2) + break; + } + return map; + } + + + public static List<String> getDomainAndSubdomains() { + List<String> domainList = new ArrayList<>(); + try { + String responseRaw = resource.path(SMPPaths.REST_DOMAIN_LIST) + .queryParam("page", "-1") + .queryParam("pageSize", "-1") + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .get(String.class); + JSONArray restDomains = new JSONObject(responseRaw).getJSONArray("serviceEntities"); + + for (int i = 0; i < restDomains.length(); i++) { + JSONObject currentDomain = restDomains.getJSONObject(i); + String currentDomainStr = currentDomain.getString("domainCode").trim(); + String currentSubdomainStr = "" + currentDomain.getString("smlSubdomain").trim().replaceAll("null", ""); + + String tmp = String.format("%s (%s)", currentDomainStr, currentSubdomainStr); + + domainList.add(tmp); + } + } catch (Exception e) { + } + return domainList; + } + + public static String getDomainSubDomainCombo(String domainCode) { + List<String> allDomains = getDomainAndSubdomains(); + for (String allDomain : allDomains) { + if (allDomain.startsWith(domainCode + " ")) { + return allDomain; + } + } + return domainCode; + } + + + public static List<NewCookie> login(String role) { + String authTemplate = "{\"username\": \"%s\", \"password\": \"%s\"}"; + TestDataProvider tdp = new TestDataProvider(); + Map<String, String> user = tdp.getUserWithRole(role); + String auth = String.format(authTemplate, user.get("username"), user.get("password")); + + List<NewCookie> session = resource.path(SMPPaths.LOGIN_PATH).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON_TYPE) + .post(ClientResponse.class, auth).getCookies(); + return session; + } + + public static List<String> getSysAdmins() { + List<NewCookie> cookies = login("SYS_ADMIN"); + HashMap<String, String> map = getCookies(cookies); + String xsrf = map.get("XSRF-TOKEN"); + String jsessionID = map.get("JSESSIONID"); + try { + String responseRaw = resource.path(SMPPaths.USER_LIST) + .queryParam("page", "-1") + .queryParam("pageSize", "-1") + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .get(String.class); + JSONArray users = new JSONObject(responseRaw).getJSONArray("serviceEntities"); + + List<String> sysadmins = new ArrayList<>(); + + for (int i = 0; i < users.length(); i++) { + JSONObject usr = users.getJSONObject(i); + if (usr.getString("role").equalsIgnoreCase("SYSTEM_ADMIN")) { + sysadmins.add(usr.getString("username")); + } + } + return sysadmins; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static List<String> getKeyStoreEntries() { + List<NewCookie> cookies = login("SYS_ADMIN"); + HashMap<String, String> map = getCookies(cookies); + String xsrf = map.get("XSRF-TOKEN"); + String jsessionID = map.get("JSESSIONID"); + try { + String responseRaw = resource.path(SMPPaths.KEYSTORE) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .get(String.class); + JSONArray entries = new JSONObject(responseRaw).getJSONArray("serviceEntities"); + + List<String> entryList = new ArrayList<>(); + + for (int i = 0; i < entries.length(); i++) { + + + String id = entries.getJSONObject(i).getString("certificateId"); + String alias = entries.getJSONObject(i).getString("alias"); + entryList.add(String.format("%s (%s)", alias, id)); + } + return entryList; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + public static boolean createDomain(String domainCode) { + List<NewCookie> cookies = login("SYS_ADMIN"); String template = "[{\"domainCode\":\"%s\",\"smlSubdomain\":\"%s\",\"smlSmpId\":\"%s\",\"smlClientKeyAlias\":\"%s\",\"signatureKeyAlias\":\"%s\",\"status\":2,\"smlClientCertHeader\":\"%s\"}]"; String domainPostStr = String.format(template, domainCode, domainCode, domainCode, domainCode, domainCode, domainCode); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - log.info("Creating domain template whose value is :"+template); - log.info("Creating the doamainpoststring" +domainPostStr); - try { + log.info("Creating domain template whose value is :" + template); + log.info("Creating the doamainpoststring" + domainPostStr); + try { ClientResponse getResponse = resource.path(SMPPaths.REST_POST_DOMAIN) .accept(MediaType.APPLICATION_JSON_TYPE) .type(MediaType.APPLICATION_JSON_TYPE) @@ -192,303 +190,314 @@ public class SMPRestClient { .cookie(new Cookie("XSRF-TOKEN", xsrf)) .header("X-XSRF-TOKEN", xsrf) .put(ClientResponse.class, domainPostStr); - log.info("Create domain return status code is:"+getResponse.getStatus()); - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } + log.info("Create domain return status code is:" + getResponse.getStatus()); + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } - return false; - } + return false; + } - public static boolean createUser(String username, String role) { - List<NewCookie> cookies = login("SYS_ADMIN"); + public static boolean createUser(String username, String role) { + List<NewCookie> cookies = login("SYS_ADMIN"); String template = "[{\"active\":true,\"username\":\"%s\",\"emailAddress\":\"\",\"password\":\"QW!@qw12\",\"confirmation\":\"\",\"role\":\"%s\",\"status\":2,\"statusPassword\":2,\"certificate\":{\"subject\":\"\",\"validFrom\":null,\"validTo\":null,\"issuer\":\"\",\"serialNumber\":\"\",\"certificateId\":\"\",\"fingerprints\":\"\"}}]"; String postStr = String.format(template, username, role); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - try{ - ClientResponse getResponse = resource.path(SMPPaths.USER_LIST) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .put(ClientResponse.class, postStr); - - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static boolean createServiceGroup(String pi, String ps, List<String> usernames, List<String> domainCodes) { - String template = "[{\"id\":null,\"extensionStatus\":1,\"participantIdentifier\":\"%s\",\"participantScheme\":\"%s\",\"serviceMetadata\":[],\"users\":%s,\"serviceGroupDomains\":%s,\"extension\":\"\",\"status\":2}]"; - - try { - List<NewCookie> cookies = login("SMP_ADMIN"); - HashMap<String, String> map = getCookies(cookies); - String xsrf = map.get("XSRF-TOKEN"); - String jsessionID = map.get("JSESSIONID"); - - JSONArray users = new JSONArray(); - for (String username : usernames) { - users.put(transformUserForSGPost(getUserForName(username,jsessionID,xsrf))); - } - - JSONArray domains = new JSONArray(); - for (String codes : domainCodes) { - domains.put(transformDomainForSGPost(getDomainForName(codes))); - } - - - String postStr = String.format(template, pi, ps, users.toString(), domains.toString()); - log.info("post str is :"+postStr); - - ClientResponse getResponse = resource.path(SMPPaths.SERVICE_GROUP) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .put(ClientResponse.class, postStr); - - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static boolean createMetadata(String pi) { - String template = "{\"documentIdentifier\":\"%s\",\"documentIdentifierScheme\":\"%s\",\"smlSubdomain\":\"%s\",\"domainCode\":\"%s\",\"domainId\":%s,\"status\":2,\"xmlContentStatus\":2}"; - String xmlTemplate = "<ServiceMetadata xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\"> <ServiceInformation> <ParticipantIdentifier scheme=\"%s\">%s</ParticipantIdentifier> <DocumentIdentifier scheme=\"%s\">%s</DocumentIdentifier> <ProcessList> <Process> <ProcessIdentifier scheme=\"[enterProcessType]\">[enterProcessName]</ProcessIdentifier> <ServiceEndpointList> <Endpoint transportProfile=\"bdxr-transport-ebms3-as4-v1p0\"> <EndpointURI>https://mypage.eu</EndpointURI> <Certificate>UGFzdGUgYmFzZTY0IGVuY29kZWQgY2VydGlmaWNhdGUgb2YgQVA=</Certificate> <ServiceDescription>Service description for partners</ServiceDescription> <TechnicalContactUrl>www.best-page.eu</TechnicalContactUrl> </Endpoint> </ServiceEndpointList> </Process> </ProcessList> </ServiceInformation> </ServiceMetadata>"; - - try { - JSONObject sg = getSGforPI(pi); - JSONObject domain = sg.getJSONArray("serviceGroupDomains").getJSONObject(0); - String domainCode = domain.getString("domainCode"); - String subdomain = domain.getString("smlSubdomain"); - String domainId = domain.getString("domainId"); - String docID = Generator.randomAlphaNumeric(5); - String docscheme = Generator.randomAlphaNumeric(5); - - String xmlContent = String.format(xmlTemplate, sg.getString("participantScheme"), pi, docscheme, docID); - - String postMeta = String.format(template, docID, docscheme, subdomain, domainCode, domainId); - - sg.getJSONArray("serviceMetadata").put(new JSONObject(postMeta).put("xmlContent", xmlContent)); - sg.put("status", 1); - - - List<NewCookie> cookies = login("SMP_ADMIN"); + try { + ClientResponse getResponse = resource.path(SMPPaths.USER_LIST) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .put(ClientResponse.class, postStr); + + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static boolean createServiceGroup(String pi, String ps, List<String> usernames, List<String> domainCodes) { + String template = "[{\"id\":null,\"extensionStatus\":1,\"participantIdentifier\":\"%s\",\"participantScheme\":\"%s\",\"serviceMetadata\":[],\"users\":%s,\"serviceGroupDomains\":%s,\"extension\":\"\",\"status\":2}]"; + try { + List<NewCookie> cookies = login("SMP_ADMIN"); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - ClientResponse getResponse = resource.path(SMPPaths.SERVICE_GROUP) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .put(ClientResponse.class, new JSONArray().put(sg).toString()); - - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static String getMetadataString(String url) { - try { - - System.out.println("url = " + url); + + JSONArray users = new JSONArray(); + for (String username : usernames) { + users.put(transformUserForSGPost(getUserForName(username, jsessionID, xsrf))); + } + + JSONArray domains = new JSONArray(); + for (String codes : domainCodes) { + domains.put(transformDomainForSGPost(getDomainForName(codes))); + } + + + String postStr = String.format(template, pi, ps, users.toString(), domains.toString()); + log.info("post str is :" + postStr); + + ClientResponse getResponse = resource.path(SMPPaths.SERVICE_GROUP) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .put(ClientResponse.class, postStr); + + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static boolean createMetadata(String pi) { + String template = "{\"documentIdentifier\":\"%s\",\"documentIdentifierScheme\":\"%s\",\"smlSubdomain\":\"%s\",\"domainCode\":\"%s\",\"domainId\":%s,\"status\":2,\"xmlContentStatus\":2}"; + String xmlTemplate = "<ServiceMetadata xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\"> <ServiceInformation> <ParticipantIdentifier scheme=\"%s\">%s</ParticipantIdentifier> <DocumentIdentifier scheme=\"%s\">%s</DocumentIdentifier> <ProcessList> <Process> <ProcessIdentifier scheme=\"[enterProcessType]\">[enterProcessName]</ProcessIdentifier> <ServiceEndpointList> <Endpoint transportProfile=\"bdxr-transport-ebms3-as4-v1p0\"> <EndpointURI>https://mypage.eu</EndpointURI> <Certificate>UGFzdGUgYmFzZTY0IGVuY29kZWQgY2VydGlmaWNhdGUgb2YgQVA=</Certificate> <ServiceDescription>Service description for partners</ServiceDescription> <TechnicalContactUrl>www.best-page.eu</TechnicalContactUrl> </Endpoint> </ServiceEndpointList> </Process> </ProcessList> </ServiceInformation> </ServiceMetadata>"; + + try { + JSONObject sg = getSGforPI(pi); + JSONObject domain = sg.getJSONArray("serviceGroupDomains").getJSONObject(0); + String domainCode = domain.getString("domainCode"); + String subdomain = domain.getString("smlSubdomain"); + String domainId = domain.getString("domainId"); + String docID = Generator.randomAlphaNumeric(5); + String docscheme = Generator.randomAlphaNumeric(5); + + String xmlContent = String.format(xmlTemplate, sg.getString("participantScheme"), pi, docscheme, docID); + + String postMeta = String.format(template, docID, docscheme, subdomain, domainCode, domainId); + + sg.getJSONArray("serviceMetadata").put(new JSONObject(postMeta).put("xmlContent", xmlContent)); + sg.put("status", 1); + + + List<NewCookie> cookies = login("SMP_ADMIN"); + + HashMap<String, String> map = getCookies(cookies); + String xsrf = map.get("XSRF-TOKEN"); + String jsessionID = map.get("JSESSIONID"); + ClientResponse getResponse = resource.path(SMPPaths.SERVICE_GROUP) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .put(ClientResponse.class, new JSONArray().put(sg).toString()); + + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static String getMetadataString(String url) { + try { + + System.out.println("url = " + url); // ------------------------------ - return client.resource(url).accept(MediaType.APPLICATION_XML).get(String.class); - } catch (Exception e) { - e.printStackTrace(); - } - return ""; - } - - private static JSONObject getUserForName(String username,String jsessionID,String xsrf) { - - try{ - String responseRaw = resource.path(SMPPaths.USER_LIST) - .queryParam("page", "-1") - .queryParam("pageSize", "-1") - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .get(String.class); - JSONArray users = new JSONObject(responseRaw).getJSONArray("serviceEntities"); - - for (int i = 0; i < users.length(); i++) { - JSONObject usr = users.getJSONObject(i); - if (username.equalsIgnoreCase(usr.getString("username"))) { - return usr; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - private static JSONObject getDomainForName(String domainName) { - List<NewCookie> cookies = login("SYS_ADMIN"); + return client.resource(url).accept(MediaType.APPLICATION_XML).get(String.class); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + private static JSONObject getUserForName(String username, String jsessionID, String xsrf) { + + try { + String responseRaw = resource.path(SMPPaths.USER_LIST) + .queryParam("page", "-1") + .queryParam("pageSize", "-1") + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .get(String.class); + JSONArray users = new JSONObject(responseRaw).getJSONArray("serviceEntities"); + + for (int i = 0; i < users.length(); i++) { + JSONObject usr = users.getJSONObject(i); + if (username.equalsIgnoreCase(usr.getString("username"))) { + return usr; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static JSONObject getDomainForName(String domainName) { + List<NewCookie> cookies = login("SYS_ADMIN"); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - try{ - String responseRaw = resource.path(SMPPaths.REST_DOMAIN_LIST) - .queryParam("page", "-1") - .queryParam("pageSize", "-1") - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .get(String.class); - JSONArray domains = new JSONObject(responseRaw).getJSONArray("serviceEntities"); - for (int i = 0; i < domains.length(); i++) { - JSONObject dom = domains.getJSONObject(i); - if (domainName.equalsIgnoreCase(dom.getString("domainCode"))) { - return dom; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - private static JSONObject getSGforPI(String pi) { - List<NewCookie> cookies = login("SMP_ADMIN"); + try { + String responseRaw = resource.path(SMPPaths.REST_DOMAIN_LIST) + .queryParam("page", "-1") + .queryParam("pageSize", "-1") + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .get(String.class); + JSONArray domains = new JSONObject(responseRaw).getJSONArray("serviceEntities"); + for (int i = 0; i < domains.length(); i++) { + JSONObject dom = domains.getJSONObject(i); + if (domainName.equalsIgnoreCase(dom.getString("domainCode"))) { + return dom; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static JSONObject getSGforPI(String pi) { + List<NewCookie> cookies = login("SMP_ADMIN"); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - try{ - String responseRaw = resource.path(SMPPaths.SERVICE_GROUP) - .queryParam("page", "-1") - .queryParam("pageSize", "-1") - .queryParam("participantIdentifier", pi) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .get(String.class); - JSONArray sgs = new JSONObject(responseRaw).getJSONArray("serviceEntities"); - for (int i = 0; i < sgs.length(); i++) { - JSONObject sg = sgs.getJSONObject(i); - if (pi.equalsIgnoreCase(sg.getString("participantIdentifier"))) { - return sg; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static boolean deleteDomain(String domainCode) { - List<NewCookie> cookies = login("SYS_ADMIN"); + try { + String responseRaw = resource.path(SMPPaths.SERVICE_GROUP) + .queryParam("page", "-1") + .queryParam("pageSize", "-1") + .queryParam("participantIdentifier", pi) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .get(String.class); + JSONArray sgs = new JSONObject(responseRaw).getJSONArray("serviceEntities"); + for (int i = 0; i < sgs.length(); i++) { + JSONObject sg = sgs.getJSONObject(i); + if (pi.equalsIgnoreCase(sg.getString("participantIdentifier"))) { + return sg; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static String getSystemInfo() { + + try { + return resource.path(SMPPaths.SYS_INFO).get(String.class); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + public static boolean deleteDomain(String domainCode) { + List<NewCookie> cookies = login("SYS_ADMIN"); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - try { - String domainPostStr = "[" + getDomainForName(domainCode).put("status", 3).toString() + "]"; - ClientResponse getResponse = resource.path(SMPPaths.REST_POST_DOMAIN) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .put(ClientResponse.class, domainPostStr); - - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static boolean deleteUser(String username) { - List<NewCookie> cookies = login("SYS_ADMIN"); + try { + String domainPostStr = "[" + getDomainForName(domainCode).put("status", 3).toString() + "]"; + ClientResponse getResponse = resource.path(SMPPaths.REST_POST_DOMAIN) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .put(ClientResponse.class, domainPostStr); + + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static boolean deleteUser(String username) { + List<NewCookie> cookies = login("SYS_ADMIN"); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - try{ - String putStr = "[" + getUserForName(username,jsessionID,xsrf).put("status", 3).toString() + "]"; - ClientResponse getResponse = resource.path(SMPPaths.USER_LIST) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .put(ClientResponse.class, putStr); - - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static boolean deleteSG(String pi) { - List<NewCookie> cookies = login("SMP_ADMIN"); + try { + String putStr = "[" + getUserForName(username, jsessionID, xsrf).put("status", 3).toString() + "]"; + ClientResponse getResponse = resource.path(SMPPaths.USER_LIST) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .put(ClientResponse.class, putStr); + + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public static boolean deleteSG(String pi) { + List<NewCookie> cookies = login("SMP_ADMIN"); HashMap<String, String> map = getCookies(cookies); String xsrf = map.get("XSRF-TOKEN"); String jsessionID = map.get("JSESSIONID"); - try{ - String putStr = "[" + getSGforPI(pi).put("status", 3).toString() + "]"; - ClientResponse getResponse = resource.path(SMPPaths.SERVICE_GROUP) - .accept(MediaType.APPLICATION_JSON_TYPE) - .type(MediaType.APPLICATION_JSON_TYPE) - .cookie(new Cookie("JSESSIONID", jsessionID)) - .cookie(new Cookie("XSRF-TOKEN", xsrf)) - .header("X-XSRF-TOKEN", xsrf) - .put(ClientResponse.class, putStr); - - return getResponse.getStatus() == 200; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - - private static JSONObject transformUserForSGPost(JSONObject user) { - try { - String template = "{\"index\":%s,\"username\":\"%s\",\"role\":\"%s\",\"userId\":%s,\"status\":0,\"password\":null,\"passwordExpireOn\":null,\"accessTokenId\":null,\"accessTokenExpireOn\":null,\"passwordExpired\":true,\"emailAddress\":\"\",\"authorities\":null,\"active\":true,\"certificate\":null,\"statusPassword\":0,\"casAuthenticated\": false,\"forceChangeExpiredPassword\": false, \"showPasswordExpirationWarning\": false}"; - String index = user.getString("index"); - String username = user.getString("username"); - String role = user.getString("role"); - String id = user.getString("userId"); - return new JSONObject(String.format(template, index, username, role, id)); - } catch (JSONException e) { - e.printStackTrace(); - } - return null; - } - - private static JSONObject transformDomainForSGPost(JSONObject domain) { - try { - String template = "{\"domainId\":%s,\"domainCode\":\"%s\",\"smlSubdomain\":\"%s\",\"id\":null,\"smlRegistered\":false,\"serviceMetadataCount\":0,\"status\":2}"; - String domainId = domain.getString("id"); - String domainCode = domain.getString("domainCode"); - String smlSubdomain = domain.getString("smlSubdomain"); - return new JSONObject(String.format(template, domainId, domainCode, smlSubdomain)); - } catch (JSONException e) { - e.printStackTrace(); - } - return null; - } + try { + String putStr = "[" + getSGforPI(pi).put("status", 3).toString() + "]"; + ClientResponse getResponse = resource.path(SMPPaths.SERVICE_GROUP) + .accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .cookie(new Cookie("JSESSIONID", jsessionID)) + .cookie(new Cookie("XSRF-TOKEN", xsrf)) + .header("X-XSRF-TOKEN", xsrf) + .put(ClientResponse.class, putStr); + + return getResponse.getStatus() == 200; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + + private static JSONObject transformUserForSGPost(JSONObject user) { + try { + String template = "{\"index\":%s,\"username\":\"%s\",\"role\":\"%s\",\"userId\":%s,\"status\":0,\"password\":null,\"passwordExpireOn\":null,\"accessTokenId\":null,\"accessTokenExpireOn\":null,\"passwordExpired\":true,\"emailAddress\":\"\",\"authorities\":null,\"active\":true,\"certificate\":null,\"statusPassword\":0,\"casAuthenticated\": false,\"forceChangeExpiredPassword\": false, \"showPasswordExpirationWarning\": false}"; + String index = user.getString("index"); + String username = user.getString("username"); + String role = user.getString("role"); + String id = user.getString("userId"); + return new JSONObject(String.format(template, index, username, role, id)); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } + + private static JSONObject transformDomainForSGPost(JSONObject domain) { + try { + String template = "{\"domainId\":%s,\"domainCode\":\"%s\",\"smlSubdomain\":\"%s\",\"id\":null,\"smlRegistered\":false,\"serviceMetadataCount\":0,\"status\":2}"; + String domainId = domain.getString("id"); + String domainCode = domain.getString("domainCode"); + String smlSubdomain = domain.getString("smlSubdomain"); + return new JSONObject(String.format(template, domainId, domainCode, smlSubdomain)); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } } diff --git a/smp-ui-tests/src/main/java/utils/customReporter/ExcelTestReporter.java b/smp-ui-tests/src/test/java/customReporter/ExcelTestReporter.java similarity index 80% rename from smp-ui-tests/src/main/java/utils/customReporter/ExcelTestReporter.java rename to smp-ui-tests/src/test/java/customReporter/ExcelTestReporter.java index 287271b8e5c017df66bd6c6da718e0d7d461c698..049b4a0a3d0ef6ca0c6cb2f4ae3cf3bcb0ff268e 100644 --- a/smp-ui-tests/src/main/java/utils/customReporter/ExcelTestReporter.java +++ b/smp-ui-tests/src/test/java/customReporter/ExcelTestReporter.java @@ -1,19 +1,24 @@ -package utils.customReporter; +package customReporter; +import org.apache.commons.io.FileUtils; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult; import org.testng.annotations.Test; +import ui.BaseTest; import utils.PROPERTIES; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; @@ -28,9 +33,8 @@ public class ExcelTestReporter implements ITestListener { @Override /*Creates the report file, the sheet and writes the headers of the table with style as well*/ public void onStart(ITestContext iTestContext) { - - - + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); String dateStr = format.format(iTestContext.getStartDate()); filename = PROPERTIES.REPORTS_FOLDER + "TestRunReport" + dateStr + ".xlsx"; @@ -47,12 +51,12 @@ public class ExcelTestReporter implements ITestListener { cell.setCellValue(headers[i]); } - try{ + try { FileOutputStream os = new FileOutputStream(filename); workbook.write(os); workbook.close(); os.close(); - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } @@ -81,6 +85,7 @@ public class ExcelTestReporter implements ITestListener { /* Writes a row in the report file with the test id, name and FAIL as status*/ @Override public void onTestFailure(ITestResult iTestResult) { + takeScreenshot(iTestResult); try { writeRowToReportFile(iTestResult, "FAIL"); } catch (Exception e) { @@ -105,27 +110,26 @@ public class ExcelTestReporter implements ITestListener { /* depending on the type of cell returns the desired style. The supported type are "Header", "Fail", "Pass" */ - private XSSFCellStyle composeCellStyle(XSSFWorkbook workbook, String type){ + private XSSFCellStyle composeCellStyle(XSSFWorkbook workbook, String type) { XSSFCellStyle style = workbook.createCellStyle(); XSSFFont font = workbook.createFont(); font.setBold(true); - if(type.equalsIgnoreCase("Pass")){ + if (type.equalsIgnoreCase("Pass")) { style.setFillBackgroundColor(IndexedColors.BRIGHT_GREEN.getIndex()); style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex()); - }else if (type.equalsIgnoreCase("Fail")){ + } else if (type.equalsIgnoreCase("Fail")) { style.setFillBackgroundColor(IndexedColors.RED.getIndex()); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFont(font); - }else if (type.equalsIgnoreCase("Skipped")){ + } else if (type.equalsIgnoreCase("Skipped")) { style.setFillBackgroundColor(IndexedColors.WHITE.getIndex()); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFont(font); - } - else if (type.equalsIgnoreCase("Header")){ + } else if (type.equalsIgnoreCase("Header")) { style.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFont(font); @@ -140,15 +144,19 @@ public class ExcelTestReporter implements ITestListener { String qualifiedName = iTestResult.getMethod().getQualifiedName(); String testType = ""; - if(qualifiedName.contains(".ui.")){testType = "UI";} - if(qualifiedName.contains(".rest.")){testType = "REST";} - + if (qualifiedName.contains(".ui.")) { + testType = "UI"; + } + if (qualifiedName.contains(".rest.")) { + testType = "REST"; + } + File myFile = new File(filename); FileInputStream inputStream = new FileInputStream(myFile); XSSFWorkbook workbook = new XSSFWorkbook(inputStream); Sheet reportSheet = workbook.getSheetAt(0); - int rowNum = reportSheet.getLastRowNum()+1; + int rowNum = reportSheet.getLastRowNum() + 1; Row currentRow = reportSheet.createRow(rowNum); currentRow.createCell(0).setCellValue(testType); @@ -162,11 +170,11 @@ public class ExcelTestReporter implements ITestListener { cell.setCellValue(result); cell.setCellStyle(composeCellStyle(workbook, result)); currentRow.createCell(7).setCellValue(sdf.format(new Date(iTestResult.getStartMillis()))); - currentRow.createCell(8).setCellValue((iTestResult.getEndMillis()-iTestResult.getStartMillis())/1000); + currentRow.createCell(8).setCellValue((iTestResult.getEndMillis() - iTestResult.getStartMillis()) / 1000); currentRow.createCell(9).setCellValue(""); currentRow.createCell(10).setCellValue(""); - if(iTestResult.getThrowable() != null){ + if (iTestResult.getThrowable() != null) { currentRow.createCell(11).setCellValue(iTestResult.getThrowable().getMessage()); } @@ -180,9 +188,21 @@ public class ExcelTestReporter implements ITestListener { } + private void takeScreenshot(ITestResult result) { + System.out.println("***** Error " + result.getName() + " test has failed *****"); + String methodName = "target/" + result.getName().toString().trim(); + WebDriver driver = ((BaseTest) result.getInstance()).driver; + File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); + try { + FileUtils.copyFile(scrFile, new File(methodName + ".png")); + System.out.println("***Placed screen shot in " + methodName + ".png ***"); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/smp-ui-tests/src/main/java/utils/customReporter/TestProgressReporter.java b/smp-ui-tests/src/test/java/customReporter/TestProgressReporter.java similarity index 93% rename from smp-ui-tests/src/main/java/utils/customReporter/TestProgressReporter.java rename to smp-ui-tests/src/test/java/customReporter/TestProgressReporter.java index af45b4cafbeb1b7baf5664b90f6db82d4eae0392..e46928bbb4b5afb854b9184f5fa6b3ffa2c1c262 100644 --- a/smp-ui-tests/src/main/java/utils/customReporter/TestProgressReporter.java +++ b/smp-ui-tests/src/test/java/customReporter/TestProgressReporter.java @@ -1,11 +1,11 @@ -package utils.customReporter; +package customReporter; import org.apache.log4j.Logger; import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult; -public class TestProgressReporter implements ITestListener { +public class TestProgressReporter implements ITestListener { static int test_count = 0; diff --git a/smp-ui-tests/src/test/java/ui/BaseTest.java b/smp-ui-tests/src/test/java/ui/BaseTest.java index 701012ff3bb609db7e71079253e10640308d43d8..6831cbb6c73c5af3552166213b6d3eadfc004b27 100644 --- a/smp-ui-tests/src/test/java/ui/BaseTest.java +++ b/smp-ui-tests/src/test/java/ui/BaseTest.java @@ -1,5 +1,7 @@ package ui; +import customReporter.ExcelTestReporter; +import customReporter.TestProgressReporter; import org.apache.log4j.Logger; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -9,8 +11,6 @@ import utils.DriverManager; import utils.Generator; import utils.PROPERTIES; import utils.TestDataProvider; -import utils.customReporter.ExcelTestReporter; -import utils.customReporter.TestProgressReporter; import utils.rest.SMPRestClient; import java.lang.reflect.Method; @@ -21,173 +21,177 @@ import java.util.List; @Listeners({ExcelTestReporter.class, TestProgressReporter.class}) public class BaseTest { - static int methodCount = 1; - - static WebDriver driver; - static TestDataProvider testDataProvider = new TestDataProvider(); - static ArrayList<String> createdDomains = new ArrayList<>(); - static ArrayList<String> createdUsers = new ArrayList<>(); - static ArrayList<String> createdServiceGroups = new ArrayList<>(); - protected Logger logger = Logger.getLogger(this.getClass()); - - @BeforeSuite(alwaysRun = true) - /*Starts the browser and navigates to the homepage. This happens once before the test - suite and the browser window is reused for all tests in suite*/ - public void beforeSuite() { - logger.info("Creating necessary data !!!!"); - createDomains(); - createUsers(); - createSGs(); - } - - - @AfterSuite(alwaysRun = true) - /*After the test suite is done we close the browser*/ - public void afterSuite() { - logger.info("Deleting created data!!!"); - - deleteTestData(); - - logger.info("Quitting!!!! Buh bye!!!"); - try { - if (null != driver) { - driver.quit(); - } - } catch (Exception e) { - logger.warn("Closing the driver failed !!!!"); - e.printStackTrace(); - } - } - - @AfterClass(alwaysRun = true) - public void afterClass() { - if (null != driver) { - driver.quit(); - } - } - - @BeforeClass(alwaysRun = true) - public void beforeClass() { - logger.info("beforeClass entry"); - driver = DriverManager.getDriver(); - driver.get(PROPERTIES.UI_BASE_URL); - logger.info("beforeClass exit"); - } - - @BeforeMethod(alwaysRun = true) - protected void logSeparator(Method method) throws Exception { - - logger.info("--------------------------- Running test number: " + methodCount); - logger.info("--------------------------- Running test method: " + method.getDeclaringClass().getSimpleName() + "." + method.getName()); - methodCount++; - } - - - private void createDomains() { - for (int i = 0; i < 5; i++) { - String generated = Generator.randomAlphaNumeric(10); - logger.info("creating domain whose value is :" + generated); - boolean created = SMPRestClient.createDomain(generated); - if (created) { - createdDomains.add(generated); - } else { - logger.warn("Test data creation: Domain creation failed for " + generated); - System.exit(-1); - } - } - } - - private void createUsers() { - String[] roles = {"SMP_ADMIN", "SERVICE_GROUP_ADMIN", "SYSTEM_ADMIN"}; - for (int i = 0; i < 6; i++) { - String generated = Generator.randomAlphaNumeric(10); - String role = roles[i % roles.length]; - boolean created = SMPRestClient.createUser(generated, role); - if (created) { - createdUsers.add(generated); - } else { - logger.warn("Test data creation: User creation failed for " + generated); - System.exit(-1); - } - } - } - - private void createSGs() { - for (int i = 0; i < 5; i++) { - String generated = Generator.randomAlphaNumeric(10); - String generatedHyphen = generated.substring(0, 3) + "-" + generated.substring(3, 6) + "-" + generated.substring(6, 9); - List<String> users = Arrays.asList(createdUsers.get(0)); - List<String> domains = Arrays.asList(createdDomains.get(0)); - boolean created = SMPRestClient.createServiceGroup(generated, generatedHyphen, users, domains); - if (created) { - createdServiceGroups.add(generated); - } else { - logger.warn("Test data creation: SG creation failed for " + generated); - System.exit(-1); - } - } - } - - private void deleteTestData() { - for (String createdServiceGroup : createdServiceGroups) { - try { - SMPRestClient.deleteSG(createdServiceGroup); - } catch (Exception e) { - e.printStackTrace(); - } - } - for (String createdUser : createdUsers) { - try { - SMPRestClient.deleteUser(createdUser); - } catch (Exception e) { - e.printStackTrace(); - } - } - for (String createdDomain : createdDomains) { - try { - SMPRestClient.deleteDomain(createdDomain); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - - protected void genericLogoutProcedure() { - logger.info("executing the generic logout procedure"); - - SMPPage page = new SMPPage(driver); - page.refreshPage(); - - try { - if (page.pageHeader.sandwichMenu.isLoggedIn()) { - logger.info("Logout!!"); - page.pageHeader.sandwichMenu.logout(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - driver.manage().deleteAllCookies(); - ((JavascriptExecutor) driver).executeScript("localStorage.clear();"); - - page.refreshPage(); - page.waitForXMillis(100); - } - - protected SMPPage genericLoginProcedure(String role) { - SMPPage page = new SMPPage(driver); - - genericLogoutProcedure(); - - if (!page.pageHeader.sandwichMenu.isLoggedIn()) { - logger.info("Login!!"); - page.pageHeader.goToLogin().login(role); - } - - page.waitForRowsToLoad(); - return page; - } + public static WebDriver driver; + static int methodCount = 1; + static TestDataProvider testDataProvider = new TestDataProvider(); + static ArrayList<String> createdDomains = new ArrayList<>(); + static ArrayList<String> createdUsers = new ArrayList<>(); + static ArrayList<String> createdServiceGroups = new ArrayList<>(); + protected Logger logger = Logger.getLogger(this.getClass()); + + @BeforeSuite(alwaysRun = true) + public void beforeSuite() { + + logger.info("********************** SUT Info **********************"); + + System.out.println(SMPRestClient.getSystemInfo()); + + logger.info("********************** SUT Info **********************"); + + logger.info("Creating necessary data !!!!"); + createDomains(); + createUsers(); + createSGs(); + } + + + @AfterSuite(alwaysRun = true) + /*After the test suite is done, we close the browser*/ + public void afterSuite() { + logger.info("Deleting created data!!!"); + + deleteTestData(); + + logger.info("Quitting!!!! Buh bye!!!"); + try { + if (null != driver) { + driver.quit(); + } + } catch (Exception e) { + logger.warn("Closing the driver failed !!!!"); + e.printStackTrace(); + } + } + + @AfterClass(alwaysRun = true) + public void afterClass() { + if (null != driver) { + driver.quit(); + } + } + + @BeforeClass(alwaysRun = true) + public void beforeClass() { + logger.info("beforeClass entry"); + driver = DriverManager.getDriver(); + driver.get(PROPERTIES.UI_BASE_URL); + logger.info("beforeClass exit"); + } + + @BeforeMethod(alwaysRun = true) + protected void logSeparator(Method method) throws Exception { + + logger.info("--------------------------- Running test number: " + methodCount); + logger.info("--------------------------- Running test method: " + method.getDeclaringClass().getSimpleName() + "." + method.getName()); + methodCount++; + } + + + private void createDomains() { + for (int i = 0; i < 5; i++) { + String generated = Generator.randomAlphaNumeric(10); + logger.info("creating domain whose value is :" + generated); + boolean created = SMPRestClient.createDomain(generated); + if (created) { + createdDomains.add(generated); + } else { + logger.warn("Test data creation: Domain creation failed for " + generated); + System.exit(-1); + } + } + } + + private void createUsers() { + String[] roles = {"SMP_ADMIN", "SERVICE_GROUP_ADMIN", "SYSTEM_ADMIN"}; + for (int i = 0; i < 6; i++) { + String generated = Generator.randomAlphaNumeric(10); + String role = roles[i % roles.length]; + boolean created = SMPRestClient.createUser(generated, role); + if (created) { + createdUsers.add(generated); + } else { + logger.warn("Test data creation: User creation failed for " + generated); + System.exit(-1); + } + } + } + + private void createSGs() { + for (int i = 0; i < 5; i++) { + String generated = Generator.randomAlphaNumeric(10); + String generatedHyphen = generated.substring(0, 3) + "-" + generated.substring(3, 6) + "-" + generated.substring(6, 9); + List<String> users = Arrays.asList(createdUsers.get(0)); + List<String> domains = Arrays.asList(createdDomains.get(0)); + boolean created = SMPRestClient.createServiceGroup(generated, generatedHyphen, users, domains); + if (created) { + createdServiceGroups.add(generated); + } else { + logger.warn("Test data creation: SG creation failed for " + generated); + System.exit(-1); + } + } + } + + private void deleteTestData() { + for (String createdServiceGroup : createdServiceGroups) { + try { + SMPRestClient.deleteSG(createdServiceGroup); + } catch (Exception e) { + e.printStackTrace(); + } + } + for (String createdUser : createdUsers) { + try { + SMPRestClient.deleteUser(createdUser); + } catch (Exception e) { + e.printStackTrace(); + } + } + for (String createdDomain : createdDomains) { + try { + SMPRestClient.deleteDomain(createdDomain); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + protected void genericLogoutProcedure() { + logger.info("executing the generic logout procedure"); + + SMPPage page = new SMPPage(driver); + page.refreshPage(); + + try { + if (page.pageHeader.sandwichMenu.isLoggedIn()) { + logger.info("Logout!!"); + page.pageHeader.sandwichMenu.logout(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + driver.manage().deleteAllCookies(); + ((JavascriptExecutor) driver).executeScript("localStorage.clear();"); + + page.refreshPage(); + page.waitForXMillis(100); + } + + protected SMPPage genericLoginProcedure(String role) { + SMPPage page = new SMPPage(driver); + + genericLogoutProcedure(); + + if (!page.pageHeader.sandwichMenu.isLoggedIn()) { + logger.info("Login!!"); + page.pageHeader.goToLogin().login(role); + } + + page.waitForRowsToLoad(); + return page; + } } diff --git a/smp-ui-tests/src/test/java/ui/EditPgTest.java b/smp-ui-tests/src/test/java/ui/EditPgTest.java index 1ddfd3bfcc9489281e2f0385b9e27a46523dc8e7..f00178500a2cfe4075c5c22f8e5101c007dcf9d7 100644 --- a/smp-ui-tests/src/test/java/ui/EditPgTest.java +++ b/smp-ui-tests/src/test/java/ui/EditPgTest.java @@ -305,7 +305,6 @@ public class EditPgTest extends BaseTest { SMPRestClient.deleteSG(identifier); identifier = Generator.randomAlphaNumeric(10); -// scheme = Generator.randomAlphaNumeric(10); popup = page.clickNew(); popup.fillParticipantIdentifier(identifier); diff --git a/smp-ui-tests/src/test/java/ui/LoginPgTest.java b/smp-ui-tests/src/test/java/ui/LoginPgTest.java index 2c477115b45580eff07e395f02a96686ca7700e7..1dc0d7f79f34c6bb70c8379818bfd41f239de6ba 100644 --- a/smp-ui-tests/src/test/java/ui/LoginPgTest.java +++ b/smp-ui-tests/src/test/java/ui/LoginPgTest.java @@ -160,12 +160,6 @@ public class LoginPgTest extends BaseTest { soft.assertAll(); } - // This will serve as a reminder to check this message manually - @Test(description = "LGN-50") - public void SMPNotRunningTest() { - throw new SkipException("This test will be executed manually !!!"); - } - @Test(description = "LGN-60") public void loginButtonDisableVerification() { SoftAssert soft = new SoftAssert(); diff --git a/smp-ui-tests/src/test/java/ui/PropertiesPgTest.java b/smp-ui-tests/src/test/java/ui/PropertiesPgTest.java index 36c72ef26f622c1c54d5fb8621d7abe13521573d..768dab82c6b8c6a1801ffc7878ec3473638cc61d 100644 --- a/smp-ui-tests/src/test/java/ui/PropertiesPgTest.java +++ b/smp-ui-tests/src/test/java/ui/PropertiesPgTest.java @@ -4,11 +4,7 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.testng.asserts.SoftAssert; -import pages.components.ConfirmationDialog; import pages.components.baseComponents.SMPPage; -import pages.components.messageArea.AlertMessage; -import pages.domain.DomainRow; -import pages.login.LoginPage; import pages.properties.PropertiesPage; import pages.properties.PropertyPopup; import pages.properties.PropertyRowInfo; @@ -17,100 +13,96 @@ import pages.service_groups.edit.ServiceGroupPopup; import pages.service_groups.search.SearchPage; import utils.Generator; import utils.enums.SMPMessages; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class PropertiesPgTest extends BaseTest{ - @AfterMethod - public void logoutAndReset(){ - genericLogoutProcedure(); - } - - - @BeforeMethod - public void loginAndGoToDomainPage(){ - - SMPPage page = genericLoginProcedure("SYS_ADMIN"); - - logger.info("Going to Property page"); - page.sidebar.goToPage(PropertiesPage.class); - } - - /*@Test(description = "PROP-0")*/ - @Test(enabled = false) - public void verifyParticipantschemeMandatoryProperty(){ - - SoftAssert soft = new SoftAssert(); - String property = "identifiersBehaviour.scheme.mandatory"; - - PropertiesPage propertiesPage = new PropertiesPage(driver); - propertiesPage.propertySearch(property); - soft.assertTrue(propertiesPage.grid().rowContainPropertyName(property),"The row does not contain the searching property"); - PropertyRowInfo newRow0 = propertiesPage.grid().getRows().get(0); - System.out.println("newRow0.getPropertyvalue() "+newRow0.getPropertyvalue()); - if(newRow0.getPropertyvalue().equals("true")) - { - propertiesPage.grid().selectRow(0); - PropertyPopup popup = propertiesPage.clickEdit(); - propertiesPage = popup.disableCheckboxOfProperty(); - soft.assertTrue(propertiesPage.isSaveButtonEnabled(),"Save button is disbled"); - propertiesPage.clickSave().confirm(); - soft.assertTrue(propertiesPage.alertArea.getAlertMessage().isError(), "Message listed is success"); - soft.assertTrue(propertiesPage.alertArea.getAlertMessage().getMessage().equalsIgnoreCase(SMPMessages.MSG_18), "Message is not listed is as expected"); - } - - propertiesPage.pageHeader.sandwichMenu.logout(); - SearchPage page = new SearchPage(driver); - logger.info("Going to login page"); - page.pageHeader.goToLogin(); - SMPPage smpPage= genericLoginProcedure("SMP_ADMIN"); - smpPage.sidebar.goToPage(EditPage.class); - EditPage editPage = new EditPage(driver); - ServiceGroupPopup servicePopup = editPage.clickNew(); - soft.assertTrue(servicePopup.isParticipantIdentifierInputEnabled(), "Participant Identifier field is disabled"); - soft.assertTrue(servicePopup.isParticipantSchemeInputEnabled(), "Participant Scheme field is disabled"); - soft.assertTrue(servicePopup.isOwnersPanelEnabled(), "Owners panel is enabled"); - soft.assertTrue(servicePopup.isDomainsPanelEnabled(), "Domain panel is enabled"); - servicePopup.fillParticipantIdentifier("sonbrat1223"); - servicePopup.chooseFirstOwner(); - servicePopup.chooseFirstDomain(); - - soft.assertTrue(servicePopup.isOKButtonEnable(),"Ok button is not enabled after creating servicegroup without scheme"); - soft.assertTrue(servicePopup.isCancelButtonEnable(),"cancel button is not enabled after creating servicegroup without scheme"); - - servicePopup.clickOK(); - - soft.assertTrue(editPage.isSaveButtonEnabled(),"Save button is not enable after cration of servicegroup without scheme"); - soft.assertTrue(editPage.isCancelButtonEnabled(),"Cancel button is not enable after cration of servicegroup without scheme"); - editPage.clickSave().confirm();; - - soft.assertTrue(editPage.alertArea.getAlertMessage().getMessage().equalsIgnoreCase(SMPMessages.MSG_18), "Message is not listed is as expected"); - - soft.assertAll(); - } - - @Test(description = "PROP-10") - public void smpAlertPasswordExpiredMailSubjectAllowString() - { - SoftAssert soft = new SoftAssert(); - String property = "smp.alert.password.expired.mail.subject"; - String string = Generator.randomAlphaNumeric(10); - - PropertiesPage propertiesPage = new PropertiesPage(driver); - propertiesPage.propertySearch(property); - soft.assertTrue(propertiesPage.grid().rowContainPropertyName(property),"The row does not contain the searching property"); - int index = 0; - propertiesPage.grid().selectRow(index); - PropertyPopup popup = propertiesPage.clickEdit(); - String sentence = " "; - for(int i=0;i<26;i++) { - sentence = sentence + string; - } - popup.editInputField(sentence); - popup.clickOK(); - soft.assertTrue(propertiesPage.getErrorMessage().equalsIgnoreCase(SMPMessages.MSG_23),"the errors message is not showing"); - popup.clickCancel(); - soft.assertAll(); - } + +public class PropertiesPgTest extends BaseTest { + @AfterMethod + public void logoutAndReset() { + genericLogoutProcedure(); + } + + + @BeforeMethod + public void loginAndGoToDomainPage() { + + SMPPage page = genericLoginProcedure("SYS_ADMIN"); + + logger.info("Going to Property page"); + page.sidebar.goToPage(PropertiesPage.class); + } + + /*@Test(description = "PROP-0")*/ + @Test(description = "PROP-0", enabled = false) + public void verifyParticipantschemeMandatoryProperty() { + + SoftAssert soft = new SoftAssert(); + String property = "identifiersBehaviour.scheme.mandatory"; + + PropertiesPage propertiesPage = new PropertiesPage(driver); + propertiesPage.propertySearch(property); + soft.assertTrue(propertiesPage.grid().rowContainPropertyName(property), "The row does not contain the searching property"); + PropertyRowInfo newRow0 = propertiesPage.grid().getRows().get(0); + + if (newRow0.getPropertyvalue().equals("true")) { + propertiesPage.grid().selectRow(0); + PropertyPopup popup = propertiesPage.clickEdit(); + propertiesPage = popup.disableCheckboxOfProperty(); + soft.assertTrue(propertiesPage.isSaveButtonEnabled(), "Save button is disbled"); + propertiesPage.clickSave().confirm(); + soft.assertTrue(propertiesPage.alertArea.getAlertMessage().isError(), "Message listed is success"); + soft.assertTrue(propertiesPage.alertArea.getAlertMessage().getMessage().equalsIgnoreCase(SMPMessages.MSG_18), "Message is not listed is as expected"); + } + + propertiesPage.pageHeader.sandwichMenu.logout(); + SearchPage page = new SearchPage(driver); + logger.info("Going to login page"); + page.pageHeader.goToLogin(); + SMPPage smpPage = genericLoginProcedure("SMP_ADMIN"); + smpPage.sidebar.goToPage(EditPage.class); + EditPage editPage = new EditPage(driver); + ServiceGroupPopup servicePopup = editPage.clickNew(); + soft.assertTrue(servicePopup.isParticipantIdentifierInputEnabled(), "Participant Identifier field is disabled"); + soft.assertTrue(servicePopup.isParticipantSchemeInputEnabled(), "Participant Scheme field is disabled"); + soft.assertTrue(servicePopup.isOwnersPanelEnabled(), "Owners panel is enabled"); + soft.assertTrue(servicePopup.isDomainsPanelEnabled(), "Domain panel is enabled"); + servicePopup.fillParticipantIdentifier("sonbrat1223"); + servicePopup.chooseFirstOwner(); + servicePopup.chooseFirstDomain(); + + soft.assertTrue(servicePopup.isOKButtonEnable(), "Ok button is not enabled after creating servicegroup without scheme"); + soft.assertTrue(servicePopup.isCancelButtonEnable(), "cancel button is not enabled after creating servicegroup without scheme"); + + servicePopup.clickOK(); + + soft.assertTrue(editPage.isSaveButtonEnabled(), "Save button is not enable after cration of servicegroup without scheme"); + soft.assertTrue(editPage.isCancelButtonEnabled(), "Cancel button is not enable after cration of servicegroup without scheme"); + editPage.clickSave().confirm(); + ; + + soft.assertTrue(editPage.alertArea.getAlertMessage().getMessage().equalsIgnoreCase(SMPMessages.MSG_18), "Message is not listed is as expected"); + + soft.assertAll(); + } + + @Test(description = "PROP-10") + public void smpAlertPasswordExpiredMailSubjectAllowString() { + SoftAssert soft = new SoftAssert(); + String property = "smp.alert.password.expired.mail.subject"; + String string = Generator.randomAlphaNumeric(10); + + PropertiesPage propertiesPage = new PropertiesPage(driver); + propertiesPage.propertySearch(property); + soft.assertTrue(propertiesPage.grid().rowContainPropertyName(property), "The row does not contain the searching property"); + int index = 0; + propertiesPage.grid().selectRow(index); + PropertyPopup popup = propertiesPage.clickEdit(); + String sentence = " "; + for (int i = 0; i < 26; i++) { + sentence = sentence + string; + } + popup.editInputField(sentence); + popup.clickOK(); + soft.assertTrue(propertiesPage.getErrorMessage().equalsIgnoreCase(SMPMessages.MSG_23), "the errors message is not showing"); + popup.clickCancel(); + soft.assertAll(); + } }