-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add page supplier, including support for multi-typed suppliers #31313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
test-poc/base/src/test/java/org/keycloak/test/base/PagesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||
| package org.keycloak.test.base; | ||||||||||||
|
|
||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||
| import org.keycloak.test.framework.KeycloakIntegrationTest; | ||||||||||||
| import org.keycloak.test.framework.page.LoginPage; | ||||||||||||
| import org.keycloak.test.framework.page.TestPage; | ||||||||||||
| import org.keycloak.test.framework.page.WelcomePage; | ||||||||||||
|
|
||||||||||||
| @KeycloakIntegrationTest | ||||||||||||
| public class PagesTest { | ||||||||||||
|
|
||||||||||||
| @TestPage | ||||||||||||
| WelcomePage welcomePage; | ||||||||||||
|
|
||||||||||||
| @TestPage | ||||||||||||
| LoginPage loginPage; | ||||||||||||
|
|
||||||||||||
| @Test | ||||||||||||
| public void testLoginFromWelcome() { | ||||||||||||
| welcomePage.navigateTo(); | ||||||||||||
| try { | ||||||||||||
| Thread.sleep(1000); | ||||||||||||
| } catch (InterruptedException e) { | ||||||||||||
| throw new RuntimeException(e); | ||||||||||||
| } | ||||||||||||
| loginPage.fillLogin("admin", "admin"); | ||||||||||||
| loginPage.submit(); | ||||||||||||
| try { | ||||||||||||
| Thread.sleep(1000); | ||||||||||||
| } catch (InterruptedException e) { | ||||||||||||
| throw new RuntimeException(e); | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+28
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| } | ||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...-poc/framework/src/main/java/org/keycloak/test/framework/injection/RequestedInstance.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.keycloak.test.framework.injection; | ||
|
|
||
| import java.lang.annotation.Annotation; | ||
|
|
||
| public class RequestedInstance<T, A extends Annotation> { | ||
|
|
||
| private final Supplier<T, A> supplier; | ||
| private final A annotation; | ||
| private final Class<? extends T> valueType; | ||
|
|
||
| public RequestedInstance(Supplier<T, A> supplier, A annotation, Class<? extends T> valueType) { | ||
| this.supplier = supplier; | ||
| this.annotation = annotation; | ||
| this.valueType = valueType; | ||
| } | ||
|
|
||
| public Supplier<T, A> getSupplier() { | ||
| return supplier; | ||
| } | ||
|
|
||
| public A getAnnotation() { | ||
| return annotation; | ||
| } | ||
|
|
||
| public Class<? extends T> getValueType() { | ||
| return valueType; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test-poc/framework/src/main/java/org/keycloak/test/framework/page/AbstractPage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.keycloak.test.framework.page; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.support.PageFactory; | ||
|
|
||
| public class AbstractPage { | ||
|
|
||
| protected final WebDriver driver; | ||
|
|
||
| public AbstractPage(WebDriver driver) { | ||
| this.driver = driver; | ||
| PageFactory.initElements(driver, this); | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
test-poc/framework/src/main/java/org/keycloak/test/framework/page/LoginPage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.keycloak.test.framework.page; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.WebElement; | ||
| import org.openqa.selenium.support.FindBy; | ||
|
|
||
| public class LoginPage extends AbstractPage { | ||
|
|
||
| @FindBy(id = "username") | ||
| private WebElement usernameInput; | ||
|
|
||
| @FindBy(id = "password") | ||
| private WebElement passwordInput; | ||
|
|
||
| @FindBy(css = "[type=submit]") | ||
| private WebElement submitButton; | ||
|
|
||
| public LoginPage(WebDriver driver) { | ||
| super(driver); | ||
| } | ||
|
|
||
| public void fillLogin(String username, String password) { | ||
| usernameInput.sendKeys(username); | ||
| passwordInput.sendKeys(password); | ||
| } | ||
|
|
||
| public void submit() { | ||
| submitButton.click(); | ||
| } | ||
|
|
||
| } |
50 changes: 50 additions & 0 deletions
50
test-poc/framework/src/main/java/org/keycloak/test/framework/page/PageSupplier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package org.keycloak.test.framework.page; | ||
|
|
||
| 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.RequestedInstance; | ||
| import org.keycloak.test.framework.injection.Supplier; | ||
| import org.openqa.selenium.WebDriver; | ||
|
|
||
| import java.lang.reflect.Constructor; | ||
|
|
||
| public class PageSupplier implements Supplier<AbstractPage, TestPage> { | ||
|
|
||
| @Override | ||
| public Class<TestPage> getAnnotationClass() { | ||
| return TestPage.class; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<AbstractPage> getValueType() { | ||
| return AbstractPage.class; | ||
| } | ||
|
|
||
| public InstanceWrapper<AbstractPage, TestPage> getValue(Registry registry, TestPage annotation) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public InstanceWrapper<AbstractPage, TestPage> getValue(Registry registry, TestPage annotation, Class<? extends AbstractPage> valueType) { | ||
| InstanceWrapper<AbstractPage, TestPage> instanceWrapper = new InstanceWrapper<>(this, annotation); | ||
| WebDriver webDriver = registry.getDependency(WebDriver.class, instanceWrapper); | ||
| AbstractPage page = createPage(webDriver, valueType); | ||
| instanceWrapper.setValue(page, LifeCycle.CLASS); | ||
| return instanceWrapper; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean compatible(InstanceWrapper<AbstractPage, TestPage> a, RequestedInstance<AbstractPage, TestPage> b) { | ||
| return true; | ||
| } | ||
|
|
||
| private <S extends AbstractPage> S createPage(WebDriver webDriver, Class<S> valueType) { | ||
| try { | ||
| Constructor<S> constructor = valueType.getDeclaredConstructor(WebDriver.class); | ||
| return constructor.newInstance(webDriver); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
test-poc/framework/src/main/java/org/keycloak/test/framework/page/TestPage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.keycloak.test.framework.page; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.FIELD) | ||
| public @interface TestPage { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this debugger stuff