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

Skip to content
Snippets Groups Projects
Commit 50d3c875 authored by Mihai BOZ's avatar Mihai BOZ
Browse files

Pull request #201: EDELIVERY-14388 Automate UI tests for the DomiSMP project Part2

Merge in EDELIVERY/smp from EDELIVERY-14388-Automate-UI-tests-for-the-DomiSMP-project---Part2 to development

* commit '909d4b09':
  added text for EditGroups, added tests for SearchResources page
  added text for EditGroups, added tests for SearchResources page
  added text for EditGroups, added variable for wait
parents 1cf44a23 909d4b09
No related branches found
No related tags found
No related merge requests found
Pipeline #244424 failed
Showing
with 134 additions and 48 deletions
......@@ -24,6 +24,7 @@ public class CommonPageWithTabs extends DomiSMPPage {
if (element.getText().contains(tabName)) {
element.click();
wait.forAttributeToContain(element, "aria-selected", "true");
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
LOG.debug("Domain tab {} is opened", tabName);
break;
}
......
......@@ -29,7 +29,7 @@ public class AlertComponent extends DComponent {
public String getAlertMessage() {
try {
wait.forElementToBeVisible(alertToaster, true);
wait.forElementToBeVisible(alertToaster, false);
String alertMesageText = alertToaster.getText();
alertMesageText = alertMesageText.replace("×", "").replaceAll("\n", "");
LOG.debug("Displayed message : {}.", alertToaster.getText());
......@@ -37,7 +37,7 @@ public class AlertComponent extends DComponent {
return alertMesageText;
} catch (Exception e) {
LOG.error("No messages displayed.");
return "No alert message found";
return "";
}
}
......
package ddsl.dcomponents.Grid;
import ddsl.dcomponents.DComponent;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
......@@ -30,7 +29,7 @@ public class BasicGrid extends DComponent {
super(driver);
LOG.info("Loading basic grid");
wait.forXMillis(500);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
PageFactory.initElements(new DefaultElementLocatorFactory(container), this);
for (WebElement gridHeader : gridHeaders) {
......@@ -38,17 +37,6 @@ public class BasicGrid extends DComponent {
}
}
public void selectRow(int rowNumber) {
LOG.info("selecting row with number ... " + rowNumber);
wait.forXMillis(500);
if (rowNumber >= gridRows.size()) {
return;
}
gridRows.get(rowNumber).click();
wait.forXMillis(500);
}
public void doubleClickRow(String fieldName) {
gridRows.forEach(row -> {
if (row.getText().startsWith(fieldName)) {
......@@ -58,7 +46,7 @@ public class BasicGrid extends DComponent {
}
);
wait.forXMillis(500);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
}
public String getValue(String fieldName) {
......@@ -72,11 +60,4 @@ public class BasicGrid extends DComponent {
return fieldValue;
}
public void scrollRow(int index) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", gridRows.get(index));
wait.forXMillis(500);
}
}
......@@ -5,6 +5,7 @@ import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -19,7 +20,7 @@ public class GridPagination extends DComponent {
public GridPagination(WebDriver driver, WebElement parentElement) {
super(driver);
PageFactory.initElements(driver, this);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getWaitTimeShort()), this);
this.parentElement = parentElement;
}
......
......@@ -24,7 +24,7 @@ public class GridWithoutPagination extends DComponent {
super(driver);
PageFactory.initElements(driver, this);
this.parentElement = parentElement;
wait.forXMillis(200);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
}
public List<WebElement> getGridHeaders() {
......@@ -41,7 +41,7 @@ public class GridWithoutPagination extends DComponent {
public void searchAndDoubleClickElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
for (int i = 0; i < rowHeaders.size(); i++) {
......@@ -77,7 +77,7 @@ public class GridWithoutPagination extends DComponent {
public WebElement searchAndGetPrecedentSiblingElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
for (int i = 0; i < rowHeaders.size(); i++) {
......@@ -103,7 +103,7 @@ public class GridWithoutPagination extends DComponent {
public WebElement searchAndGetFollowingSiblingElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
for (int i = 0; i < rowHeaders.size(); i++) {
......
......@@ -47,7 +47,7 @@ public class MatSmallGrid extends DComponent {
public WebElement searchAndGetElementInColumn(String columnName, String value) {
wait.forXMillis(200);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......@@ -110,7 +110,7 @@ public class MatSmallGrid extends DComponent {
}
public String getColumnValueForSpecificRow(String columnNameToSearch, String valueToSearch, String searchedColumnValue) {
wait.forXMillis(data.getWaitTimeShort());
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......@@ -150,7 +150,7 @@ public class MatSmallGrid extends DComponent {
public void searchAndClickElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......
......@@ -41,7 +41,7 @@ public class SmallGrid extends MatSmallGrid {
public WebElement searchAndGetElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......@@ -73,7 +73,7 @@ public class SmallGrid extends MatSmallGrid {
public Boolean isValuePresentInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......@@ -104,7 +104,7 @@ public class SmallGrid extends MatSmallGrid {
}
public String getColumnValueForSpecificRow(String columnNameToSearch, String valueToSearch, String searchedColumnValue) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......@@ -143,7 +143,7 @@ public class SmallGrid extends MatSmallGrid {
}
public void searchAndClickElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Integer numOfPages = getGridPagination().getTotalPageNumber();
List<WebElement> rowHeaders = getGridHeaders();
int columnIndex = -1;
......
......@@ -5,6 +5,8 @@ import ddsl.dcomponents.SetChangePasswordDialog;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
......@@ -28,9 +30,19 @@ public class UserDataCommonComponent extends DomiSMPPage {
private WebElement lastSetLbl;
@FindBy(id = "passwordExpireOn_id")
private WebElement passwordExpiresOnLbl;
@FindBy(id = "sequentialLoginFailureCount_id")
private WebElement seqFailedAttempts;
@FindBy(id = "LastFailedAttempt_id")
private WebElement lastFailedAttempt;
@FindBy(id = "suspendedUtil_id")
private WebElement suspendedUntil;
public UserDataCommonComponent(WebDriver driver) {
super(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getWaitTimeShort()), this);
}
public String getSelectedTheme() {
......@@ -57,6 +69,18 @@ public class UserDataCommonComponent extends DomiSMPPage {
return passwordExpiresOnLbl.getAttribute("value");
}
public String getSequenceFailedAttempts() {
return seqFailedAttempts.getAttribute("value");
}
public String getlastFailedAttempt() {
return lastFailedAttempt.getAttribute("value");
}
public String getsuspendedUntil() {
return suspendedUntil.getAttribute("value");
}
public SetChangePasswordDialog clickOnChangePassword(){
setChangePasswordBtn.click();
return new SetChangePasswordDialog(driver);
......@@ -70,7 +94,7 @@ public class UserDataCommonComponent extends DomiSMPPage {
weToDInput(fullNameInput).fill(fullNameValue);
}
weToDSelect(themeSel).selectByVisibleText(selectThemeValue);
wait.forXMillis(50);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
weToDSelect(localeSel).selectByVisibleText(localeValue);
......
package ddsl.dobjects;
import org.openqa.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
......@@ -80,7 +83,7 @@ public class DWait {
}
} catch (NoSuchElementException e) {
} catch (Exception e) {
LOG.error("element {} not found", element);
}
}
......
......@@ -50,6 +50,7 @@ public class CreateResourceDetailsDialog extends DComponent {
wait.forElementToBeClickable(saveBtn);
if (weToDButton(saveBtn).isEnabled()) {
weToDButton(saveBtn).click();
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
return true;
} else {
return false;
......
......@@ -19,4 +19,8 @@ public class ResourceTab extends SubcategoryTabComponent {
create();
return new CreateResourceDetailsDialog(driver);
}
public void deleteResource(String resourceIdentifier) throws ElementNotInteractableException {
delete("Identifier", resourceIdentifier);
}
}
......@@ -107,7 +107,7 @@ public class CommonEditDocumentPage extends DomiSMPPage {
}
public String getStatusValue() {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
return weToDInput(statusLbl).getText();
}
......
......@@ -44,7 +44,7 @@ public class ResourcePageGrid extends DComponent {
public void searchAndClickElementInColumn(String columnName, String value) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
int numOfPages;
try {
numOfPages = getGridPagination().getTotalPageNumber();
......@@ -93,7 +93,7 @@ public class ResourcePageGrid extends DComponent {
public void openSubresource(String resourceColumn, String resourceValue, String columnNameSubresouce, String valueSubresource) {
wait.forXMillis(100);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
int numOfPages;
try {
numOfPages = getGridPagination().getTotalPageNumber();
......
......@@ -42,11 +42,12 @@ public class ResourcesPage extends DomiSMPPage {
LOG.debug("Click on Open URL for " + resourceIdentifier);
weToDButton(searchBtn).click();
getGrid().searchAndClickElementInColumn("Resource URL", "Open URL");
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
Set<String> handles = driver.getWindowHandles();
Iterator<String> iterator = handles.iterator();
// Switch to the new tab
String original = iterator.next();
iterator.next();
String newTab = iterator.next();
driver.switchTo().window(newTab);
LOG.debug("Switching to new tab" + newTab);
......@@ -73,10 +74,10 @@ public class ResourcesPage extends DomiSMPPage {
Iterator<String> iterator = handles.iterator();
// Switch to the new tab
String original = iterator.next();
iterator.next();
String newTab = iterator.next();
driver.switchTo().window(newTab);
wait.forXMillis(data.getWaitTimeShort());
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
LOG.debug("Switching to new tab" + newTab);
try {
......
......@@ -87,6 +87,7 @@ public class SMLIntegrationTab extends DComponent {
weToDButton(registerBtn).click();
ConfirmationDialog confirmationDialog = new ConfirmationDialog(driver);
confirmationDialog.confirm();
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
}
} catch (Exception e) {
......
......@@ -39,9 +39,9 @@ public class PropertiesPage extends DomiSMPPage {
public void propertySearch(String propertyname) {
LOG.info("Search for property");
wait.forElementToBeVisible(searchPropertyField).sendKeys(propertyname);
wait.forXMillis(500);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
wait.forElementToBeClickable(searchBtn).click();
wait.forXMillis(500);
wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
}
public PropertyPopup openEditPropertyPopupup(String propertyName) {
......
......@@ -15,6 +15,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.NewCookie;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BaseRestClient {
protected final Logger log = LoggerFactory.getLogger(this.getClass());
......@@ -77,6 +78,19 @@ public class BaseRestClient {
return builder.type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
}
protected ClientResponse requestGET(WebResource resource, HashMap<String, String> params) throws Exception {
if (params != null) {
for (Map.Entry<String, String> param : params.entrySet()) {
resource = resource.queryParam(param.getKey(), param.getValue());
}
}
WebResource.Builder builder = decorateBuilder(resource);
ClientResponse response = builder.get(ClientResponse.class);
return response;
}
// -------------------------------------------- Login --------------------------------------------------------------
......
......@@ -22,6 +22,10 @@ public class DomiSMPRestClient extends BaseRestClient {
return new KeystoreClient();
}
public PropertiesClient propertiesClient() {
return new PropertiesClient();
}
}
......
package rest;
import com.sun.jersey.api.client.ClientResponse;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
/**
* Rest client for group actions
*/
public class PropertiesClient extends BaseRestClient {
private final static Logger LOG = LoggerFactory.getLogger(PropertiesClient.class);
public JSONObject getProperty(String propertyName) throws Exception {
startSession();
HashMap<String, String> params = new HashMap<>();
params.put("property", propertyName);
ClientResponse clientResponse = requestGET(resource.path(RestServicePaths.getPropertyPath()), params);
if (clientResponse.getStatus() != 200) {
throw new Exception("Could not get properties ");
}
log.debug("Getting property value for " + propertyName);
return new JSONObject(clientResponse.getEntity(String.class)).getJSONArray("serviceEntities").getJSONObject(0);
}
public void setPropertyValue(JSONObject propertyObject) throws Exception {
startSession();
JSONArray list = new JSONArray();
list.put(propertyObject);
ClientResponse clientResponse = jsonPUT(resource.path(RestServicePaths.getPropertyPath()), list.toString());
if (clientResponse.getStatus() != 200) {
throw new Exception("Could not get properties ");
}
}
}
......@@ -20,7 +20,11 @@ public class ResourceClient extends BaseRestClient {
public ResourceModel createResourceForGroup(DomainModel domainModel, GroupModel groupModel, ResourceModel resourceModelToBeCreated) {
JSONObject resourceJson = new JSONObject(resourceModelToBeCreated);
String createResourcePath = RestServicePaths.getCreateResourcePath(TestRunData.getInstance().getUserId(), domainModel.getDomainId(), groupModel.getGroupId());
String userId = TestRunData.getInstance().getUserId();
if (userId.isEmpty()) {
startSession();
}
String createResourcePath = RestServicePaths.getCreateResourcePath(userId, domainModel.getDomainId(), groupModel.getGroupId());
ClientResponse response = jsonPUT(resource.path(createResourcePath), resourceJson);
if (response.getStatus() != 200) {
try {
......@@ -36,8 +40,12 @@ public class ResourceClient extends BaseRestClient {
public MemberModel addMembersToResource(DomainModel domainModel, GroupModel groupModel, ResourceModel resourceModel, MemberModel groupMember) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
String membersJson = mapper.writeValueAsString(groupMember);
String userId = TestRunData.getInstance().getUserId();
String addGroupMemberPath = RestServicePaths.getResourceAddMemberPath(TestRunData.getInstance().getUserId(), domainModel.getDomainId(), groupModel.getGroupId(), resourceModel.getResourceId());
if (userId.isEmpty()) {
startSession();
}
String addGroupMemberPath = RestServicePaths.getResourceAddMemberPath(userId, domainModel.getDomainId(), groupModel.getGroupId(), resourceModel.getResourceId());
ClientResponse response = jsonPUT(resource.path(addGroupMemberPath), membersJson);
if (response.getStatus() != 200) {
......
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