Testsuite PoC - Implement a ChromeWebDriverSupplier (#30377) (#31026)

Also edits Selenium dependencies at root and for both test suites

Closes keycloak#30377

Signed-off-by: Simon Vacek <simonvacky@email.cz>
This commit is contained in:
Šimon Vacek 2024-07-08 14:01:34 +02:00 committed by GitHub
parent cb54980f7b
commit 628de9d92a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 20 deletions

View file

@ -35,7 +35,8 @@
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<scope>provided</scope> <version>2.35.0</version>
<type>pom</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.keycloak</groupId> <groupId>org.keycloak</groupId>

15
pom.xml
View file

@ -178,7 +178,6 @@
<jmeter.version>2.10</jmeter.version> <jmeter.version>2.10</jmeter.version>
<junit.version>4.13.2</junit.version> <junit.version>4.13.2</junit.version>
<picketlink.version>2.7.0.Final</picketlink.version> <picketlink.version>2.7.0.Final</picketlink.version>
<selenium.version>2.35.0</selenium.version>
<!-- Needs to be aligned with Quarkus, see e.g. https://github.com/quarkusio/quarkus-quickstarts/blob/2.13.5.Final/getting-started-async/pom.xml#L14 --> <!-- Needs to be aligned with Quarkus, see e.g. https://github.com/quarkusio/quarkus-quickstarts/blob/2.13.5.Final/getting-started-async/pom.xml#L14 -->
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version> <surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
<xml-apis.version>1.4.01</xml-apis.version> <xml-apis.version>1.4.01</xml-apis.version>
@ -678,20 +677,6 @@
<artifactId>api-ldap-codec-standalone</artifactId> <artifactId>api-ldap-codec-standalone</artifactId>
<version>${apacheds.codec.version}</version> <version>${apacheds.codec.version}</version>
</dependency> </dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.jmeter</groupId> <groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId> <artifactId>ApacheJMeter_java</artifactId>

View file

@ -31,6 +31,10 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<description>PoC JUnit 5 testing framework for Keycloak</description> <description>PoC JUnit 5 testing framework for Keycloak</description>
<properties>
<selenium.version>4.21.0</selenium.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.keycloak</groupId> <groupId>org.keycloak</groupId>
@ -47,13 +51,19 @@
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<version>4.21.0</version> <version>${selenium.version}</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId> <artifactId>selenium-firefox-driver</artifactId>
<version>4.21.0</version> <version>${selenium.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -0,0 +1,42 @@
package org.keycloak.test.framework.webdriver;
import org.keycloak.test.framework.injection.InstanceWrapper;
import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.injection.Registry;
import org.keycloak.test.framework.injection.Supplier;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeWebDriverSupplier implements Supplier<WebDriver, TestWebDriver> {
@Override
public Class<TestWebDriver> getAnnotationClass() {
return TestWebDriver.class;
}
@Override
public Class<WebDriver> getValueType() {
return WebDriver.class;
}
@Override
public InstanceWrapper<WebDriver, TestWebDriver> getValue(Registry registry, TestWebDriver annotation) {
final var driver = new ChromeDriver();
return new InstanceWrapper<>(this, annotation, driver);
}
@Override
public LifeCycle getLifeCycle() {
return LifeCycle.GLOBAL;
}
@Override
public boolean compatible(InstanceWrapper<WebDriver, TestWebDriver> a, InstanceWrapper<WebDriver, TestWebDriver> b) {
return true;
}
@Override
public void close(WebDriver instance) {
instance.quit();
}
}

View file

@ -37,7 +37,7 @@ public class FirefoxWebDriverSupplier implements Supplier<WebDriver, TestWebDriv
@Override @Override
public void close(WebDriver instance) { public void close(WebDriver instance) {
instance.close(); instance.quit();
} }
} }

View file

@ -2,4 +2,5 @@ org.keycloak.test.framework.admin.KeycloakAdminClientSupplier
org.keycloak.test.framework.realm.ClientSupplier org.keycloak.test.framework.realm.ClientSupplier
org.keycloak.test.framework.realm.RealmSupplier org.keycloak.test.framework.realm.RealmSupplier
org.keycloak.test.framework.server.KeycloakTestServerSupplier org.keycloak.test.framework.server.KeycloakTestServerSupplier
org.keycloak.test.framework.webdriver.FirefoxWebDriverSupplier org.keycloak.test.framework.webdriver.ChromeWebDriverSupplier
org.keycloak.test.framework.webdriver.FirefoxWebDriverSupplier