Merge pull request #4502 from mhajas/KEYCLOAK-5555
KEYCLOAK-5555 Use driver from function argument for URL Asserts
This commit is contained in:
commit
98c63bc195
8 changed files with 97 additions and 34 deletions
|
@ -20,11 +20,33 @@ package org.keycloak.testsuite.util;
|
||||||
import org.jboss.arquillian.graphene.context.GrapheneContext;
|
import org.jboss.arquillian.graphene.context.GrapheneContext;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
*/
|
*/
|
||||||
public final class DroneUtils {
|
public final class DroneUtils {
|
||||||
|
private static Queue<WebDriver> driverQueue = new LinkedList<>();
|
||||||
|
|
||||||
public static WebDriver getCurrentDriver() {
|
public static WebDriver getCurrentDriver() {
|
||||||
|
if (driverQueue.isEmpty()) {
|
||||||
return GrapheneContext.lastContext().getWebDriver();
|
return GrapheneContext.lastContext().getWebDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return driverQueue.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addWebDriver(WebDriver driver) {
|
||||||
|
driverQueue.add(driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeWebDriver() {
|
||||||
|
driverQueue.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetQueue() {
|
||||||
|
driverQueue = new LinkedList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ import org.keycloak.testsuite.auth.page.login.OIDCLogin;
|
||||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||||
import org.keycloak.testsuite.client.KeycloakTestingClient;
|
import org.keycloak.testsuite.client.KeycloakTestingClient;
|
||||||
import org.keycloak.testsuite.util.AdminClientUtil;
|
import org.keycloak.testsuite.util.AdminClientUtil;
|
||||||
|
import org.keycloak.testsuite.util.DroneUtils;
|
||||||
import org.keycloak.testsuite.util.OAuthClient;
|
import org.keycloak.testsuite.util.OAuthClient;
|
||||||
import org.keycloak.testsuite.util.TestCleanup;
|
import org.keycloak.testsuite.util.TestCleanup;
|
||||||
import org.keycloak.testsuite.util.TestEventsLogger;
|
import org.keycloak.testsuite.util.TestEventsLogger;
|
||||||
|
@ -213,6 +214,9 @@ public abstract class AbstractKeycloakTest {
|
||||||
}
|
}
|
||||||
testContext.getCleanups().clear();
|
testContext.getCleanups().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove all browsers from queue
|
||||||
|
DroneUtils.resetQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TestCleanup getCleanup(String realmName) {
|
protected TestCleanup getCleanup(String realmName) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public abstract class AbstractFuseAdminAdapterTest extends AbstractExampleAdapte
|
||||||
assertCurrentUrlDoesntStartWith(hawtioPage);
|
assertCurrentUrlDoesntStartWith(hawtioPage);
|
||||||
|
|
||||||
testRealmLoginPage.form().login("root", "password");
|
testRealmLoginPage.form().login("root", "password");
|
||||||
assertCurrentUrlStartsWith(hawtioPage.getDriver(), hawtioPage.toString() + "/welcome");
|
assertCurrentUrlStartsWith(hawtioPage.toString() + "/welcome", hawtioPage.getDriver());
|
||||||
hawtioPage.logout();
|
hawtioPage.logout();
|
||||||
assertCurrentUrlStartsWith(testRealmLoginPage);
|
assertCurrentUrlStartsWith(testRealmLoginPage);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public abstract class AbstractHawtioAdapterTest extends AbstractExampleAdapterTe
|
||||||
testRealmLoginPage.form().login("root", "password");
|
testRealmLoginPage.form().login("root", "password");
|
||||||
|
|
||||||
waitUntilElement(By.xpath("//body")).is().present();
|
waitUntilElement(By.xpath("//body")).is().present();
|
||||||
assertCurrentUrlStartsWith(hawtioPage.getDriver(), hawtioPage.toString() + "/welcome");
|
assertCurrentUrlStartsWith(hawtioPage.toString() + "/welcome", hawtioPage.getDriver());
|
||||||
|
|
||||||
hawtioPage.logout();
|
hawtioPage.logout();
|
||||||
pause(1000);
|
pause(1000);
|
||||||
|
|
|
@ -194,7 +194,7 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
|
||||||
|
|
||||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
||||||
testRealmLoginPage.form().login("bburke@redhat.com", "password");
|
testRealmLoginPage.form().login("bburke@redhat.com", "password");
|
||||||
assertCurrentUrlEquals(driver, inputPortal + "/secured/post");
|
assertCurrentUrlEquals(inputPortal + "/secured/post");
|
||||||
waitForPageToLoad();
|
waitForPageToLoad();
|
||||||
String pageSource = driver.getPageSource();
|
String pageSource = driver.getPageSource();
|
||||||
assertThat(pageSource, containsString("parameter=hello"));
|
assertThat(pageSource, containsString("parameter=hello"));
|
||||||
|
|
|
@ -127,7 +127,7 @@ public abstract class AbstractOIDCPublicKeyRotationAdapterTest extends AbstractS
|
||||||
testRealmLoginPage.form().waitForUsernameInputPresent();
|
testRealmLoginPage.form().waitForUsernameInputPresent();
|
||||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
||||||
testRealmLoginPage.form().login("bburke@redhat.com", "password");
|
testRealmLoginPage.form().login("bburke@redhat.com", "password");
|
||||||
URLAssert.assertCurrentUrlStartsWith(driver, tokenMinTTLPage.getInjectedUrl().toString());
|
URLAssert.assertCurrentUrlStartsWith(tokenMinTTLPage.getInjectedUrl().toString());
|
||||||
Assert.assertNull(tokenMinTTLPage.getAccessToken());
|
Assert.assertNull(tokenMinTTLPage.getAccessToken());
|
||||||
|
|
||||||
driver.navigate().to(logoutUri);
|
driver.navigate().to(logoutUri);
|
||||||
|
|
|
@ -37,9 +37,8 @@ import org.keycloak.testsuite.util.SecondBrowser;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.keycloak.testsuite.auth.page.AuthRealm.DEMO;
|
import static org.keycloak.testsuite.auth.page.AuthRealm.DEMO;
|
||||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
|
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
|
||||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf;
|
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf;
|
||||||
|
@ -84,13 +83,13 @@ public abstract class AbstractSessionServletAdapterTest extends AbstractServlets
|
||||||
|
|
||||||
// cannot pass to loginAndCheckSession becayse loginPage is not working together with driver2, therefore copypasta
|
// cannot pass to loginAndCheckSession becayse loginPage is not working together with driver2, therefore copypasta
|
||||||
driver2.navigate().to(sessionPortalPage.toString());
|
driver2.navigate().to(sessionPortalPage.toString());
|
||||||
assertCurrentUrlStartsWithLoginUrlOf(driver2, testRealmPage);
|
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage, driver2);
|
||||||
driver2.findElement(By.id("username")).sendKeys("bburke@redhat.com");
|
driver2.findElement(By.id("username")).sendKeys("bburke@redhat.com");
|
||||||
driver2.findElement(By.id("password")).sendKeys("password");
|
driver2.findElement(By.id("password")).sendKeys("password");
|
||||||
driver2.findElement(By.id("password")).submit();
|
driver2.findElement(By.id("password")).submit();
|
||||||
assertCurrentUrlEquals(driver2, sessionPortalPage);
|
assertCurrentUrlEquals(sessionPortalPage, driver2);
|
||||||
String pageSource = driver2.getPageSource();
|
String pageSource = driver2.getPageSource();
|
||||||
assertTrue(pageSource.contains("Counter=1"));
|
assertThat(pageSource, containsString("Counter=1"));
|
||||||
// Counter increased now
|
// Counter increased now
|
||||||
driver2.navigate().to(sessionPortalPage.toString());
|
driver2.navigate().to(sessionPortalPage.toString());
|
||||||
pageSource = driver2.getPageSource();
|
pageSource = driver2.getPageSource();
|
||||||
|
@ -108,12 +107,12 @@ public abstract class AbstractSessionServletAdapterTest extends AbstractServlets
|
||||||
|
|
||||||
// Assert that I am still logged in browser2 and same session is still preserved
|
// Assert that I am still logged in browser2 and same session is still preserved
|
||||||
driver2.navigate().to(sessionPortalPage.toString());
|
driver2.navigate().to(sessionPortalPage.toString());
|
||||||
assertCurrentUrlEquals(driver2, sessionPortalPage);
|
assertCurrentUrlEquals(sessionPortalPage, driver2);
|
||||||
pageSource = driver2.getPageSource();
|
pageSource = driver2.getPageSource();
|
||||||
assertTrue(pageSource.contains("Counter=3"));
|
assertThat(pageSource, containsString("Counter=3"));
|
||||||
|
|
||||||
driver2.navigate().to(logoutUri);
|
driver2.navigate().to(logoutUri);
|
||||||
assertCurrentUrlStartsWithLoginUrlOf(driver2, testRealmPage);
|
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage, driver2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,47 +46,85 @@ import static org.keycloak.testsuite.util.URLUtils.currentUrlStartWith;
|
||||||
*/
|
*/
|
||||||
public class URLAssert {
|
public class URLAssert {
|
||||||
|
|
||||||
public static void assertCurrentUrlEquals(AbstractPage page) {
|
public static void assertCurrentUrlEquals(final AbstractPage page, WebDriver driver) {
|
||||||
assertCurrentUrlEquals(page.getDriver(), page);
|
assertCurrentUrlEquals(page.toString(), driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlEquals(WebDriver driver, final AbstractPage page) {
|
public static void assertCurrentUrlEquals(final String url, WebDriver driver) {
|
||||||
String expected = page.toString();
|
DroneUtils.addWebDriver(driver);
|
||||||
assertTrue("Expected URL: " + expected + "; actual: " + driver.getCurrentUrl(),
|
assertCurrentUrlEquals(url);
|
||||||
currentUrlEqual(page.toString()));
|
DroneUtils.removeWebDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlEquals(WebDriver driver, final String url) {
|
public static void assertCurrentUrlEquals(final AbstractPage page) {
|
||||||
assertTrue("Expected URL: " + url + "; actual: " + driver.getCurrentUrl(),
|
assertCurrentUrlEquals(page.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlEquals(final String url) {
|
||||||
|
assertTrue("Expected URL: " + url + "; actual: " + DroneUtils.getCurrentDriver().getCurrentUrl(),
|
||||||
currentUrlEqual(url));
|
currentUrlEqual(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlStartsWith(AbstractPage page) {
|
|
||||||
assertCurrentUrlStartsWith(page.getDriver(), page.toString());
|
public static void assertCurrentUrlStartsWith(final AbstractPage page, WebDriver driver) {
|
||||||
|
assertCurrentUrlStartsWith(page.toString(), driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlStartsWith(WebDriver driver, final String url) {
|
public static void assertCurrentUrlStartsWith(final String url, WebDriver driver) {
|
||||||
assertTrue("URL expected to begin with:" + url + "; actual URL: " + driver.getCurrentUrl(),
|
DroneUtils.addWebDriver(driver);
|
||||||
|
assertCurrentUrlStartsWith(url);
|
||||||
|
DroneUtils.removeWebDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlStartsWith(final AbstractPage page) {
|
||||||
|
assertCurrentUrlStartsWith(page.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlStartsWith(final String url){
|
||||||
|
assertTrue("URL expected to begin with:" + url + "; actual URL: " + DroneUtils.getCurrentDriver().getCurrentUrl(),
|
||||||
currentUrlStartWith(url));
|
currentUrlStartWith(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlDoesntStartWith(AbstractPage page) {
|
|
||||||
assertCurrentUrlDoesntStartWith(page.getDriver(), page.toString());
|
public static void assertCurrentUrlDoesntStartWith(final AbstractPage page, WebDriver driver) {
|
||||||
|
assertCurrentUrlDoesntStartWith(page.toString(), driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlDoesntStartWith(WebDriver driver, final String url) {
|
public static void assertCurrentUrlDoesntStartWith(final String url, WebDriver driver) {
|
||||||
assertTrue("URL expected NOT to begin with:" + url + "; actual URL: " + driver.getCurrentUrl(),
|
DroneUtils.addWebDriver(driver);
|
||||||
|
assertCurrentUrlDoesntStartWith(url);
|
||||||
|
DroneUtils.removeWebDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlDoesntStartWith(AbstractPage page) {
|
||||||
|
assertCurrentUrlDoesntStartWith(page.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlDoesntStartWith(final String url) {
|
||||||
|
assertTrue("URL expected NOT to begin with:" + url + "; actual URL: " + DroneUtils.getCurrentDriver().getCurrentUrl(),
|
||||||
currentUrlDoesntStartWith(url));
|
currentUrlDoesntStartWith(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlStartsWithLoginUrlOf(PageWithLoginUrl page) {
|
|
||||||
assertCurrentUrlStartsWithLoginUrlOf(page.getDriver(), page);
|
public static void assertCurrentUrlStartsWithLoginUrlOf(final PageWithLoginUrl page, WebDriver driver) {
|
||||||
|
assertCurrentUrlStartsWithLoginUrlOf(page.getOIDCLoginUrl().toString(), driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertCurrentUrlStartsWithLoginUrlOf(WebDriver driver, PageWithLoginUrl page) {
|
public static void assertCurrentUrlStartsWithLoginUrlOf(final String url, WebDriver driver) {
|
||||||
assertCurrentUrlStartsWith(driver, page.getOIDCLoginUrl().toString());
|
DroneUtils.addWebDriver(driver);
|
||||||
|
assertCurrentUrlStartsWithLoginUrlOf(url);
|
||||||
|
DroneUtils.removeWebDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlStartsWithLoginUrlOf(final PageWithLoginUrl page) {
|
||||||
|
assertCurrentUrlStartsWithLoginUrlOf(page.getOIDCLoginUrl().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertCurrentUrlStartsWithLoginUrlOf(final String url) {
|
||||||
|
assertCurrentUrlStartsWith(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void assertGetURL(URI url, String accessToken, AssertResponseHandler handler) {
|
public static void assertGetURL(URI url, String accessToken, AssertResponseHandler handler) {
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue