Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 410ffab4 authored by Catalin COMANICI's avatar Catalin COMANICI
Browse files

Pull request #2: PerformanceImprovements

Merge in EDELIVERY/smp from performanceImprovements to development

* commit 'edb5b5fc':
  added screenshots on test failure, SUT info, and other minor fixes
  minor fixes
  ...increased wait time for element to be gone
  minor fixes
parents bc1916f5 edb5b5fc
No related branches found
No related tags found
No related merge requests found
Showing
with 954 additions and 993 deletions
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> 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> <modelVersion>4.0.0</modelVersion>
<groupId>com.test.smp</groupId> <groupId>com.test.smp</groupId>
<artifactId>SMPUIAutomation</artifactId> <artifactId>SMPUIAutomation</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<url>http://localhost:8080/smp</url> <url>http://localhost:8982/smp</url>
<gecko.driver.path>drivers/geckodriver.exe</gecko.driver.path> <gecko.driver.path>drivers/geckodriver</gecko.driver.path>
<chrome.driver.path>drivers/chromedriver.exe</chrome.driver.path> <chrome.driver.path>drivers/chromedriver</chrome.driver.path>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
<version>1.2.17</version> <version>1.2.17</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>
<version>7.0.0-beta1</version> <version>7.0.0-beta1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<version>3.14.0</version> <version>3.14.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<version>3.17</version> <version>3.17</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.reflections</groupId> <groupId>org.reflections</groupId>
<artifactId>reflections</artifactId> <artifactId>reflections</artifactId>
<version>0.9.11</version> <version>0.9.11</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20080701</version> <version>20080701</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.thoughtworks.xstream</groupId> <groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId> <artifactId>xstream</artifactId>
<version>1.4.10</version> <version>1.4.10</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId> <artifactId>jersey-client</artifactId>
<version>1.19.4</version> <version>1.19.4</version>
</dependency> </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> </dependencies>
<profiles> <profiles>
<profile> <profile>
<id>smp_e5</id> <id>smp_e5</id>
<activation> <activation>
<activeByDefault>true</activeByDefault> <activeByDefault>true</activeByDefault>
</activation> </activation>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version> <version>2.22.1</version>
<configuration> <configuration>
<failIfNoTests>true</failIfNoTests> <failIfNoTests>true</failIfNoTests>
<systemPropertyVariables> <systemPropertyVariables>
<webdriver.chrome.driver>${chrome.driver.path}</webdriver.chrome.driver> <webdriver.chrome.driver>${chrome.driver.path}</webdriver.chrome.driver>
<webdriver.gecko.driver>chromedriver.exe</webdriver.gecko.driver> <webdriver.gecko.driver>chromedriver.exe</webdriver.gecko.driver>
<reports.folder>./target/</reports.folder> <reports.folder>./target/</reports.folder>
<data.folder>.\src\main\resources\</data.folder> <data.folder>./src/main/resources/</data.folder>
<testdata.file>testData.json</testdata.file> <testdata.file>testData.json</testdata.file>
<LONG_TIMEOUT>30</LONG_TIMEOUT> <LONG_TIMEOUT>30</LONG_TIMEOUT>
<SHORT_TIMEOUT>5</SHORT_TIMEOUT> <SHORT_TIMEOUT>5</SHORT_TIMEOUT>
<UI_BASE_URL>${url}/ui/</UI_BASE_URL> <UI_BASE_URL>${url}/ui/</UI_BASE_URL>
</systemPropertyVariables> </systemPropertyVariables>
<properties> <properties>
<property> <property>
<name>usedefaultlisteners</name> <name>usedefaultlisteners</name>
<value>true</value> <value>true</value>
</property> </property>
</properties> </properties>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>
<profile> <profile>
<id>ubuntu</id> <id>ubuntu</id>
<activation> <activation>
<activeByDefault>false</activeByDefault> <activeByDefault>false</activeByDefault>
</activation> </activation>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version> <version>2.22.1</version>
<configuration> <configuration>
<failIfNoTests>true</failIfNoTests> <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>
<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> </project>
\ No newline at end of file
package pages.components; package pages.components;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
...@@ -13,32 +11,28 @@ import utils.PROPERTIES; ...@@ -13,32 +11,28 @@ import utils.PROPERTIES;
public class ConfirmationDialog extends PageComponent { public class ConfirmationDialog extends PageComponent {
public ConfirmationDialog(WebDriver driver) {
super(driver);
PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this);
}
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "yesbuttondialog_id") @FindBy(id = "yesbuttondialog_id")
private WebElement yesBtn; private WebElement yesBtn;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "nobuttondialog_id") @FindBy(id = "nobuttondialog_id")
private WebElement noBtn; 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"); log.info("dialog .. confirm");
waitForElementToBeClickable(yesBtn); waitForElementToBeClickable(yesBtn);
yesBtn.click(); yesBtn.click();
waitForElementToBeGone(yesBtn); waitForElementToBeGone(yesBtn);
} }
public void cancel(){ public void cancel() {
log.info("dialog .. cancel"); log.info("dialog .. cancel");
waitForElementToBeClickable(noBtn); waitForElementToBeClickable(noBtn);
/* Actions actions = new Actions(driver);
actions.moveToElement(noBtn).click().build().perform();*/
//((JavascriptExecutor) driver).executeScript("arguments[0].click();", noBtn);
noBtn.click(); noBtn.click();
waitForElementToBeGone(noBtn); waitForElementToBeGone(noBtn);
} }
......
...@@ -14,38 +14,36 @@ import java.util.List; ...@@ -14,38 +14,36 @@ import java.util.List;
public class GenericSelect extends PageComponent { 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) { public GenericSelect(WebDriver driver, WebElement container) {
super(driver); super(driver);
log.info("select init"); log.info("select init");
this.container = container; this.container = container;
PageFactory.initElements(new DefaultElementLocatorFactory(container), this); PageFactory.initElements(new DefaultElementLocatorFactory(container), this);
} }
private WebElement container; private void expandSelect() {
@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(){
log.info("expand select"); log.info("expand select");
waitForElementToBeClickable(expandoButton).click(); waitForElementToBeClickable(expandoButton);
waitForXMillis(500);
expandoButton.click();
} }
private List<WebElement> getOptions(){ private List<WebElement> getOptions() {
expandSelect(); expandSelect();
log.info("getting options"); log.info("getting options");
return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(optionSelector)); return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(optionSelector));
} }
public List<String> getOptionTexts(){ public List<String> getOptionTexts() {
log.info("get displayed option texts"); log.info("get displayed option texts");
List<WebElement> options = getOptions(); List<WebElement> options = getOptions();
List<String> optionTexts = new ArrayList<>(); List<String> optionTexts = new ArrayList<>();
...@@ -56,13 +54,13 @@ public class GenericSelect extends PageComponent { ...@@ -56,13 +54,13 @@ public class GenericSelect extends PageComponent {
return optionTexts; return optionTexts;
} }
public boolean selectOptionWithText(String text){ public boolean selectOptionWithText(String text) {
log.info("selecting option with text" + text); log.info("selecting option with text" + text);
List<WebElement> options = getOptions(); List<WebElement> options = getOptions();
for (WebElement option : options) { for (WebElement option : options) {
if(option.getText().trim().equalsIgnoreCase(text)){ if (option.getText().trim().equalsIgnoreCase(text)) {
waitForElementToBeClickable(option).click(); waitForElementToBeClickable(option).click();
waitForElementToBeGone(option); waitForElementToBeGone(option);
log.info("return type is True"); log.info("return type is True");
...@@ -73,7 +71,7 @@ public class GenericSelect extends PageComponent { ...@@ -73,7 +71,7 @@ public class GenericSelect extends PageComponent {
return false; return false;
} }
public boolean selectFirstOption(){ public boolean selectFirstOption() {
log.info("selecting first option"); log.info("selecting first option");
List<WebElement> options = getOptions(); List<WebElement> options = getOptions();
...@@ -82,7 +80,8 @@ public class GenericSelect extends PageComponent { ...@@ -82,7 +80,8 @@ public class GenericSelect extends PageComponent {
waitForElementToBeGone(option); waitForElementToBeGone(option);
return true; return true;
} }
public boolean selectWithIndex(int index){
public boolean selectWithIndex(int index) {
log.info("selecting the required option"); log.info("selecting the required option");
List<WebElement> options = getOptions(); List<WebElement> options = getOptions();
...@@ -93,7 +92,6 @@ public class GenericSelect extends PageComponent { ...@@ -93,7 +92,6 @@ public class GenericSelect extends PageComponent {
} }
public String getSelectedValue() { public String getSelectedValue() {
log.info("getting current selected value"); log.info("getting current selected value");
return currentValueElement.getText().trim(); return currentValueElement.getText().trim();
...@@ -107,20 +105,22 @@ public class GenericSelect extends PageComponent { ...@@ -107,20 +105,22 @@ public class GenericSelect extends PageComponent {
List<WebElement> options = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(optionSelector)); List<WebElement> options = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(optionSelector));
for (WebElement option : options) { for (WebElement option : options) {
String optionDomain = option.getText().trim(); String optionDomain = option.getText().trim();
if(optionDomain.equalsIgnoreCase(text)){ if (optionDomain.equalsIgnoreCase(text)) {
option.click(); option.click();
waitForElementToBeGone(option); waitForElementToBeGone(option);
return true; 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; return false;
} }
public boolean isLoaded() { public boolean isLoaded() {
log.info("assert loaded state"); log.info("assert loaded state");
waitForElementToBeVisible(expandoButton); waitForElementToBeVisible(expandoButton);
if(!expandoButton.isDisplayed()){ return false;} if (!expandoButton.isDisplayed()) {
return false;
}
return currentValueElement.isDisplayed(); return currentValueElement.isDisplayed();
} }
} }
...@@ -7,52 +7,40 @@ import org.openqa.selenium.support.FindBy; ...@@ -7,52 +7,40 @@ import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import pages.components.baseComponents.Header; import pages.components.baseComponents.Header;
import pages.components.baseComponents.SMPPage;
import pages.components.baseComponents.PageComponent; import pages.components.baseComponents.PageComponent;
import pages.service_groups.search.SearchPage; import pages.components.baseComponents.SMPPage;
import utils.PROPERTIES; import utils.PROPERTIES;
import java.security.PublicKey;
import java.util.List;
public class Sidebar extends PageComponent { public class Sidebar extends PageComponent {
public Sidebar(WebDriver driver) {
super(driver);
PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this);
}
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@FindBy(tagName = "mat-sidenav") @FindBy(tagName = "mat-sidenav")
private WebElement sideBar; private WebElement sideBar;
private WebElement topLogo; private WebElement topLogo;
private WebElement topLogoText; private WebElement topLogoText;
@FindBy(id = "sidebar_search_id") @FindBy(id = "sidebar_search_id")
private WebElement searchLnk; private WebElement searchLnk;
@FindBy(id = "sidebar_edit_id") @FindBy(id = "sidebar_edit_id")
private WebElement editLnk; private WebElement editLnk;
@FindBy(id = "sidebar_domain_id") @FindBy(id = "sidebar_domain_id")
private WebElement domainLnk; private WebElement domainLnk;
@FindBy(id = "sidebar_user_id") @FindBy(id = "sidebar_user_id")
private WebElement userLnk; private WebElement userLnk;
@FindBy(id = "sidebar_property_id") @FindBy(id = "sidebar_property_id")
private WebElement propertyLnk; private WebElement propertyLnk;
@FindBy(css = "mat-icon[role=img][mattooltip=Collapse]") @FindBy(css = "mat-icon[role=img][mattooltip=Collapse]")
private WebElement collapseButton; private WebElement collapseButton;
@FindBy(xpath = "//button[@id='sidebar_search_id']//span[text()='Search']") @FindBy(xpath = "//button[@id='sidebar_search_id']//span[text()='Search']")
private WebElement sidebarSearchText; 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 /* 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 */ 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()); log.info("Navigating to " + expect.getSimpleName());
switch (expect.getSimpleName()) { switch (expect.getSimpleName()) {
...@@ -82,25 +70,31 @@ public class Sidebar extends PageComponent { ...@@ -82,25 +70,31 @@ public class Sidebar extends PageComponent {
return PageFactory.initElements(driver, expect); return PageFactory.initElements(driver, expect);
} }
public boolean isSearchLnkEnabled(){ public boolean isSearchLnkEnabled() {
return isVisible(searchLnk) && isEnabled(searchLnk); return isVisible(searchLnk) && isEnabled(searchLnk);
} }
public boolean isEditLnkEnabled(){
public boolean isEditLnkEnabled() {
return isVisible(editLnk) && isEnabled(editLnk); return isVisible(editLnk) && isEnabled(editLnk);
} }
public boolean isDomainLnkEnabled(){
public boolean isDomainLnkEnabled() {
return isVisible(domainLnk) && isEnabled(domainLnk); return isVisible(domainLnk) && isEnabled(domainLnk);
} }
public boolean isUsersLnkEnabled(){
public boolean isUsersLnkEnabled() {
return isVisible(userLnk) && isEnabled(userLnk); return isVisible(userLnk) && isEnabled(userLnk);
} }
public boolean isSidebarSearchTextEnable(){
public boolean isSidebarSearchTextEnable() {
return isVisible(sidebarSearchText) && isEnabled(sidebarSearchText); return isVisible(sidebarSearchText) && isEnabled(sidebarSearchText);
} }
public void collapsingSideBar(){
public void collapsingSideBar() {
collapseButton.click(); collapseButton.click();
} }
public void expandingSideBar(){
public void expandingSideBar() {
driver.findElement(By.cssSelector("mat-icon[role=img][mattooltip=Expand]")).click(); driver.findElement(By.cssSelector("mat-icon[role=img][mattooltip=Expand]")).click();
} }
} }
package pages.components.baseComponents; package pages.components.baseComponents;
import com.google.common.base.Stopwatch;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.JavascriptExecutor;
...@@ -17,7 +18,7 @@ public class PageComponent { ...@@ -17,7 +18,7 @@ public class PageComponent {
protected WebDriver driver; protected WebDriver driver;
protected WebDriverWait wait; protected WebDriverWait wait;
protected Logger log = Logger.getLogger(this.getClass()); 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) { public PageComponent(WebDriver driver) {
...@@ -41,8 +42,8 @@ public class PageComponent { ...@@ -41,8 +42,8 @@ public class PageComponent {
int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000; int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000;
int waitedSoFar = 0; int waitedSoFar = 0;
while ((null != element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) { while ((null != element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) {
waitedSoFar += 300; waitedSoFar += 100;
waitForXMillis(300); waitForXMillis(100);
} }
} }
...@@ -50,63 +51,15 @@ public class PageComponent { ...@@ -50,63 +51,15 @@ public class PageComponent {
int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000; int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000;
int waitedSoFar = 0; int waitedSoFar = 0;
while ((null == element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) { while ((null == element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) {
waitedSoFar += 300; waitedSoFar += 100;
waitForXMillis(300); waitForXMillis(100);
} }
} }
public void waitForElementToBeGone(WebElement element) { public void waitForElementToBeGone(WebElement element) {
WebDriverWait myWait = new WebDriverWait(driver, 1); waitForXMillis(1000);
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;
}
} }
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) { public void waitForNumberOfWindowsToBe(int noOfWindows) {
try { try {
...@@ -163,12 +116,13 @@ public class PageComponent { ...@@ -163,12 +116,13 @@ public class PageComponent {
public void waitForElementToBe(WebElement element) { public void waitForElementToBe(WebElement element) {
wait.until(new ExpectedCondition<Boolean>() { wait.until(ExpectedConditions.visibilityOf(element));
@Override // wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) { // @Override
return element.getLocation() != null; // public Boolean apply(WebDriver driver) {
} // return element.getLocation() != null;
}); // }
// });
} }
...@@ -221,12 +175,23 @@ public class PageComponent { ...@@ -221,12 +175,23 @@ public class PageComponent {
} }
public void waitForRowsToLoad() { public void waitForRowsToLoad() {
log.info("waiting for rows to load"); log.info("waiting for rows to load");
try { 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) { } catch (Exception e) {
} }
waitForXMillis(500);
} }
......
...@@ -46,12 +46,6 @@ public class DomainPopup extends PageComponent { ...@@ -46,12 +46,6 @@ public class DomainPopup extends PageComponent {
@FindBy(css = "#smlClientCertHeaderAuth_id-input") @FindBy(css = "#smlClientCertHeaderAuth_id-input")
WebElement userClientCertHeaderToggleInput; 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") @FindBy(css = "div.mat-form-field-infix > div.ng-star-inserted")
WebElement domainCodeValidationError; WebElement domainCodeValidationError;
...@@ -62,6 +56,7 @@ public class DomainPopup extends PageComponent { ...@@ -62,6 +56,7 @@ public class DomainPopup extends PageComponent {
public void clickOK() { public void clickOK() {
waitForElementToBeClickable(okBtn).click(); waitForElementToBeClickable(okBtn).click();
waitForXMillis(500);
waitForElementToBeGone(okBtn); waitForElementToBeGone(okBtn);
} }
......
package pages.keystore; package pages.keystore;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import pages.components.baseComponents.PageComponent; import pages.components.baseComponents.PageComponent;
import pages.domain.DomainGrid;
import pages.domain.DomainPage; import pages.domain.DomainPage;
import utils.PROPERTIES; import utils.PROPERTIES;
public class KeyStoreEditDialog extends PageComponent { public class KeyStoreEditDialog extends PageComponent {
public KeyStoreEditDialog(WebDriver driver){ @FindBy(css = "#keystoreTable_id")
super(driver); private WebElement keystoreTable;
PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); @FindBy(xpath = "//span[text()='Import keystore']")
private WebElement importKeystore;
} @FindBy(css = "button[mat-dialog-close]")
private WebElement closeBtn;
@FindBy(css = "#keystoreTable_id")
private WebElement keystoreTable; public KeyStoreEditDialog(WebDriver driver) {
super(driver);
@FindBy(xpath = "//span[text()='Import keystore']") PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this);
private WebElement importKeystore;
}
@FindBy(css = "button[mat-dialog-close]")
private WebElement closeBtn; public KeyStoreImportDialog clickImportKeystore() {
log.info("clicking import keystore");
public KeyStoreImportDialog clickImportKeystore() waitForElementToBeClickable(importKeystore).click();
{ waitForElementToBeGone(importKeystore);
log.info("clicking import keystore"); return new KeyStoreImportDialog(driver);
waitForElementToBeClickable(importKeystore).click(); }
waitForElementToBeGone(importKeystore);
return new KeyStoreImportDialog(driver); public DomainPage clickCloseInKeystore() {
} log.info("clicking close btn in keystore edit dialog");
waitForElementToBeClickable(closeBtn).click();
public DomainPage clickCloseInKeystore(){ waitForElementToBeGone(closeBtn);
log.info("clicking close btn in keystore edit dialog"); return new DomainPage(driver);
waitForElementToBeClickable(closeBtn).click(); }
waitForElementToBeGone(closeBtn);
return new DomainPage(driver); public KeyStoreGrid grid() {
} return new KeyStoreGrid(driver, keystoreTable);
}
public KeyStoreGrid grid(){
return new KeyStoreGrid(driver, keystoreTable);
}
} }
...@@ -5,7 +5,6 @@ import org.openqa.selenium.WebElement; ...@@ -5,7 +5,6 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import pages.components.ConfirmationDialog;
import pages.components.baseComponents.SMPPage; import pages.components.baseComponents.SMPPage;
import pages.service_groups.search.SearchPage; import pages.service_groups.search.SearchPage;
import utils.PROPERTIES; import utils.PROPERTIES;
...@@ -15,48 +14,44 @@ import java.util.HashMap; ...@@ -15,48 +14,44 @@ import java.util.HashMap;
public class LoginPage extends SMPPage { 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") @FindBy(id = "username_id")
private WebElement username; private WebElement username;
@FindBy(id = "password_id") @FindBy(id = "password_id")
private WebElement password; private WebElement password;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "loginbutton_id") @FindBy(id = "loginbutton_id")
private WebElement loginBtn; private WebElement loginBtn;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "okbuttondialog_id") @FindBy(id = "okbuttondialog_id")
private WebElement dialogOKBtn; private WebElement dialogOKBtn;
@FindBy(className = "smpVersion") @FindBy(className = "smpVersion")
private WebElement 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"); log.info("check if Login page is loaded");
if(!isEnabled(username)){ if (!isEnabled(username)) {
log.error("Could not find username input!"); log.error("Could not find username input!");
return false; return false;
} }
if(!isEnabled(password)){ if (!isEnabled(password)) {
log.error("Could not find password input!"); log.error("Could not find password input!");
return false; return false;
} }
if(!isVisible(loginBtn)){ if (!isVisible(loginBtn)) {
log.error("Could not find login button!"); log.error("Could not find login button!");
return false; return false;
} }
if(!isVisible(smpVersion)){ if (!isVisible(smpVersion)) {
log.error("Could not find version text!"); log.error("Could not find version text!");
return false; return false;
} }
...@@ -64,7 +59,7 @@ public class LoginPage extends SMPPage { ...@@ -64,7 +59,7 @@ public class LoginPage extends SMPPage {
return true; 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!!"); log.info("Login started!!");
clearAndFillInput(username, user); clearAndFillInput(username, user);
...@@ -79,8 +74,8 @@ public class LoginPage extends SMPPage { ...@@ -79,8 +74,8 @@ public class LoginPage extends SMPPage {
return PageFactory.initElements(driver, expect); return PageFactory.initElements(driver, expect);
} }
public SearchPage login(String user, String pass){ public SearchPage login(String user, String pass) {
log.info("Login started!!"); log.info("Login started!!");
clearAndFillInput(username, user); clearAndFillInput(username, user);
...@@ -95,7 +90,7 @@ public class LoginPage extends SMPPage { ...@@ -95,7 +90,7 @@ public class LoginPage extends SMPPage {
return new SearchPage(driver); return new SearchPage(driver);
} }
public void invalidLogin(String user, String pass){ public void invalidLogin(String user, String pass) {
log.info("Invalid login started!!"); log.info("Invalid login started!!");
clearAndFillInput(username, user); clearAndFillInput(username, user);
...@@ -105,7 +100,7 @@ public class LoginPage extends SMPPage { ...@@ -105,7 +100,7 @@ public class LoginPage extends SMPPage {
loginBtn.click(); loginBtn.click();
} }
public SearchPage login(String role){ public SearchPage login(String role) {
log.info("Login started!!"); log.info("Login started!!");
HashMap<String, String> user = new TestDataProvider().getUserWithRole(role); HashMap<String, String> user = new TestDataProvider().getUserWithRole(role);
...@@ -124,27 +119,28 @@ public class LoginPage extends SMPPage { ...@@ -124,27 +119,28 @@ public class LoginPage extends SMPPage {
} }
public String getListedSMPVersion(){ public String getListedSMPVersion() {
log.info("getting listed version"); log.info("getting listed version");
return waitForElementToBeVisible(smpVersion).getText().trim(); return waitForElementToBeVisible(smpVersion).getText().trim();
} }
public String getTextInUsernameInput(){ public String getTextInUsernameInput() {
log.info("getting text in username input"); log.info("getting text in username input");
return waitForElementToBeVisible(username).getText().trim(); return waitForElementToBeVisible(username).getText().trim();
} }
public String getTextInPasswordInput(){ public String getTextInPasswordInput() {
log.info("getting text in pass input"); log.info("getting text in pass input");
return waitForElementToBeVisible(password).getText().trim(); return waitForElementToBeVisible(password).getText().trim();
} }
private void closeChangePassModal(){ private void closeChangePassModal() {
log.info("Closing Change password modal"); log.info("Closing Change password modal");
try{ try {
waitForElementToBeClickable(dialogOKBtn).click(); waitForElementToBeClickable(dialogOKBtn).click();
waitForElementToBeGone(dialogOKBtn); waitForElementToBeGone(dialogOKBtn);
}catch (Exception e){} } catch (Exception e) {
}
} }
public void loginWithoutUserAndPassword() { public void loginWithoutUserAndPassword() {
......
...@@ -9,88 +9,82 @@ import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; ...@@ -9,88 +9,82 @@ import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import pages.components.ConfirmationDialog; import pages.components.ConfirmationDialog;
import pages.components.baseComponents.PaginationControls; import pages.components.baseComponents.PaginationControls;
import pages.components.baseComponents.SMPPage; import pages.components.baseComponents.SMPPage;
import pages.users.UserPopup;
import pages.users.UsersGrid;
import utils.PROPERTIES; import utils.PROPERTIES;
public class PropertiesPage extends SMPPage { public class PropertiesPage extends SMPPage {
public PropertiesPage(WebDriver driver) { public PaginationControls pagination = new PaginationControls(driver);
super(driver); @FindBy(id = "searchTable")
this.pageHeader.waitForTitleToBe("Properties"); private WebElement propertyTableContainer;
PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this); @FindBy(id = "cancelButton")
} private WebElement cancelBtn;
public PaginationControls pagination = new PaginationControls(driver); @FindBy(id = "saveButton")
private WebElement saveBtn;
@FindBy(id = "searchTable") @FindBy(id = "editButton")
private WebElement propertyTableContainer; private WebElement editBtn;
@FindBy(id = "searchProperty")
@FindBy(id = "cancelButton") private WebElement searchPropertyField;
private WebElement cancelBtn; @FindBy(id = "searchbutton_id")
private WebElement searchBtn;
@FindBy(id = "saveButton")
private WebElement saveBtn; public PropertiesPage(WebDriver driver) {
super(driver);
@FindBy(id = "editButton") this.pageHeader.waitForTitleToBe("Properties");
private WebElement editBtn; PageFactory.initElements(new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this);
}
@FindBy(id = "searchProperty")
private WebElement searchPropertyField; public String getErrorMessage() {
return driver.findElement(By.cssSelector(".alert-message-error")).getText();
@FindBy(id = "searchbutton_id") }
private WebElement searchBtn;
public String getErrorMessage() public boolean isLoaded() {
{ log.info("checking if Property page is loaded");
return driver.findElement(By.cssSelector(".alert-message-error")).getText(); return isVisible(cancelBtn)
} && isVisible(saveBtn)
&& isVisible(editBtn);
}
public boolean isLoaded(){ public boolean isCancelButtonEnabled() {
log.info("checking if Property page is loaded"); log.info("checking cancel button is enabled");
return isVisible(cancelBtn) return isEnabled(cancelBtn);
&& isVisible(saveBtn) }
&& isVisible(editBtn);
} public boolean isSaveButtonEnabled() {
log.info("checking save button is enabled");
public boolean isCancelButtonEnabled() { return isEnabled(saveBtn);
log.info("checking cancel button is enabled"); }
return isEnabled(cancelBtn);
} public ConfirmationDialog clickCancel() {
log.info("click cancel button");
public boolean isSaveButtonEnabled() { waitForElementToBeClickable(cancelBtn).click();
log.info("checking save button is enabled"); return new ConfirmationDialog(driver);
return isEnabled(saveBtn); }
}
public ConfirmationDialog clickCancel() { public boolean isEditButtonEnabled() {
log.info("click cancel button"); log.info("checking edit button is enabled");
waitForElementToBeClickable(cancelBtn).click(); return isEnabled(editBtn);
return new ConfirmationDialog(driver); }
}
public boolean isEditButtonEnabled() {
log.info("checking edit button is enabled"); public ConfirmationDialog clickSave() {
return isEnabled(editBtn); log.info("click save button");
} waitForElementToBeClickable(saveBtn).click();
return new ConfirmationDialog(driver);
}
public ConfirmationDialog clickSave() { public PropertyPopup clickEdit() {
log.info("click save button"); log.info("click edit button");
waitForElementToBeClickable(saveBtn).click(); waitForElementToBeClickable(editBtn).click();
return new ConfirmationDialog(driver); return new PropertyPopup(driver);
} }
public PropertyPopup clickEdit() {
log.info("click edit button"); public void propertySearch(String propertyname) {
waitForElementToBeClickable(editBtn).click(); log.info("Search for property");
return new PropertyPopup(driver); waitForElementToBeVisible(searchPropertyField).sendKeys(propertyname);
} waitForElementToBeClickable(searchBtn).click();
public void propertySearch(String propertyname) }
{
log.info("Search for property"); public PropertiesGrid grid() {
waitForElementToBeVisible(searchPropertyField).sendKeys(propertyname); return new PropertiesGrid(driver, propertyTableContainer);
waitForElementToBeClickable(searchBtn).click(); }
}
public PropertiesGrid grid() {
return new PropertiesGrid(driver, propertyTableContainer);
}
} }
...@@ -5,21 +5,12 @@ import org.openqa.selenium.WebElement; ...@@ -5,21 +5,12 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import pages.components.GenericSelect; import pages.components.GenericSelect;
import pages.components.baseComponents.PageComponent; import pages.components.baseComponents.PageComponent;
import utils.PROPERTIES; import utils.PROPERTIES;
public class FilterArea extends PageComponent { public class FilterArea extends PageComponent {
public FilterArea(WebDriver driver) { public GenericSelect domainSelect;
super(driver);
PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this);
domainSelect = new GenericSelect(driver, domainSelectContainer);
}
@FindBy(id = "participantIdentifier") @FindBy(id = "participantIdentifier")
private WebElement participantIdentifierInput; private WebElement participantIdentifierInput;
...@@ -28,13 +19,17 @@ public class FilterArea extends PageComponent { ...@@ -28,13 +19,17 @@ public class FilterArea extends PageComponent {
@FindBy(id = "domain_id") @FindBy(id = "domain_id")
private WebElement domainSelectContainer; private WebElement domainSelectContainer;
public GenericSelect domainSelect;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@FindBy(id = "searchbutton_id") @FindBy(id = "searchbutton_id")
private WebElement searchButton; 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() { public String getParticipantIdentifierInputValue() {
log.info("getting text in participant Identifier Input"); log.info("getting text in participant Identifier Input");
...@@ -48,23 +43,23 @@ public class FilterArea extends PageComponent { ...@@ -48,23 +43,23 @@ public class FilterArea extends PageComponent {
return participantSchemeInput.getText().trim(); return participantSchemeInput.getText().trim();
} }
public boolean isLoaded(){ public boolean isLoaded() {
log.info("checking filter area is properly loaded"); log.info("checking filter area is properly loaded");
if(!isVisible(participantIdentifierInput)){ if (!isVisible(participantIdentifierInput)) {
return false; return false;
} }
if(!isVisible(participantSchemeInput)){ if (!isVisible(participantSchemeInput)) {
return false; return false;
} }
return domainSelect.isLoaded(); 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)); log.info(String.format("filtering by %s, %s, %s", identifier, scheme, domain));
clearAndFillInput(participantIdentifierInput, identifier); clearAndFillInput(participantIdentifierInput, identifier);
clearAndFillInput(participantSchemeInput, scheme); clearAndFillInput(participantSchemeInput, scheme);
if(null != domain && !domain.isEmpty()){ if (null != domain && !domain.isEmpty()) {
domainSelect.selectOptionByText(domain); domainSelect.selectOptionByText(domain);
} }
...@@ -73,21 +68,19 @@ public class FilterArea extends PageComponent { ...@@ -73,21 +68,19 @@ public class FilterArea extends PageComponent {
waitForXMillis(1000); waitForXMillis(1000);
} }
public boolean isSearchButtonVisible(){ public boolean isSearchButtonVisible() {
try{ try {
return searchButton.isDisplayed(); return searchButton.isDisplayed();
} } catch (Exception e) {
catch(Exception e){
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} }
public boolean isSearchButtonEnable(){ public boolean isSearchButtonEnable() {
try{ try {
return searchButton.isEnabled(); return searchButton.isEnabled();
} } catch (Exception e) {
catch (Exception e){
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
......
package pages.service_groups.edit; package pages.service_groups.edit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
...@@ -16,16 +15,8 @@ import utils.PROPERTIES; ...@@ -16,16 +15,8 @@ import utils.PROPERTIES;
import java.util.List; import java.util.List;
public class EditPage extends SMPPage { 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 FilterArea filterArea;
public PaginationControls pagination = new PaginationControls(driver);
@FindBy(id = "searchTable") @FindBy(id = "searchTable")
private WebElement searchTable; private WebElement searchTable;
...@@ -47,7 +38,12 @@ public class EditPage extends SMPPage { ...@@ -47,7 +38,12 @@ public class EditPage extends SMPPage {
@FindBy(id = "deleteButton") @FindBy(id = "deleteButton")
private WebElement 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() { public boolean isCancelButtonEnabled() {
log.info("cancel button"); log.info("cancel button");
...@@ -104,6 +100,7 @@ public class EditPage extends SMPPage { ...@@ -104,6 +100,7 @@ public class EditPage extends SMPPage {
waitForElementToBeClickable(cancelButton).click(); waitForElementToBeClickable(cancelButton).click();
return new ConfirmationDialog(driver); return new ConfirmationDialog(driver);
} }
public ConfirmationDialog clickOk() { public ConfirmationDialog clickOk() {
log.info("canceling ..."); log.info("canceling ...");
waitForElementToBeClickable(okButton).click(); waitForElementToBeClickable(okButton).click();
......
...@@ -5,127 +5,119 @@ import org.openqa.selenium.WebElement; ...@@ -5,127 +5,119 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import pages.components.baseComponents.PageComponent; import pages.components.baseComponents.PageComponent;
import utils.PROPERTIES; import utils.PROPERTIES;
import java.util.List; import java.util.List;
public class ServiceGroupPopup extends PageComponent { public class ServiceGroupPopup extends PageComponent {
public ServiceGroupPopup(WebDriver driver) { public AccordionSection ownersPanel;
super(driver); public AccordionSection domainsPanel;
PageFactory.initElements( new AjaxElementLocatorFactory(driver, PROPERTIES.TIMEOUT), this);
try {
ownersPanel = new AccordionSection(driver, ownersPanelContainer);
} catch (Exception e) {
}
domainsPanel = new AccordionSection(driver, domainsPanelContainer);
}
@FindBy(css = "#owner_expansion_panel_id") @FindBy(css = "#owner_expansion_panel_id")
private WebElement ownersPanelContainer; private WebElement ownersPanelContainer;
public AccordionSection ownersPanel;
@FindBy(css = "#domain_expansion_panel_id") @FindBy(css = "#domain_expansion_panel_id")
private WebElement domainsPanelContainer; private WebElement domainsPanelContainer;
public AccordionSection domainsPanel;
@FindBy(css = "mat-dialog-actions button:nth-child(1)") @FindBy(css = "mat-dialog-actions button:nth-child(1)")
private WebElement okButton; private WebElement okButton;
@FindBy(css = "mat-dialog-actions button:nth-child(2)") @FindBy(css = "mat-dialog-actions button:nth-child(2)")
private WebElement cancelButton; private WebElement cancelButton;
@FindBy(css = "#participantIdentifier_id") @FindBy(css = "#participantIdentifier_id")
private WebElement participantIdentifierInput; private WebElement participantIdentifierInput;
@FindBy(css = "#participantScheme_id") @FindBy(css = "#participantScheme_id")
private WebElement participantSchemeInput; private WebElement participantSchemeInput;
@FindBy(css = "#extensionTextArea") @FindBy(css = "#extensionTextArea")
private WebElement extensionTextArea; private WebElement extensionTextArea;
@FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(1)") @FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(1)")
private WebElement clearExtensionButton; private WebElement clearExtensionButton;
@FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(2)") @FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(2)")
private WebElement extensionWizardButton; private WebElement extensionWizardButton;
@FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(3)") @FindBy(css = "mat-card-content > mat-toolbar > mat-toolbar-row > button:nth-child(3)")
private WebElement validateExtensionButton; private WebElement validateExtensionButton;
@FindBy(css = "mat-card-content > div.ng-star-inserted") @FindBy(css = "mat-card-content > div.ng-star-inserted")
private WebElement errorContainer; 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"); log.info("is ok button visible");
return isVisible(okButton); return isVisible(okButton);
} }
public boolean isCancelButtonPresent(){
public boolean isCancelButtonPresent() {
log.info("is cancel button visible"); log.info("is cancel button visible");
return isVisible(cancelButton); return isVisible(cancelButton);
} }
public boolean isOKButtonEnable(){
public boolean isOKButtonEnable() {
log.info("is ok button visible"); log.info("is ok button visible");
return isEnabled(okButton); return isEnabled(okButton);
} }
public boolean isCancelButtonEnable(){
public boolean isCancelButtonEnable() {
log.info("is cancel button visible"); log.info("is cancel button visible");
return isEnabled(cancelButton); return isEnabled(cancelButton);
} }
public boolean isExtensionAreaEditable(){ public boolean isExtensionAreaEditable() {
log.info("is Extension Area Editable"); 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"); 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"); 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"); log.info("check owner panel is enabled");
return ownersPanel.optionsEnabled(); return ownersPanel.optionsEnabled();
} }
public boolean isOwnersPanelPresent(){ public boolean isOwnersPanelPresent() {
log.info("check owner panel is present"); log.info("check owner panel is present");
return null == ownersPanel; return null == ownersPanel;
} }
public boolean isDomainsPanelEnabled(){ public boolean isDomainsPanelEnabled() {
log.info("check domains panel is enabled"); log.info("check domains panel is enabled");
return domainsPanel.optionsEnabled(); return domainsPanel.optionsEnabled();
} }
public void clickOK(){ public void clickOK() {
log.info("click ok.."); log.info("click ok..");
waitForElementToBeClickable(okButton).click(); waitForElementToBeClickable(okButton).click();
waitForElementToBeGone(okButton); waitForElementToBeGone(okButton);
} }
public void clickClear(){ public void clickClear() {
log.info("click clear.."); log.info("click clear..");
waitForElementToBeClickable(clearExtensionButton).click(); waitForElementToBeClickable(clearExtensionButton).click();
waitForXMillis(100); waitForXMillis(100);
} }
public void clickCancel(){ public void clickCancel() {
log.info("click cancel.."); log.info("click cancel..");
waitForElementToBeClickable(cancelButton).click(); waitForElementToBeClickable(cancelButton).click();
waitForElementToBeGone(cancelButton); 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.."); log.info("filling form..");
waitForElementToBeVisible(participantIdentifierInput); waitForElementToBeVisible(participantIdentifierInput);
...@@ -147,19 +139,19 @@ public class ServiceGroupPopup extends PageComponent { ...@@ -147,19 +139,19 @@ public class ServiceGroupPopup extends PageComponent {
} }
public String getParticipantIdentifierValue(){ public String getParticipantIdentifierValue() {
return waitForElementToBeVisible(participantIdentifierInput).getAttribute("value").trim(); return waitForElementToBeVisible(participantIdentifierInput).getAttribute("value").trim();
} }
public String getParticipantSchemeValue(){ public String getParticipantSchemeValue() {
return participantSchemeInput.getAttribute("value").trim(); return participantSchemeInput.getAttribute("value").trim();
} }
public String getErrorMessage(){ public String getErrorMessage() {
return errorContainer.getText().trim(); return errorContainer.getText().trim();
} }
public String getExtensionAreaContent(){ public String getExtensionAreaContent() {
log.info("getting Extension Area Content"); log.info("getting Extension Area Content");
waitForElementToBeVisible(extensionTextArea); waitForElementToBeVisible(extensionTextArea);
...@@ -167,38 +159,44 @@ public class ServiceGroupPopup extends PageComponent { ...@@ -167,38 +159,44 @@ public class ServiceGroupPopup extends PageComponent {
return extensionTextArea.getAttribute("value").trim(); return extensionTextArea.getAttribute("value").trim();
} }
public void enterDataInExtensionTextArea(String text){ public void enterDataInExtensionTextArea(String text) {
waitForElementToBeVisible(extensionTextArea).clear(); waitForElementToBeVisible(extensionTextArea).clear();
extensionTextArea.sendKeys(text); extensionTextArea.sendKeys(text);
waitForXMillis(1000); waitForXMillis(1000);
} }
public void fillParticipantIdentifier(String participantIdentifier){ public void fillParticipantIdentifier(String participantIdentifier) {
clearAndFillInput(participantIdentifierInput, participantIdentifier); clearAndFillInput(participantIdentifierInput, participantIdentifier);
} }
public void fillParticipantScheme(String participantScheme){
public void fillParticipantScheme(String participantScheme) {
clearAndFillInput(participantSchemeInput, participantScheme); clearAndFillInput(participantSchemeInput, participantScheme);
} }
public void chooseFirstOwner(){
if(!ownersPanel.isExpanded()){ ownersPanel.expandSection();} public void chooseFirstOwner() {
if (!ownersPanel.isExpanded()) {
ownersPanel.expandSection();
}
ownersPanel.selectOptionWithIndex(0); ownersPanel.selectOptionWithIndex(0);
} }
public void chooseFirstDomain(){
if(!domainsPanel.isExpanded()){ domainsPanel.expandSection();} public void chooseFirstDomain() {
if (!domainsPanel.isExpanded()) {
domainsPanel.expandSection();
}
domainsPanel.selectOptionWithIndex(0); domainsPanel.selectOptionWithIndex(0);
} }
public void fillExtensionArea(String extension){
public void fillExtensionArea(String extension) {
clearAndFillInput(extensionTextArea, extension); clearAndFillInput(extensionTextArea, extension);
} }
public void generateRndExtension(){ public void generateRndExtension() {
extensionWizardButton.click(); extensionWizardButton.click();
new SGExtensionWizzard(driver).fillWithRndStrings(); new SGExtensionWizzard(driver).fillWithRndStrings();
} }
} }
...@@ -2,6 +2,7 @@ package utils; ...@@ -2,6 +2,7 @@ package utils;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -21,15 +22,24 @@ public class DriverManager { ...@@ -21,15 +22,24 @@ public class DriverManager {
// } // }
public static WebDriver getDriver() { 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(); driver.manage().window().maximize();
return driver; return driver;
} }
} }
...@@ -6,7 +6,8 @@ public class PROPERTIES { ...@@ -6,7 +6,8 @@ public class PROPERTIES {
public static final String UI_BASE_URL = System.getProperty("UI_BASE_URL"); public static final String UI_BASE_URL = System.getProperty("UI_BASE_URL");
public static final int SHORT_UI_TIMEOUT = 5; public static final int SHORT_UI_TIMEOUT = 5;
public static final int TIMEOUT = Integer.valueOf(System.getProperty("SHORT_TIMEOUT")); 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 REPORTS_FOLDER = System.getProperty("reports.folder");
public static final String TESTDATAFILE = System.getProperty("data.folder") + System.getProperty("testdata.file"); public static final String TESTDATAFILE = System.getProperty("data.folder") + System.getProperty("testdata.file");
......
...@@ -20,7 +20,7 @@ public class TestDataProvider { ...@@ -20,7 +20,7 @@ public class TestDataProvider {
content = new String(Files.readAllBytes(Paths.get(PROPERTIES.TESTDATAFILE))); content = new String(Files.readAllBytes(Paths.get(PROPERTIES.TESTDATAFILE)));
testData = new JSONObject(content); testData = new JSONObject(content);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new RuntimeException("Error reading test data file: " + PROPERTIES.TESTDATAFILE);
} }
} }
......
package utils.enums; package utils.enums;
import utils.TestDataProvider;
import java.util.Map;
public class SMPMessages { public class SMPMessages {
public static final String MSG_1 = "Login failed; Invalid userID or password"; 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" + 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" + 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" + "Click on the \"Ok\" button keep your changes and come back to the current\n" +
"window unchanged."; "window unchanged.";
public static final String MSG_4 = "Please confirm by clicking on the \"Save\" button that you want to save all changes.\n" + 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" + "If you don't want to save these changes now, please click on the \"Don't\n" +
"save now\" button"; "save now\" button";
public static final String MSG_5 = "To delete the current item(s) click on the \"Ok\" button.\n" + 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" + "Click on the \"Cancel\" button to keep this item and come back to the\n" +
"current window unchanged"; "current window unchanged";
public static final String MSG_6 = "The system detected a concurrent access.\n" + 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" + "Your changes are irremediably lost, and the data were reverted to what\n" +
"the concurrent user saved before you."; "the concurrent user saved before you.";
public static final String MSG_7 = "Component ${COMPONENT} is not accessible. Administration console is\n" + 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" + 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" + "modifications were not saved yet.\n" +
"Click on \"Abandon\" to abandon your changes.\n" + "Click on \"Abandon\" to abandon your changes.\n" +
"Click \"Keep\" to stay on the current screen and keep your changes without\n" + "Click \"Keep\" to stay on the current screen and keep your changes without\n" +
"saving them now"+ "saving them now" +
"Click \"Save\" to save your changes and move to the selected screen."; "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" + 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" + 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" + 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 \"Delete\" to confirm the deletion.\n" +
"Click on \"Keep\" to keep the ServiceMetadata."; "Click on \"Keep\" to keep the ServiceMetadata.";
public static final String MSG_12 = "You are about to delete ServiceMetadata: ${ServiceMetadata}.\n" + public static final String MSG_12 = "You are about to delete ServiceMetadata: ${ServiceMetadata}.\n" +
"Click on \"Delete\" to confirm the deletion.\n" + "Click on \"Delete\" to confirm the deletion.\n" +
"Click on \"Keep\" to keep the ServiceMetadata"; "Click on \"Keep\" to keep the ServiceMetadata";
public static final String MSG_13 = "You are about to delete User: ${User}.\n" + public static final String MSG_13 = "You are about to delete User: ${User}.\n" +
"Click on \"Delete\" to confirm the deletion.\n" + "Click on \"Delete\" to confirm the deletion.\n" +
"Click on \"Keep\" to keep the user.\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" + 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" + "register new user SMP user to SML for domain ${ BDMSL _DOMAIN}.\n" +
"Domain will be saved to SMP. Action is not recoverable.\n" + "Domain will be saved to SMP. Action is not recoverable.\n" +
"Click on \"Register\" to confirm the registration and saving.\n" + "Click on \"Register\" to confirm the registration and saving.\n" +
"Click on \"Cancel\" to cancel the registration."; "Click on \"Cancel\" to cancel the registration.";
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
public static final String MSG_15 = "You are about to delete an SMP Domain: ${SMP_DOMAIN_ID}. Action\n" + 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" + "will unregister SMP domain user ${SMP_SML_ID}. from SML for domain\n" +
"${ BDMSL _DOMAIN}. Action is not recoverable.\n" + "${ BDMSL _DOMAIN}. Action is not recoverable.\n" +
"Click on \"Delete\" to confirm the deleting and unregistration of domain.\n" + "Click on \"Delete\" to confirm the deleting and unregistration of domain.\n" +
"Click on \"Keep\" to keep the domain."; "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" + 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 \"Delete\" to confirm the deleting the key.\n" +
"Click on \"Keep\" to keep the key."; "Click on \"Keep\" to keep the key.";
public static final String MSG_17 = "You are about to delete Domain: ${SMP_DOMAIN_ID}.\n" + 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 \"Delete\" to confirm the deletion.\n" +
"Click on \"Keep\" to keep the domain."; "Click on \"Keep\" to keep the domain.";
public static final String MSG_18 = "The operation 'update' completed successfully."; 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!"; public static final String USER_OWN_DELETE_ERR = "Delete validation error Could not delete logged user!";
...@@ -78,6 +74,6 @@ public class SMPMessages { ...@@ -78,6 +74,6 @@ public class SMPMessages {
public static final String KEYSTORE_IMPORTED_MSG = "Keystore %s imported!"; public static final String KEYSTORE_IMPORTED_MSG = "Keystore %s imported!";
public static final String KEYSTORE_DELETION_MSG = "Certificate %s deleted!"; 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 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 DOMAINCODE_VALIDATION_MESSAGE = "Domain code must contain only chars and numbers and must be less than 63 chars long.";
} }
package utils.rest; package utils.rest;
import utils.PROPERTIES;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
public class SMPPaths { public class SMPPaths {
...@@ -11,5 +9,6 @@ public class SMPPaths { ...@@ -11,5 +9,6 @@ public class SMPPaths {
public static final String USER_LIST = "internal/rest/user"; public static final String USER_LIST = "internal/rest/user";
public static final String SERVICE_GROUP = "public/rest/service-group"; public static final String SERVICE_GROUP = "public/rest/service-group";
public static final String KEYSTORE = "internal/rest/keystore"; public static final String KEYSTORE = "internal/rest/keystore";
public static final String SYS_INFO = "public/rest/application/info";
} }
This diff is collapsed.
package utils.customReporter; package customReporter;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 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.ITestContext;
import org.testng.ITestListener; import org.testng.ITestListener;
import org.testng.ITestResult; import org.testng.ITestResult;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ui.BaseTest;
import utils.PROPERTIES; import utils.PROPERTIES;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
...@@ -28,9 +33,8 @@ public class ExcelTestReporter implements ITestListener { ...@@ -28,9 +33,8 @@ public class ExcelTestReporter implements ITestListener {
@Override @Override
/*Creates the report file, the sheet and writes the headers of the table with style as well*/ /*Creates the report file, the sheet and writes the headers of the table with style as well*/
public void onStart(ITestContext iTestContext) { public void onStart(ITestContext iTestContext) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
String dateStr = format.format(iTestContext.getStartDate()); String dateStr = format.format(iTestContext.getStartDate());
filename = PROPERTIES.REPORTS_FOLDER + "TestRunReport" + dateStr + ".xlsx"; filename = PROPERTIES.REPORTS_FOLDER + "TestRunReport" + dateStr + ".xlsx";
...@@ -47,12 +51,12 @@ public class ExcelTestReporter implements ITestListener { ...@@ -47,12 +51,12 @@ public class ExcelTestReporter implements ITestListener {
cell.setCellValue(headers[i]); cell.setCellValue(headers[i]);
} }
try{ try {
FileOutputStream os = new FileOutputStream(filename); FileOutputStream os = new FileOutputStream(filename);
workbook.write(os); workbook.write(os);
workbook.close(); workbook.close();
os.close(); os.close();
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -81,6 +85,7 @@ public class ExcelTestReporter implements ITestListener { ...@@ -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*/ /* Writes a row in the report file with the test id, name and FAIL as status*/
@Override @Override
public void onTestFailure(ITestResult iTestResult) { public void onTestFailure(ITestResult iTestResult) {
takeScreenshot(iTestResult);
try { try {
writeRowToReportFile(iTestResult, "FAIL"); writeRowToReportFile(iTestResult, "FAIL");
} catch (Exception e) { } catch (Exception e) {
...@@ -105,27 +110,26 @@ public class ExcelTestReporter implements ITestListener { ...@@ -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" */ /* 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(); XSSFCellStyle style = workbook.createCellStyle();
XSSFFont font = workbook.createFont(); XSSFFont font = workbook.createFont();
font.setBold(true); font.setBold(true);
if(type.equalsIgnoreCase("Pass")){ if (type.equalsIgnoreCase("Pass")) {
style.setFillBackgroundColor(IndexedColors.BRIGHT_GREEN.getIndex()); style.setFillBackgroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
style.setFillForegroundColor(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.setFillBackgroundColor(IndexedColors.RED.getIndex());
style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillForegroundColor(IndexedColors.RED.getIndex());
style.setFont(font); style.setFont(font);
}else if (type.equalsIgnoreCase("Skipped")){ } else if (type.equalsIgnoreCase("Skipped")) {
style.setFillBackgroundColor(IndexedColors.WHITE.getIndex()); style.setFillBackgroundColor(IndexedColors.WHITE.getIndex());
style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillForegroundColor(IndexedColors.WHITE.getIndex());
style.setFont(font); style.setFont(font);
} } else if (type.equalsIgnoreCase("Header")) {
else if (type.equalsIgnoreCase("Header")){
style.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFont(font); style.setFont(font);
...@@ -140,15 +144,19 @@ public class ExcelTestReporter implements ITestListener { ...@@ -140,15 +144,19 @@ public class ExcelTestReporter implements ITestListener {
String qualifiedName = iTestResult.getMethod().getQualifiedName(); String qualifiedName = iTestResult.getMethod().getQualifiedName();
String testType = ""; String testType = "";
if(qualifiedName.contains(".ui.")){testType = "UI";} if (qualifiedName.contains(".ui.")) {
if(qualifiedName.contains(".rest.")){testType = "REST";} testType = "UI";
}
if (qualifiedName.contains(".rest.")) {
testType = "REST";
}
File myFile = new File(filename); File myFile = new File(filename);
FileInputStream inputStream = new FileInputStream(myFile); FileInputStream inputStream = new FileInputStream(myFile);
XSSFWorkbook workbook = new XSSFWorkbook(inputStream); XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
Sheet reportSheet = workbook.getSheetAt(0); Sheet reportSheet = workbook.getSheetAt(0);
int rowNum = reportSheet.getLastRowNum()+1; int rowNum = reportSheet.getLastRowNum() + 1;
Row currentRow = reportSheet.createRow(rowNum); Row currentRow = reportSheet.createRow(rowNum);
currentRow.createCell(0).setCellValue(testType); currentRow.createCell(0).setCellValue(testType);
...@@ -162,11 +170,11 @@ public class ExcelTestReporter implements ITestListener { ...@@ -162,11 +170,11 @@ public class ExcelTestReporter implements ITestListener {
cell.setCellValue(result); cell.setCellValue(result);
cell.setCellStyle(composeCellStyle(workbook, result)); cell.setCellStyle(composeCellStyle(workbook, result));
currentRow.createCell(7).setCellValue(sdf.format(new Date(iTestResult.getStartMillis()))); 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(9).setCellValue("");
currentRow.createCell(10).setCellValue(""); currentRow.createCell(10).setCellValue("");
if(iTestResult.getThrowable() != null){ if (iTestResult.getThrowable() != null) {
currentRow.createCell(11).setCellValue(iTestResult.getThrowable().getMessage()); currentRow.createCell(11).setCellValue(iTestResult.getThrowable().getMessage());
} }
...@@ -180,9 +188,21 @@ public class ExcelTestReporter implements ITestListener { ...@@ -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();
}
}
} }
package utils.customReporter; package customReporter;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.testng.ITestContext; import org.testng.ITestContext;
import org.testng.ITestListener; import org.testng.ITestListener;
import org.testng.ITestResult; import org.testng.ITestResult;
public class TestProgressReporter implements ITestListener { public class TestProgressReporter implements ITestListener {
static int test_count = 0; static int test_count = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment