Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void authenticate(AuthenticationFlowContext context) {
String accessCode = context.generateAccessCode();
String actionUrl = context.getActionUrl(accessCode).toString();

StringBuilder response = new StringBuilder("<html><head><title>PushTheButton</title></head><body>");
StringBuilder response = new StringBuilder("<html><head><title>PushTheButton</title></head><body data-page-id=\"push-the-button\">");

UserModel user = context.getUser();
if (user == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import java.net.URL;

import org.keycloak.representations.idm.CredentialRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.testsuite.auth.page.login.SAMLPostLogin;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.util.WaitUtils;

import org.jboss.arquillian.container.test.api.OperateOnDeployment;
Expand All @@ -40,7 +41,7 @@ public class EmployeeRoleMappingServlet extends SAMLServlet {
@OperateOnDeployment(DEPLOYMENT_NAME)
private URL url;

private SAMLPostLogin loginPage;
private LoginPage loginPage;
private UserRepresentation user;

@Override
Expand All @@ -56,7 +57,7 @@ public URL getInjectedUrl() {
* @param page the login page to be used to authenticate an user.
* @param user the user being authenticated.
*/
public void setupLoginInfo(final SAMLPostLogin page, final UserRepresentation user) {
public void setupLoginInfo(final LoginPage page, final UserRepresentation user) {
this.loginPage = page;
this.user = user;
}
Expand All @@ -75,7 +76,8 @@ public void setRolesToCheck(String roles) {
if (this.loginPage != null) {
// authenticates user before calling setCheckRoles on the servlet - required in filter tests.
driver.navigate().to(getUriBuilder().clone().path("setCheckRoles").queryParam("roles", roles).build().toASCIIString());
loginPage.form().login(user);
String password = user.getCredentials().stream().filter(f -> f.getType().equals(CredentialRepresentation.PASSWORD)).findFirst().get().getValue();
loginPage.login(user.getUsername(), password);
WaitUtils.waitUntilElement(By.tagName("body")).text().contains("These roles will be checked:");
this.logout();
} else {
Expand All @@ -88,7 +90,8 @@ public void checkRolesEndPoint(boolean value) {
if (this.loginPage != null) {
// authenticates user before calling setCheckRoles on the servlet - required in filter tests.
driver.navigate().to(getUriBuilder().clone().path((value ? "" : "un") + "checkRoles").build().toASCIIString());
loginPage.form().login(user);
String password = user.getCredentials().stream().filter(f -> f.getType().equals(CredentialRepresentation.PASSWORD)).findFirst().get().getValue();
loginPage.login(user.getUsername(), password);
WaitUtils.waitUntilElement(By.tagName("body")).text().contains("Roles will " + (value ? "" : "not ") + "be checked");
this.logout();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.testsuite.util.UIUtils;

import org.jboss.arquillian.graphene.page.Page;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
Expand All @@ -33,7 +32,7 @@
*/
public class AccountFields extends FieldsBase {

@Page

private AccountErrors inputErrors;

@FindBy(id = "username")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.keycloak.testsuite.util.UIUtils;

import org.jboss.arquillian.graphene.page.Page;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
Expand All @@ -31,7 +30,7 @@
*/
public class PasswordFields extends FieldsBase {

@Page

private PasswordErrors inputErrors;

@FindBy(id = "password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import jakarta.ws.rs.core.UriBuilder;

import org.jboss.arquillian.graphene.page.Page;

/**
*
Expand Down Expand Up @@ -46,7 +45,7 @@ private String getProtocol() {
return getUriParameter(PROTOCOL).toString();
}

@Page

private LoginForm form;

public LoginForm form() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.keycloak.testsuite.auth.page.login;

import org.keycloak.models.UserModel;
import org.keycloak.testsuite.pages.LogoutSessionsPage;

import org.openqa.selenium.NoSuchElementException;
Expand Down Expand Up @@ -44,9 +43,8 @@ public class UpdateEmailPage extends LogoutSessionsPage {
private WebElement feedbackMessage;

@Override
public boolean isCurrent() {
return driver.getCurrentUrl().contains("login-actions/required-action")
&& driver.getCurrentUrl().contains("execution=" + UserModel.RequiredAction.UPDATE_EMAIL.name());
public String getExpectedPageId() {
return "login-update-email";
}

public void changeEmail(String email){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@

package org.keycloak.testsuite.pages;

import java.time.Duration;

import org.keycloak.testsuite.util.oauth.OAuthClient;

import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*
* THIS ABSTRACT PAGE WON'T BE MIGRATED TO THE NEW TEST FRAMEWORK!
*/
@Deprecated(forRemoval = true)
public abstract class AbstractPage {

@ArquillianResource
Expand All @@ -35,20 +44,30 @@ public abstract class AbstractPage {
protected OAuthClient oauth;

public void assertCurrent() {
String name = getClass().getSimpleName();
Assertions.assertTrue(isCurrent(),
"Expected " + name + " but was " + driver.getTitle() + " (" + driver.getCurrentUrl() + ")");
waitForPage(this);
}

abstract public boolean isCurrent();

public boolean isCurrent(String expectedTitle) {
return PageUtils.getPageTitle(driver).equals(expectedTitle);
}
public abstract String getExpectedPageId();

public void setDriver(WebDriver driver) {
this.driver = driver ;
oauth.setDriver(driver);
}

private void waitForPage(AbstractPage page) {
String expectedPageId = page.getExpectedPageId();
try {
createDefaultWait().ignoring(StaleElementReferenceException.class).until(d -> expectedPageId.equals(getCurrentPageId()));
} catch (TimeoutException e) {
Assertions.fail("Expected page '" + expectedPageId + "' to be loaded, but currently on page '" + getCurrentPageId() + "' after timeout");
}
}

private WebDriverWait createDefaultWait() {
return new WebDriverWait(driver, Duration.ofSeconds(5), Duration.ofMillis(50));
}

private String getCurrentPageId() {
return driver.findElement(By.xpath("//body")).getAttribute("data-page-id");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.keycloak.testsuite.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

Expand All @@ -41,11 +40,7 @@ public void cancel() {
}

@Override
public boolean isCurrent() {
return isCurrent(driver);
}

public boolean isCurrent(WebDriver driver1) {
return PageUtils.getPageTitle(driver1).contains("Grant Access to ");
public String getExpectedPageId() {
return "login-login-oauth-grant";
}
}
Loading
Loading