From 6f4ab8870e3ed4d385280aac25b8cc59b04f3499 Mon Sep 17 00:00:00 2001 From: vmuzikar Date: Thu, 23 Nov 2017 13:51:38 +0100 Subject: [PATCH] KEYCLOAK-5816, KEYCLOAK-5815 UI tests fixes --- .../console/page/fragment/DataTable.java | 14 +-- .../org/keycloak/testsuite/page/Form.java | 4 +- .../authorization/permission/Permissions.java | 7 +- .../authorization/policy/GroupPolicyForm.java | 28 ++--- .../authorization/policy/Policies.java | 7 +- .../authorization/policy/RulePolicyForm.java | 10 +- .../authorization/resource/Resources.java | 7 +- .../clients/authorization/scope/Scopes.java | 7 +- .../page/clients/roles/ClientRole.java | 4 +- .../console/page/roles/CreateRole.java | 4 +- .../testsuite/console/page/roles/Role.java | 36 +++++- .../console/page/roles/RoleDetails.java | 33 +++++ .../{RoleForm.java => RoleDetailsForm.java} | 2 +- .../console/page/roles/UsersInRole.java | 84 +++++++++++++ .../testsuite/console/page/users/Users.java | 10 +- .../console/roles/RealmRolesTest.java | 23 ++-- .../console/roles/UsersInRoleTest.java | 118 +++++++----------- 17 files changed, 265 insertions(+), 133 deletions(-) create mode 100644 testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetails.java rename testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/{RoleForm.java => RoleDetailsForm.java} (98%) create mode 100644 testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/UsersInRole.java diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/DataTable.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/DataTable.java index 9906b133a4..d5cf11241f 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/DataTable.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/console/page/fragment/DataTable.java @@ -25,6 +25,7 @@ import org.openqa.selenium.support.FindBy; import java.util.List; +import static org.keycloak.testsuite.util.UIUtils.clickLink; import static org.keycloak.testsuite.util.WaitUtils.pause; import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad; import static org.openqa.selenium.By.xpath; @@ -55,17 +56,15 @@ public class DataTable { public void search(String pattern) { searchInput.sendKeys(pattern); - searchButton.click(); + clickLink(searchButton); } public void clickHeaderButton(String buttonText) { - header.findElement(By.xpath(".//button[text()='" + buttonText + "']")).click(); - waitForPageToLoad(); + clickLink(header.findElement(By.xpath(".//button[text()='" + buttonText + "']"))); } public void clickHeaderLink(String linkText) { - header.findElement(By.linkText(linkText)).click(); - waitForPageToLoad(); + clickLink(header.findElement(By.linkText(linkText))); } public WebElement body() { @@ -73,6 +72,7 @@ public class DataTable { } public List rows() { + waitForPageToLoad(); pause(500); // wait a bit to ensure the table is no more changing return rows; } @@ -83,11 +83,11 @@ public class DataTable { } public void clickRowByLinkText(String text) { - body.findElement(By.xpath(".//tr/td/a[text()='" + text + "']")).click(); + clickLink(body.findElement(By.xpath(".//tr/td/a[text()='" + text + "']"))); } public void clickRowActionButton(WebElement row, String buttonText) { - row.findElement(xpath(".//td[contains(@class, 'kc-action-cell') and text()='" + buttonText + "']")).click(); + clickLink(row.findElement(xpath(".//td[contains(@class, 'kc-action-cell') and text()='" + buttonText + "']"))); } } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/Form.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/Form.java index 6eab0c7d19..d4b9e1d0c9 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/Form.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/Form.java @@ -25,6 +25,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import static org.jboss.arquillian.graphene.Graphene.guardAjax; +import static org.keycloak.testsuite.util.UIUtils.clickLink; /** * @@ -46,8 +47,7 @@ public class Form { public void save() { // guardAjax(save).click(); - save.click(); - WaitUtils.waitForPageToLoad(); + clickLink(save); } public void cancel() { diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/Permissions.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/Permissions.java index f861c85292..fcb5b8c879 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/Permissions.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/permission/Permissions.java @@ -22,9 +22,9 @@ import org.keycloak.representations.idm.authorization.PolicyRepresentation; import org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation; import org.keycloak.representations.idm.authorization.ScopePermissionRepresentation; import org.keycloak.testsuite.console.page.clients.authorization.policy.PolicyTypeUI; +import org.keycloak.testsuite.console.page.fragment.ModalDialog; import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.util.WaitUtils; -import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; @@ -49,6 +49,9 @@ public class Permissions extends Form { @Page private ScopePermission scopePermission; + @Page + private ModalDialog modalDialog; + public PermissionsTable permissions() { return table; } @@ -130,7 +133,7 @@ public class Permissions extends Form { PolicyRepresentation actual = permissions().toRepresentation(row); if (actual.getName().equalsIgnoreCase(name)) { row.findElements(tagName("td")).get(4).click(); - driver.findElement(By.xpath(".//button[text()='Delete']")).click(); + modalDialog.confirmDeletion(); return; } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/GroupPolicyForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/GroupPolicyForm.java index d063f6cd8e..e3591e3318 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/GroupPolicyForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/GroupPolicyForm.java @@ -16,21 +16,11 @@ */ package org.keycloak.testsuite.console.page.clients.authorization.policy; -import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; -import static org.openqa.selenium.By.tagName; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collectors; - import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.page.Page; import org.keycloak.representations.idm.authorization.GroupPolicyRepresentation; import org.keycloak.representations.idm.authorization.Logic; +import org.keycloak.testsuite.console.page.fragment.ModalDialog; import org.keycloak.testsuite.page.Form; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -38,6 +28,12 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; +import java.util.HashSet; +import java.util.List; + +import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement; +import static org.openqa.selenium.By.tagName; + /** * @author Pedro Igor */ @@ -58,12 +54,12 @@ public class GroupPolicyForm extends Form { @FindBy(xpath = "//i[contains(@class,'pficon-delete')]") private WebElement deleteButton; - @FindBy(xpath = ACTIVE_DIV_XPATH + "/button[text()='Delete']") - private WebElement confirmDelete; - @FindBy(id = "selectGroup") private WebElement selectGroupButton; + @Page + private ModalDialog modalDialog; + @Drone private WebDriver driver; @@ -131,7 +127,7 @@ public class GroupPolicyForm extends Form { public void delete() { deleteButton.click(); - confirmDelete.click(); + modalDialog.confirmDeletion(); } public GroupPolicyRepresentation toRepresentation() { diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/Policies.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/Policies.java index 79c69578fd..12e2fd4c1d 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/Policies.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/Policies.java @@ -27,8 +27,8 @@ import org.keycloak.representations.idm.authorization.RolePolicyRepresentation; import org.keycloak.representations.idm.authorization.RulePolicyRepresentation; import org.keycloak.representations.idm.authorization.TimePolicyRepresentation; import org.keycloak.representations.idm.authorization.UserPolicyRepresentation; +import org.keycloak.testsuite.console.page.fragment.ModalDialog; import org.keycloak.testsuite.page.Form; -import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; @@ -72,6 +72,9 @@ public class Policies extends Form { @Page private GroupPolicy groupPolicy; + @Page + private ModalDialog modalDialog; + public PoliciesTable policies() { return table; } @@ -204,7 +207,7 @@ public class Policies extends Form { PolicyRepresentation actual = policies().toRepresentation(row); if (actual.getName().equalsIgnoreCase(name)) { row.findElements(tagName("td")).get(4).click(); - driver.findElement(By.xpath(".//button[text()='Delete']")).click(); + modalDialog.confirmDeletion(); return; } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/RulePolicyForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/RulePolicyForm.java index 3b02288a43..a990bc42a3 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/RulePolicyForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/policy/RulePolicyForm.java @@ -25,6 +25,12 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; +import java.util.concurrent.TimeUnit; + +import static org.jboss.arquillian.graphene.Graphene.waitGui; +import static org.keycloak.testsuite.util.UIUtils.clickLink; +import static org.openqa.selenium.By.id; + /** * @author Pedro Igor */ @@ -76,8 +82,8 @@ public class RulePolicyForm extends Form { setInputValue(artifactId, expected.getArtifactId()); setInputValue(artifactVersion, expected.getArtifactVersion()); - resolveModuleButton.click(); - WaitUtils.waitForPageToLoad(); + clickLink(resolveModuleButton); + waitGui().withTimeout(30, TimeUnit.SECONDS).until().element(id("moduleName")).is().enabled(); moduleName.selectByVisibleText(expected.getModuleName()); WaitUtils.pause(1000); diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/resource/Resources.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/resource/Resources.java index d079ce69d8..72de12c9fa 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/resource/Resources.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/resource/Resources.java @@ -18,9 +18,9 @@ package org.keycloak.testsuite.console.page.clients.authorization.resource; import org.jboss.arquillian.graphene.page.Page; import org.keycloak.representations.idm.authorization.ResourceRepresentation; +import org.keycloak.testsuite.console.page.fragment.ModalDialog; import org.keycloak.testsuite.page.Form; import org.keycloak.testsuite.util.WaitUtils; -import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -41,6 +41,9 @@ public class Resources extends Form { @Page private Resource resource; + @Page + private ModalDialog modalDialog; + public ResourcesTable resources() { return table; } @@ -79,7 +82,7 @@ public class Resources extends Form { ResourceRepresentation actual = resources().toRepresentation(row); if (actual.getName().equalsIgnoreCase(name)) { row.findElements(tagName("td")).get(6).click(); - driver.findElement(By.xpath(".//button[text()='Delete']")).click(); + modalDialog.confirmDeletion(); return; } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/scope/Scopes.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/scope/Scopes.java index 7324996aa6..7df2fb5252 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/scope/Scopes.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/authorization/scope/Scopes.java @@ -18,8 +18,8 @@ package org.keycloak.testsuite.console.page.clients.authorization.scope; import org.jboss.arquillian.graphene.page.Page; import org.keycloak.representations.idm.authorization.ScopeRepresentation; +import org.keycloak.testsuite.console.page.fragment.ModalDialog; import org.keycloak.testsuite.page.Form; -import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -40,6 +40,9 @@ public class Scopes extends Form { @Page private Scope scope; + @Page + private ModalDialog modalDialog; + public ScopesTable scopes() { return table; } @@ -74,7 +77,7 @@ public class Scopes extends Form { ScopeRepresentation actual = scopes().toRepresentation(row); if (actual.getName().equalsIgnoreCase(name)) { row.findElements(tagName("td")).get(3).click(); - driver.findElement(By.xpath(".//button[text()='Delete']")).click(); + modalDialog.confirmDeletion(); } } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/roles/ClientRole.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/roles/ClientRole.java index 262199723a..cfdcde9f87 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/roles/ClientRole.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/roles/ClientRole.java @@ -28,9 +28,9 @@ public class ClientRole extends ClientRoles { return getUriParameter(ROLE_ID).toString(); } - private RoleForm form; + private RoleDetailsForm form; - public RoleForm form() { + public RoleDetailsForm form() { return form; } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/CreateRole.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/CreateRole.java index d1f218b8d2..ac7b358d24 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/CreateRole.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/CreateRole.java @@ -14,9 +14,9 @@ public class CreateRole extends AdminConsoleCreate { } @Page - private RoleForm form; + private RoleDetailsForm form; - public RoleForm form() { + public RoleDetailsForm form() { return form; } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/Role.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/Role.java index 2bde155e9d..7602dc2988 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/Role.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/Role.java @@ -1,6 +1,9 @@ package org.keycloak.testsuite.console.page.roles; -import org.jboss.arquillian.graphene.page.Page; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +import static org.keycloak.testsuite.util.UIUtils.clickLink; /** * @@ -23,11 +26,34 @@ public class Role extends RealmRoles { return getUriParameter(ROLE_ID).toString(); } - @Page - private RoleForm form; + @FindBy(css = "ul.nav-tabs") + private RoleTabs tabs; - public RoleForm form() { - return form; + public RoleTabs roleTabs() { + return tabs; + } + + public class RoleTabs { + @FindBy(linkText = "Details") + private WebElement detailsTab; + + @FindBy(linkText = "Permissions") + private WebElement permissionsTab; + + @FindBy(linkText = "Users in Role") + private WebElement usersInRoleTab; + + public void details() { + clickLink(detailsTab); + } + + public void permissions() { + clickLink(permissionsTab); + } + + public void usersInRole() { + clickLink(usersInRoleTab); + } } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetails.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetails.java new file mode 100644 index 0000000000..ef801304ec --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetails.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.testsuite.console.page.roles; + +import org.jboss.arquillian.graphene.page.Page; + +/** + * @author Vaclav Muzikar + */ +public class RoleDetails extends Role { + + @Page + private RoleDetailsForm form; + + public RoleDetailsForm form() { + return form; + } +} diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetailsForm.java similarity index 98% rename from testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleForm.java rename to testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetailsForm.java index b4f974a485..29328afaec 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/RoleDetailsForm.java @@ -10,7 +10,7 @@ import org.openqa.selenium.support.FindBy; * * @author tkyjovsk */ -public class RoleForm extends Form { +public class RoleDetailsForm extends Form { @FindBy(id = "name") private WebElement nameInput; diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/UsersInRole.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/UsersInRole.java new file mode 100644 index 0000000000..dd1e3ba3f5 --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/roles/UsersInRole.java @@ -0,0 +1,84 @@ +/* + * Copyright 2017 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.testsuite.console.page.roles; + +import org.keycloak.representations.idm.UserRepresentation; +import org.keycloak.testsuite.console.page.fragment.DataTable; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.openqa.selenium.By.tagName; +import static org.openqa.selenium.By.xpath; + +/** + * @author Vaclav Muzikar + */ +public class UsersInRole extends Role { + @FindBy(css = "table[class*='table']") + private UsersInRoleTable usersInRoleTable; + + public UsersInRoleTable usersTable() { + return usersInRoleTable; + } + + public class UsersInRoleTable extends DataTable { + + public void clickUser(String userName) { + clickRowByLinkText(userName); + } + + public void editUser(String userName) { + clickRowActionButton(getRowByLinkText(userName), "Edit"); + } + + public UserRepresentation getUserFromTableRow(WebElement row) { + UserRepresentation user = null; + List tds = row.findElements(tagName("td")); + if (tds.size() == 5 && !tds.get(0).getText().isEmpty()) { + user = new UserRepresentation(); + user.setUsername(tds.get(0).getText()); + user.setLastName(tds.get(1).getText()); + user.setFirstName(tds.get(2).getText()); + user.setEmail(tds.get(3).getText()); + } + return user; + } + + public List getUsersFromTableRows() { + return rows().stream() + .map(this::getUserFromTableRow) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + public boolean noRoleMembersIsDisplayed() { + try { + return body().findElement(xpath(".//td[text()='No role members' and not(contains(@class, 'ng-hide'))]")).isDisplayed(); + } + catch (NoSuchElementException e) { + return false; + } + } + + } +} diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java index ca1fa9eb18..fea10a90fa 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/users/Users.java @@ -21,7 +21,6 @@ import org.jboss.arquillian.drone.api.annotation.Drone; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.console.page.AdminConsoleRealm; import org.keycloak.testsuite.console.page.fragment.DataTable; -import org.keycloak.testsuite.util.URLUtils; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -30,8 +29,8 @@ import org.openqa.selenium.support.FindBy; import java.util.ArrayList; import java.util.List; -import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad; -import static org.openqa.selenium.By.*; +import static org.keycloak.testsuite.util.UIUtils.clickLink; +import static org.openqa.selenium.By.tagName; /** * @@ -79,18 +78,15 @@ public class Users extends AdminConsoleRealm { } public void clickUser(String username) { - URLUtils.navigateToUri(getRowByUsername(username).findElement(By.xpath("./td[position()=1]/a")).getAttribute("href"), true); - waitForPageToLoad(); + clickLink(getRowByUsername(username).findElement(By.xpath("./td[position()=1]/a"))); } public void editUser(String username) { clickRowActionButton(getRowByUsername(username), EDIT); - waitForPageToLoad(); } public void impersonateUser(String username) { clickRowActionButton(getRowByUsername(username), IMPERSONATE); - waitForPageToLoad(); } public void deleteUser(String username) { diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/RealmRolesTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/RealmRolesTest.java index 953892e9c0..19d7d2e76a 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/RealmRolesTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/RealmRolesTest.java @@ -7,10 +7,13 @@ import org.junit.Test; import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.testsuite.console.page.roles.CreateRole; import org.keycloak.testsuite.console.page.roles.RealmRoles; -import org.keycloak.testsuite.console.page.roles.Role; +import org.keycloak.testsuite.console.page.roles.RoleDetails; import org.keycloak.testsuite.util.Timer; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; import static org.keycloak.testsuite.util.WaitUtils.pause; @@ -26,7 +29,7 @@ public class RealmRolesTest extends AbstractRolesTest { @Page private CreateRole createRolePage; @Page - private Role rolePage; + private RoleDetails roleDetailsPage; private RoleRepresentation testRole; @@ -51,10 +54,10 @@ public class RealmRolesTest extends AbstractRolesTest { assertCurrentUrlEquals(realmRolesPage); realmRolesPage.table().editRole(roleRep.getName()); // assertCurrentUrl(role); // can't do this, role id needed as uri param - rolePage.form().setBasicAttributes(roleRep); - rolePage.form().save(); + roleDetailsPage.form().setBasicAttributes(roleRep); + roleDetailsPage.form().save(); assertAlertSuccess(); - rolePage.form().setCompositeRoles(roleRep); + roleDetailsPage.form().setCompositeRoles(roleRep); } public void assertBasicRoleAttributesEqual(RoleRepresentation r1, RoleRepresentation r2) { @@ -72,12 +75,12 @@ public class RealmRolesTest extends AbstractRolesTest { RoleRepresentation foundRole = realmRolesPage.table().findRole(testRole.getName()); // search & get role from table assertBasicRoleAttributesEqual(testRole, foundRole); realmRolesPage.table().editRole(testRole.getName()); - foundRole = rolePage.form().getBasicAttributes(); + foundRole = roleDetailsPage.form().getBasicAttributes(); assertBasicRoleAttributesEqual(testRole, foundRole); testRole.setDescription("updated role description"); - rolePage.form().setDescription(testRole.getDescription()); - rolePage.form().save(); + roleDetailsPage.form().setDescription(testRole.getDescription()); + roleDetailsPage.form().save(); assertAlertSuccess(); configure().roles(); @@ -96,7 +99,7 @@ public class RealmRolesTest extends AbstractRolesTest { // add again addRole(testRole); // delete from page - rolePage.form().delete(); + roleDetailsPage.form().delete(); modalDialog.confirmDeletion(); assertCurrentUrlEquals(realmRolesPage); } diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/UsersInRoleTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/UsersInRoleTest.java index c68366c294..cf14539b81 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/UsersInRoleTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/roles/UsersInRoleTest.java @@ -3,33 +3,28 @@ */ package org.keycloak.testsuite.console.roles; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.keycloak.testsuite.admin.ApiUtil.createUserWithAdminClient; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - import org.jboss.arquillian.graphene.page.Page; import org.junit.Before; import org.junit.Test; -import org.keycloak.admin.client.resource.RoleResource; -import org.keycloak.admin.client.resource.RolesResource; -import org.keycloak.admin.client.resource.UserResource; import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.console.page.roles.DefaultRoles; import org.keycloak.testsuite.console.page.roles.RealmRoles; -import org.keycloak.testsuite.console.page.roles.Role; -import org.keycloak.testsuite.console.page.roles.Roles; +import org.keycloak.testsuite.console.page.roles.UsersInRole; import org.keycloak.testsuite.console.page.users.UserRoleMappings; -import org.keycloak.testsuite.console.page.users.Users; +import org.keycloak.testsuite.util.RealmRepUtil; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.keycloak.testsuite.admin.ApiUtil.assignRealmRoles; +import static org.keycloak.testsuite.admin.ApiUtil.createUserWithAdminClient; +import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; /** - * @author Antonio Ferreira + * See KEYCLOAK-2035 * + * @author Antonio Ferreira + * @author Vaclav Muzikar */ public class UsersInRoleTest extends AbstractRolesTest { @@ -39,80 +34,61 @@ public class UsersInRoleTest extends AbstractRolesTest { @Page private UserRoleMappings userRolesPage; - + @Page - private Users usersPage; - - @Page - private Roles rolesPage; - - @Page - private Role rolePage; + private UsersInRole usersInRolePage; @Page private RealmRoles realmRolesPage; - + private RoleRepresentation testRoleRep; + private RoleRepresentation emptyTestRoleRep; private UserRepresentation newUser; - - @Before - public void beforeDefaultRolesTest() { + public void beforeUsersInRoleTestClass() { // create a role via admin client testRoleRep = new RoleRepresentation("test-role", "", false); - rolesResource().create(testRoleRep); + testRealmResource().roles().create(testRoleRep); + + emptyTestRoleRep = new RoleRepresentation("empty-test-role", "", false); + testRealmResource().roles().create(emptyTestRoleRep); newUser = new UserRepresentation(); newUser.setUsername("test_user"); newUser.setEnabled(true); - newUser.setEmail("test-role-member@test-role-member.com"); - newUser.setRequiredActions(Collections.emptyList()); - //testRealmResource().users().create(newUser); - createUserWithAdminClient(testRealmResource(), newUser); - rolesResource().create(testRoleRep); - rolesPage.navigateTo(); + newUser.setId(createUserWithAdminClient(testRealmResource(), newUser)); + + assignRealmRoles(testRealmResource(), newUser.getId(), testRoleRep.getName()); + + userPage.setId(newUser.getId()); } - - public RolesResource rolesResource() { - return testRealmResource().roles(); - } - - //Added for KEYCLOAK-2035 @Test - public void usersInRoleTabIsPresent() { + public void userInRoleIsPresent() { + // Clicking user name link + navigateToUsersInRole(testRoleRep); + assertEquals(1, usersInRolePage.usersTable().getUsersFromTableRows().size()); + usersInRolePage.usersTable().clickUser(newUser.getUsername()); + assertCurrentUrlEquals(userPage); - rolesPage.navigateTo(); - rolesPage.tabs().realmRoles(); - realmRolesPage.table().search(testRoleRep.getName()); - realmRolesPage.table().clickRole(testRoleRep.getName()); - //assert no users in list - //Role Page class missing a getUsers() method - - List users = testRealmResource().users().search("test_user", null, null, null, null, null); - assertEquals(1, users.size()); - UserResource user = testRealmResource().users().get(users.get(0).getId()); - UserRepresentation userRep = user.toRepresentation(); - - usersPage.navigateTo(); - usersPage.table().search(userRep.getUsername()); - usersPage.table().clickUser(userRep.getUsername()); - - assertFalse(userRolesPage.form().isAssignedRole(testRoleRep.getName())); - - RoleResource roleResource = testRealmResource().roles().get(testRoleRep.getName()); - List rolesToAdd = new LinkedList<>(); - rolesToAdd.add(roleResource.toRepresentation()); - testRealmResource().users().get(userRep.getId()).roles().realmLevel().add(rolesToAdd); - - rolesPage.navigateTo(); - rolesPage.tabs().realmRoles(); - realmRolesPage.table().search(testRoleRep.getName()); - realmRolesPage.table().clickRole(testRoleRep.getName()); - - assertTrue(userRolesPage.form().isAssignedRole(testRoleRep.getName())); + // Clicking edit button + navigateToUsersInRole(testRoleRep); + usersInRolePage.usersTable().editUser(newUser.getUsername()); + assertCurrentUrlEquals(userPage); } + @Test + public void emptyRoleTest() { + navigateToUsersInRole(emptyTestRoleRep); + assertEquals(0, usersInRolePage.usersTable().getUsersFromTableRows().size()); + assertTrue("No roles members message is not displayed", usersInRolePage.usersTable().noRoleMembersIsDisplayed()); + } + private void navigateToUsersInRole(RoleRepresentation role) { + realmRolesPage.navigateTo(); + realmRolesPage.tabs().realmRoles(); + realmRolesPage.table().clickRole(role.getName()); + usersInRolePage.roleTabs().usersInRole(); + } }