make the tests capable of running against login v1 and v2 (#33732)

* make the tests capable of running against login v1 and v2

fixes: #31764

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* added build for v1

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* Update testsuite/integration-arquillian/tests/base/testsuites/login-suite

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* added login default theme

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* Update .github/workflows/ci.yml

Co-authored-by: Stian Thorgersen <stian@redhat.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>

* added default

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

---------

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
Co-authored-by: Stian Thorgersen <stian@redhat.com>
This commit is contained in:
Erik Jan de Wit 2024-11-14 10:21:30 +01:00 committed by GitHub
parent dcc18085ab
commit a2d33cf4aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 117 additions and 50 deletions

View File

@ -325,6 +325,41 @@ jobs:
with:
job-id: jdk-integration-tests-${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.version }}
login-v1-tests:
name: Login Theme v1 tests
needs: build
timeout-minutes: 100
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: integration-test-setup
name: Integration test setup
uses: ./.github/actions/integration-test-setup
- name: Run base tests
run: |
TESTS=`testsuite/integration-arquillian/tests/base/testsuites/suite.sh login`
echo "Tests: $TESTS"
./mvnw test ${{ env.SUREFIRE_RETRY }} -Pauth-server-quarkus -Dtest=$TESTS -pl testsuite/integration-arquillian/tests/base 2>&1 | misc/log/trimmer.sh
- name: Upload JVM Heapdumps
if: always()
uses: ./.github/actions/upload-heapdumps
- uses: ./.github/actions/upload-flaky-tests
name: Upload flaky tests
env:
GH_TOKEN: ${{ github.token }}
with:
job-name: Java Distribution IT
- name: Surefire reports
if: always()
uses: ./.github/actions/archive-surefire-reports
with:
job-id: jdk-integration-tests-${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.version }}
volatile-sessions-tests:
name: Volatile Sessions IT
needs: [build, conditional]

View File

@ -2,17 +2,20 @@ package org.keycloak.testsuite.auth.page.login;
import org.keycloak.authentication.requiredactions.DeleteAccount;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
import static org.keycloak.testsuite.util.UIUtils.clickLink;
public class DeleteAccountActionConfirmPage extends RequiredActions {
@FindBy(css = "button[name='cancel-aia']")
@FindBy(css = "[name='cancel-aia']")
WebElement cancelActionButton;
@FindBy(css = "button[type='submit']")
@FindBy(css = "[type='submit']")
WebElement confirmActionButton;
@Override
@ -34,10 +37,6 @@ public class DeleteAccountActionConfirmPage extends RequiredActions {
clickLink(confirmActionButton);
}
public boolean isErrorMessageDisplayed() {
return driver.findElements(By.cssSelector(".pf-v5-c-alert")).size() == 1;
}
public String getErrorMessageText() {
return driver.findElement(By.cssSelector("#kc-content-wrapper > div > span.kc-feedback-text")).getText();
}

View File

@ -75,12 +75,16 @@ public class FeedbackMessage {
}
}
public String getType() {
private String getType() {
try {
String cssClass = alertRoot.getAttribute("class");
Matcher classMatcher = ALERT_TYPE_CLASS_PATTERN.matcher(cssClass);
if (!classMatcher.find()) {
throw new RuntimeException("Failed to identify feedback message type");
classMatcher = Pattern.compile("alert-(.+)").matcher(cssClass);
if (!classMatcher.find())
throw new RuntimeException("Failed to identify feedback message type");
return classMatcher.group(1);
}
return classMatcher.group(1);
} catch (NoSuchElementException e) {

View File

@ -44,7 +44,7 @@ public class InstalledAppRedirectPage extends AbstractPage {
@FindBy(id = "kc-page-title")
private WebElement pageTitle;
@FindBy(className = "pf-v5-c-alert")
@FindBy(css = "div[class^='pf-v5-c-alert'], div[class^='alert-error']")
private WebElement errorBox;
@Override

View File

@ -126,7 +126,9 @@ public abstract class LanguageComboboxAwarePage extends AbstractPage {
}
public String getAttemptedUsername() {
return attemptedUsernameLabel.getAttribute("value");
String text = attemptedUsernameLabel.getAttribute("value");
if (text == null) return attemptedUsernameLabel.getText();
return text;
}
public void clickResetLogin() {

View File

@ -54,6 +54,9 @@ public class LoginPage extends LanguageComboboxAwarePage {
@FindBy(id = "input-error-password")
private WebElement passwordInputError;
@FindBy(id = "input-error")
private WebElement inputError;
@FindBy(id = "rememberMe")
private WebElement rememberMe;
@ -170,7 +173,11 @@ public class LoginPage extends LanguageComboboxAwarePage {
try {
return getTextFromElement(passwordInputError);
} catch (NoSuchElementException e) {
return null;
try {
return getTextFromElement(inputError);
} catch (NoSuchElementException error) {
return null;
}
}
}
}

View File

@ -32,10 +32,10 @@ public class LoginPasswordResetPage extends LanguageComboboxAwarePage {
@FindBy(id = "input-error-username")
private WebElement usernameError;
@FindBy(css = "button[type=\"submit\"]")
@FindBy(css = "[type=\"submit\"]")
private WebElement submitButton;
@FindBy(className = "pf-v5-c-success")
@FindBy(css = "[class='pf-v5-c-success'], [class='alert-success']")
private WebElement emailSuccessMessage;
@FindBy(css = "div[class^='pf-v5-c-alert'], div[class^='alert-error']")

View File

@ -32,7 +32,7 @@ public class LoginPasswordUpdatePage extends LogoutSessionsPage {
@FindBy(id = "password-confirm")
private WebElement passwordConfirmInput;
@FindBy(css = "button[type=\"submit\"]")
@FindBy(css = "[type=\"submit\"]")
private WebElement submitButton;
@FindBy(css = "div[class^='pf-v5-c-alert'], div[class^='alert-error']")

View File

@ -39,7 +39,7 @@ public class LoginTotpPage extends LanguageComboboxAwarePage {
@FindBy(id = "password-token")
private WebElement passwordToken;
@FindBy(css = "button[type=\"submit\"]")
@FindBy(css = "[type=\"submit\"]")
private WebElement submitButton;
@FindBy(css = "div[class^='pf-v5-c-alert'], div[class^='alert-error']")
@ -48,6 +48,9 @@ public class LoginTotpPage extends LanguageComboboxAwarePage {
@FindBy(id = "input-error-otp")
private WebElement totpInputCodeError;
@FindBy(id = "input-error-otp-code")
private WebElement otpInputCodeError;
public void login(String totp) {
otpInput.clear();
if (totp != null) otpInput.sendKeys(totp);
@ -67,7 +70,11 @@ public class LoginTotpPage extends LanguageComboboxAwarePage {
try {
return UIUtils.getTextFromElement(totpInputCodeError);
} catch (NoSuchElementException e) {
return null;
try {
return UIUtils.getTextFromElement(otpInputCodeError);
} catch (NoSuchElementException ex) {
return null;
}
}
}

View File

@ -48,13 +48,13 @@ public class LoginUpdateProfilePage extends AbstractPage {
@FindBy(name = "email")
private WebElement emailInput;
@FindBy(name = "department")
private WebElement departmentInput;
@FindBy(css = "input[type=\"submit\"]")
private WebElement submitButton;
@FindBy(name = "cancel-aia")
private WebElement cancelAIAButton;
@ -96,7 +96,7 @@ public class LoginUpdateProfilePage extends AbstractPage {
public String getLastName() {
return lastNameInput.getAttribute("value");
}
public String getEmail() {
return emailInput.getAttribute("value");
}
@ -116,9 +116,9 @@ public class LoginUpdateProfilePage extends AbstractPage {
public UpdateProfileErrors getInputErrors() {
return errorsPage;
}
public String getLabelForField(String fieldId) {
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText();
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText().replaceAll("\\s\\*$", "");
}
public WebElement getElementById(String fieldId) {
@ -130,7 +130,7 @@ public class LoginUpdateProfilePage extends AbstractPage {
return null;
}
}
public boolean isDepartmentPresent() {
try {
isDepartmentEnabled();
@ -268,7 +268,7 @@ public class LoginUpdateProfilePage extends AbstractPage {
@FindBy(id = "input-error-lastname")
private WebElement inputErrorLastName;
@FindBy(id = "input-error-lastName")
private WebElement inputErrorLastNameDynamic;

View File

@ -41,9 +41,9 @@ public class OAuthGrantPage extends LanguageComboboxAwarePage {
public static final String OFFLINE_ACCESS_CONSENT_TEXT = "Offline Access";
public static final String ROLES_CONSENT_TEXT = "User roles";
@FindBy(css = "button[name=\"accept\"]")
@FindBy(css = "[name=\"accept\"]")
private WebElement acceptButton;
@FindBy(css = "button[name=\"cancel\"]")
@FindBy(css = "[name=\"cancel\"]")
private WebElement cancelButton;

View File

@ -201,7 +201,7 @@ public class RegisterPage extends AbstractPage {
}
public String getLabelForField(String fieldId) {
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText();
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText().replaceAll("\\s\\*$", "");
}
public String getFirstName() {

View File

@ -23,7 +23,7 @@ public class UpdateAccountInformationPage extends LanguageComboboxAwarePage {
@FindBy(name = "department")
private WebElement departmentInput;
@FindBy(css = "input[type=\"submit\"]")
private WebElement submitButton;
@ -45,27 +45,27 @@ public class UpdateAccountInformationPage extends LanguageComboboxAwarePage {
clickLink(submitButton);
}
public void updateAccountInformation(String userName,
String email,
String firstName,
String lastName,
String lastName,
String department) {
usernameInput.clear();
usernameInput.sendKeys(userName);
emailInput.clear();
emailInput.sendKeys(email);
firstNameInput.clear();
firstNameInput.sendKeys(firstName);
lastNameInput.clear();
lastNameInput.sendKeys(lastName);
departmentInput.clear();
departmentInput.sendKeys(department);
clickLink(submitButton);
}
@ -99,11 +99,11 @@ public class UpdateAccountInformationPage extends LanguageComboboxAwarePage {
public boolean isCurrent() {
return PageUtils.getPageTitle(driver).equalsIgnoreCase("update account information");
}
public String getLabelForField(String fieldId) {
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText();
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText().replaceAll("\\s\\*$", "");
}
public boolean isDepartmentPresent() {
try {
return driver.findElement(By.name("department")).isDisplayed();

View File

@ -41,10 +41,10 @@ public class VerifyProfilePage extends AbstractPage {
@FindBy(name = "email")
private WebElement emailInput;
@FindBy(name = "department")
private WebElement departmentInput;
@FindBy(css = "input[type=\"submit\"]")
private WebElement submitButton;
@ -66,7 +66,7 @@ public class VerifyProfilePage extends AbstractPage {
submitButton.click();
}
public void update(String firstName, String lastName, String department) {
departmentInput.clear();
if (department != null) {
@ -103,9 +103,9 @@ public class VerifyProfilePage extends AbstractPage {
return null;
}
}
public String getLabelForField(String fieldId) {
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText();
return driver.findElement(By.cssSelector("label[for="+fieldId+"]")).getText().replaceAll("\\s\\*$", "");
}
public String getFirstName() {

View File

@ -148,11 +148,11 @@ public class RequiredActionUpdateProfileWithUserProfileTest extends AbstractTest
//assert field names
// i18n replaced
Assert.assertEquals("First name *", updateProfilePage.getLabelForField("firstName"));
Assert.assertEquals("First name", updateProfilePage.getLabelForField("firstName"));
// attribute name used if no display name set
Assert.assertEquals("lastName", updateProfilePage.getLabelForField("lastName"));
// direct value in display name
Assert.assertEquals("Department *", updateProfilePage.getLabelForField("department"));
Assert.assertEquals("Department", updateProfilePage.getLabelForField("department"));
}

View File

@ -34,6 +34,7 @@ import org.keycloak.testsuite.Assert;
import org.keycloak.testsuite.util.FlowUtil;
import org.keycloak.testsuite.util.UIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import static org.junit.Assert.assertEquals;
@ -120,7 +121,13 @@ public abstract class AbstractDefaultIdpTest extends AbstractInitializedBaseBrok
waitForPage(driver, "sign in to", true);
WebElement errorElement = driver.findElement(By.className("pf-v5-c-alert"));
WebElement errorElement;
try {
errorElement = driver.findElement(By.className("pf-v5-c-alert"));
} catch (NoSuchElementException e) {
errorElement = driver.findElement(By.className("alert-error"));
}
assertNotNull("Page should show an error message but it's missing", errorElement);
// Login to IDP failed due consent denied. Error message is displayed on the username/password screen of the consumer realm

View File

@ -465,11 +465,11 @@ public class KcOidcFirstBrokerLoginTest extends AbstractFirstBrokerLoginTest {
//assert field names
// i18n replaced
org.junit.Assert.assertEquals("First name *", updateAccountInformationPage.getLabelForField("firstName"));
org.junit.Assert.assertEquals("First name", updateAccountInformationPage.getLabelForField("firstName"));
// attribute name used if no display name set
org.junit.Assert.assertEquals("lastName", updateAccountInformationPage.getLabelForField("lastName"));
// direct value in display name
org.junit.Assert.assertEquals("Department *", updateAccountInformationPage.getLabelForField("department"));
org.junit.Assert.assertEquals("Department", updateAccountInformationPage.getLabelForField("department"));
}
@Test

View File

@ -265,11 +265,11 @@ public class RegisterWithUserProfileTest extends AbstractTestRealmKeycloakTest {
//assert field names
// i18n replaced
Assert.assertEquals("First name *",registerPage.getLabelForField("firstName"));
Assert.assertEquals("First name",registerPage.getLabelForField("firstName"));
// attribute name used if no display name set
Assert.assertEquals("lastName",registerPage.getLabelForField("lastName"));
// direct value in display name
Assert.assertEquals("Department *",registerPage.getLabelForField("department"));
Assert.assertEquals("Department",registerPage.getLabelForField("department"));
}
@Test

View File

@ -191,11 +191,11 @@ public class VerifyProfileTest extends AbstractTestRealmKeycloakTest {
//assert field names
// i18n replaced
Assert.assertEquals("First name *",verifyProfilePage.getLabelForField("firstName"));
Assert.assertEquals("First name",verifyProfilePage.getLabelForField("firstName"));
// attribute name used if no display name set
Assert.assertEquals("lastName",verifyProfilePage.getLabelForField("lastName"));
// direct value in display name
Assert.assertEquals("Department *",verifyProfilePage.getLabelForField("department"));
Assert.assertEquals("Department",verifyProfilePage.getLabelForField("department"));
}
@Test

View File

@ -0,0 +1,6 @@
org.keycloak.testsuite.actions
org.keycloak.testsuite.forms
KcOidcBrokerLoginHintTest
KcOidcFirstBrokerLoginTest
KcOidcMultipleTabsBrokerTest
LoginPageTest