Fix social login tests (#33525)

Part of #33524

Signed-off-by: Ivan Khomyn <ikhomyn@redhat.com>
This commit is contained in:
ikhomyn 2024-10-07 16:44:33 +02:00 committed by GitHub
parent 304da50efc
commit 6b96ee2b6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 37 deletions

View file

@ -36,10 +36,10 @@ public class LoginActions extends LoginBase {
.path("login-actions");
}
@FindBy(css = "button[type='submit']")
@FindBy(css = "*[type='submit']")
private WebElement submitButton;
@FindBy(css = "button[name='cancel-aia']")
@FindBy(css = "*[name='cancel-aia']")
private WebElement cancelButton;
public void submit() {

View file

@ -17,14 +17,21 @@
package org.keycloak.testsuite.pages.social;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
/**
* @author Vaclav Muzikar <vmuzikar@redhat.com>
*/
public class FacebookLoginPage extends AbstractSocialLoginPage {
private static final String continueButtonLocator = "//*[contains(@aria-label,'Continue')]";
private static final String allowAllCookiesLocator = "//button[text()='Allow all cookies']";
@FindBy(id = "email")
private WebElement emailInput;
@ -34,12 +41,25 @@ public class FacebookLoginPage extends AbstractSocialLoginPage {
@FindBy(id = "loginbutton")
private WebElement loginButton;
@FindBy(xpath = continueButtonLocator)
private WebElement continueButton;
@Override
public void login(String user, String password) {
emailInput.clear();
emailInput.sendKeys(user);
passwordInput.sendKeys(password);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", loginButton);
// Check if allowing cookies is required and eventually allow them
List<WebElement> allowCookiesButton = driver.findElements(By.xpath(allowAllCookiesLocator));
if (allowCookiesButton.size() > 0)
allowCookiesButton.get(0).click();
if (driver.findElements(By.xpath(continueButtonLocator)).isEmpty()){ //on first login
emailInput.clear();
emailInput.sendKeys(user);
passwordInput.sendKeys(password);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", loginButton);
continueButton.click();
}else{ //already logged in in previous testcase, just confirm previous session
continueButton.click();
}
}
}

View file

@ -17,6 +17,7 @@
package org.keycloak.testsuite.pages.social;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -33,11 +34,15 @@ public class StackOverflowLoginPage extends AbstractSocialLoginPage {
@FindBy(xpath = "//button[@name='submit-button']")
private WebElement loginButton;
@FindBy(id = "onetrust-accept-btn-handler")
private WebElement acceptAllCookiesButton;
@Override
public void login(String user, String password) {
acceptAllCookiesButton.click();
usernameInput.sendKeys(user);
passwordInput.sendKeys(password);
loginButton.click();
passwordInput.sendKeys(Keys.RETURN);
}
}

View file

@ -27,7 +27,7 @@ import org.openqa.selenium.support.FindBy;
*/
public class TwitterLoginPage extends AbstractSocialLoginPage {
@FindBy(xpath = "//input[@type='text' and @name='text']")
@FindBy(xpath = "//input[@type='text']")
private WebElement usernameInput;
@FindBy(xpath = "//input[@type='password']")
@ -39,10 +39,7 @@ public class TwitterLoginPage extends AbstractSocialLoginPage {
// needs lots of JS, twitter does not work with default HtmlUnit driver
usernameInput.clear();
usernameInput.sendKeys(user);
usernameInput.sendKeys(Keys.RETURN);
// wait for the password input to appear
WaitUtils.waitUntilElement(passwordInput).is().visible();
passwordInput.clear();
passwordInput.sendKeys(password);
passwordInput.sendKeys(Keys.RETURN);

View file

@ -346,7 +346,7 @@ public class SocialLoginTest extends AbstractKeycloakTest {
@UncaughtServerErrorExpected
public void facebookLogin() throws InterruptedException {
setTestProvider(FACEBOOK);
performFacebookLogin();
performLogin();
appPage.assertCurrent();
testTokenExchange();
}
@ -356,7 +356,7 @@ public class SocialLoginTest extends AbstractKeycloakTest {
public void facebookLoginWithEnhancedScope() throws InterruptedException {
setTestProvider(FACEBOOK_INCLUDE_BIRTHDAY);
addAttributeMapper("birthday", "birthday");
performFacebookLogin();
performLogin();
appPage.assertCurrent();
assertAttribute("birthday", getConfig("profile.birthday"));
testTokenExchange();
@ -514,27 +514,6 @@ public class SocialLoginTest extends AbstractKeycloakTest {
doLogin();
}
private void performFacebookLogin() {
navigateToLoginPage();
// Check if allowing cookies is required and eventually allow them
List<WebElement> allowCookiesButton = driver.findElements(By.xpath("//button[text()='Allow all cookies']"));
if (allowCookiesButton.size() > 0) {
allowCookiesButton.get(0).click();
}
doLogin();
// When logging into facebook app for the first time user is required to press continue as button to finish login flow
String firstName = getConfig("profile.firstName");
List<WebElement> continueAsButton = driver.findElements(By.xpath("//span[text()='Continue as " + firstName + "']"));
if (continueAsButton.size() > 0) {
continueAsButton.get(0).click();
WaitUtils.pause(3000);
WaitUtils.waitForPageToLoad();
}
}
private void navigateToLoginPage() {
currentSocialLoginPage.logout(); // try to logout first to be sure we're not logged in
@ -570,7 +549,7 @@ public class SocialLoginTest extends AbstractKeycloakTest {
assertNotNull(users.get(0).getAttributes().get(attrName));
String attrValue = users.get(0).getAttributes().get(attrName).get(0);
if (currentTestProvider.equals(LINKEDIN) && attrName.equals("picture")) {
assertTrue(attrValue.contains(expectedValue));
assertTrue(attrValue.contains(expectedValue.replace("image/","image/v2/").replace("/0/","/")));
} else {
assertEquals(expectedValue, attrValue);
}