Fix social login tests (#33525)
Part of #33524 Signed-off-by: Ivan Khomyn <ikhomyn@redhat.com>
This commit is contained in:
parent
304da50efc
commit
6b96ee2b6d
5 changed files with 38 additions and 37 deletions
|
@ -36,10 +36,10 @@ public class LoginActions extends LoginBase {
|
||||||
.path("login-actions");
|
.path("login-actions");
|
||||||
}
|
}
|
||||||
|
|
||||||
@FindBy(css = "button[type='submit']")
|
@FindBy(css = "*[type='submit']")
|
||||||
private WebElement submitButton;
|
private WebElement submitButton;
|
||||||
|
|
||||||
@FindBy(css = "button[name='cancel-aia']")
|
@FindBy(css = "*[name='cancel-aia']")
|
||||||
private WebElement cancelButton;
|
private WebElement cancelButton;
|
||||||
|
|
||||||
public void submit() {
|
public void submit() {
|
||||||
|
|
|
@ -17,14 +17,21 @@
|
||||||
|
|
||||||
package org.keycloak.testsuite.pages.social;
|
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.JavascriptExecutor;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
*/
|
*/
|
||||||
public class FacebookLoginPage extends AbstractSocialLoginPage {
|
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")
|
@FindBy(id = "email")
|
||||||
private WebElement emailInput;
|
private WebElement emailInput;
|
||||||
|
|
||||||
|
@ -34,12 +41,25 @@ public class FacebookLoginPage extends AbstractSocialLoginPage {
|
||||||
@FindBy(id = "loginbutton")
|
@FindBy(id = "loginbutton")
|
||||||
private WebElement loginButton;
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@FindBy(xpath = continueButtonLocator)
|
||||||
|
private WebElement continueButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void login(String user, String password) {
|
public void login(String user, String password) {
|
||||||
emailInput.clear();
|
// Check if allowing cookies is required and eventually allow them
|
||||||
emailInput.sendKeys(user);
|
List<WebElement> allowCookiesButton = driver.findElements(By.xpath(allowAllCookiesLocator));
|
||||||
passwordInput.sendKeys(password);
|
if (allowCookiesButton.size() > 0)
|
||||||
JavascriptExecutor executor = (JavascriptExecutor) driver;
|
allowCookiesButton.get(0).click();
|
||||||
executor.executeScript("arguments[0].click();", loginButton);
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.keycloak.testsuite.pages.social;
|
package org.keycloak.testsuite.pages.social;
|
||||||
|
|
||||||
|
import org.openqa.selenium.Keys;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
@ -33,11 +34,15 @@ public class StackOverflowLoginPage extends AbstractSocialLoginPage {
|
||||||
@FindBy(xpath = "//button[@name='submit-button']")
|
@FindBy(xpath = "//button[@name='submit-button']")
|
||||||
private WebElement loginButton;
|
private WebElement loginButton;
|
||||||
|
|
||||||
|
@FindBy(id = "onetrust-accept-btn-handler")
|
||||||
|
private WebElement acceptAllCookiesButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void login(String user, String password) {
|
public void login(String user, String password) {
|
||||||
|
acceptAllCookiesButton.click();
|
||||||
|
|
||||||
usernameInput.sendKeys(user);
|
usernameInput.sendKeys(user);
|
||||||
passwordInput.sendKeys(password);
|
passwordInput.sendKeys(password);
|
||||||
|
passwordInput.sendKeys(Keys.RETURN);
|
||||||
loginButton.click();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.openqa.selenium.support.FindBy;
|
||||||
*/
|
*/
|
||||||
public class TwitterLoginPage extends AbstractSocialLoginPage {
|
public class TwitterLoginPage extends AbstractSocialLoginPage {
|
||||||
|
|
||||||
@FindBy(xpath = "//input[@type='text' and @name='text']")
|
@FindBy(xpath = "//input[@type='text']")
|
||||||
private WebElement usernameInput;
|
private WebElement usernameInput;
|
||||||
|
|
||||||
@FindBy(xpath = "//input[@type='password']")
|
@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
|
// needs lots of JS, twitter does not work with default HtmlUnit driver
|
||||||
usernameInput.clear();
|
usernameInput.clear();
|
||||||
usernameInput.sendKeys(user);
|
usernameInput.sendKeys(user);
|
||||||
usernameInput.sendKeys(Keys.RETURN);
|
|
||||||
|
|
||||||
// wait for the password input to appear
|
|
||||||
WaitUtils.waitUntilElement(passwordInput).is().visible();
|
|
||||||
passwordInput.clear();
|
passwordInput.clear();
|
||||||
passwordInput.sendKeys(password);
|
passwordInput.sendKeys(password);
|
||||||
passwordInput.sendKeys(Keys.RETURN);
|
passwordInput.sendKeys(Keys.RETURN);
|
||||||
|
|
|
@ -346,7 +346,7 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
@UncaughtServerErrorExpected
|
@UncaughtServerErrorExpected
|
||||||
public void facebookLogin() throws InterruptedException {
|
public void facebookLogin() throws InterruptedException {
|
||||||
setTestProvider(FACEBOOK);
|
setTestProvider(FACEBOOK);
|
||||||
performFacebookLogin();
|
performLogin();
|
||||||
appPage.assertCurrent();
|
appPage.assertCurrent();
|
||||||
testTokenExchange();
|
testTokenExchange();
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
public void facebookLoginWithEnhancedScope() throws InterruptedException {
|
public void facebookLoginWithEnhancedScope() throws InterruptedException {
|
||||||
setTestProvider(FACEBOOK_INCLUDE_BIRTHDAY);
|
setTestProvider(FACEBOOK_INCLUDE_BIRTHDAY);
|
||||||
addAttributeMapper("birthday", "birthday");
|
addAttributeMapper("birthday", "birthday");
|
||||||
performFacebookLogin();
|
performLogin();
|
||||||
appPage.assertCurrent();
|
appPage.assertCurrent();
|
||||||
assertAttribute("birthday", getConfig("profile.birthday"));
|
assertAttribute("birthday", getConfig("profile.birthday"));
|
||||||
testTokenExchange();
|
testTokenExchange();
|
||||||
|
@ -514,27 +514,6 @@ public class SocialLoginTest extends AbstractKeycloakTest {
|
||||||
doLogin();
|
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() {
|
private void navigateToLoginPage() {
|
||||||
currentSocialLoginPage.logout(); // try to logout first to be sure we're not logged in
|
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));
|
assertNotNull(users.get(0).getAttributes().get(attrName));
|
||||||
String attrValue = users.get(0).getAttributes().get(attrName).get(0);
|
String attrValue = users.get(0).getAttributes().get(attrName).get(0);
|
||||||
if (currentTestProvider.equals(LINKEDIN) && attrName.equals("picture")) {
|
if (currentTestProvider.equals(LINKEDIN) && attrName.equals("picture")) {
|
||||||
assertTrue(attrValue.contains(expectedValue));
|
assertTrue(attrValue.contains(expectedValue.replace("image/","image/v2/").replace("/0/","/")));
|
||||||
} else {
|
} else {
|
||||||
assertEquals(expectedValue, attrValue);
|
assertEquals(expectedValue, attrValue);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue