Skip to content
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

Page object refactoring for two additional tests #2490

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.cloudfoundry.identity.uaa.util.RetryRule;
import org.cloudfoundry.identity.uaa.zone.IdentityZone;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
import org.flywaydb.core.internal.util.StringUtils;
import org.hamcrest.Matchers;
import org.junit.After;
Expand Down Expand Up @@ -338,11 +337,14 @@ public void testSimpleSamlPhpLogin() throws Exception {
public void testSimpleSamlPhpLoginDisplaysLastLogin() throws Exception {
Long beforeTest = System.currentTimeMillis();
IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN);
login(provider);
logout();
login(provider);
LoginPage.go(webDriver, baseUrl)
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.logout()
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.hasLastLoginTime();

assertNotNull(webDriver.findElement(By.cssSelector("#last_login_time")));
Long afterTest = System.currentTimeMillis();
String zoneAdminToken = IntegrationTestUtils.getClientCredentialsToken(serverRunning, "admin", "adminsecret");
ScimUser user = IntegrationTestUtils.getUser(zoneAdminToken, baseUrl, SAML_ORIGIN, testAccounts.getEmail());
Expand Down Expand Up @@ -442,21 +444,11 @@ public void testSingleLogoutWithNoLogoutUrlOnIDP() throws Exception {

provider = IntegrationTestUtils.createOrUpdateProvider(zoneAdminToken, baseUrl, provider);

webDriver.get(baseUrl + "/login");
Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
webDriver.findElement(By.xpath(SIMPLESAMLPHP_LOGIN_PROMPT_XPATH_EXPR));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
webDriver.findElement(By.xpath("//input[@value='Login']")).click();
assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to"));

webDriver.findElement(By.cssSelector(".dropdown-trigger")).click();
webDriver.findElement(By.linkText("Sign Out")).click();
webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();

assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to"));
LoginPage.go(webDriver, baseUrl)
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.logout()
.automaticSamlLogin();
swalchemist marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
Expand Down Expand Up @@ -1502,22 +1494,6 @@ private SamlIdentityProviderDefinition createIDPWithNoSLOSConfigured() {
return def;
}

private void logout() {
webDriver.findElement(By.cssSelector(".dropdown-trigger")).click();
webDriver.findElement(By.linkText("Sign Out")).click();
}

private void login(IdentityProvider<SamlIdentityProviderDefinition> provider) {
webDriver.get(baseUrl + "/login");
Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
webDriver.findElement(By.xpath(SIMPLESAMLPHP_LOGIN_PROMPT_XPATH_EXPR));
webDriver.findElement(By.name("username")).clear();
webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
webDriver.findElement(By.xpath("//input[@value='Login']")).click();
}

private void CallEmpptyPageAndCheckHttpStatusCode(String errorPath, int codeExpected) throws IOException {
HttpURLConnection cn = (HttpURLConnection)new URL(baseUrl + errorPath).openConnection();
cn.setRequestMethod("GET");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package org.cloudfoundry.identity.uaa.integration.pageObjects;

import org.hamcrest.Matchers;
import org.joda.time.DateTime;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.opensaml.xml.encryption.Public;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.assertNotNull;

public class HomePage extends Page {
public HomePage(WebDriver driver) {
super(driver);
assertThat("Should be on the home page", driver.getCurrentUrl(), endsWith("/"));
assertThat(driver.getPageSource(), Matchers.containsString("Where to?"));
}

public boolean hasLastLoginTime() {
WebElement lastLoginTime = driver.findElement(By.id("last_login_time"));
String loginTime = lastLoginTime.getText();
return loginTime != null && ! loginTime.isBlank();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import static org.junit.Assert.assertThat;

public class LoginPage extends Page {

static public LoginPage go(WebDriver driver, String baseUrl) {
driver.get(baseUrl + "/login");
return new LoginPage(driver);
}

public LoginPage(WebDriver driver) {
super(driver);
assertThat("Should be on the login page", driver.getCurrentUrl(), endsWith("/login"));
Expand All @@ -15,7 +21,19 @@ public LoginPage(WebDriver driver) {
// When there is a SAML integration, there is a link to go to a SAML login page instead. This assumes there is
// only one SAML link.
public SamlLoginPage startSamlLogin() {
driver.findElement(By.className("saml-login-link")).click();
clickFirstSamlLoginLink();
return new SamlLoginPage(driver);
}

// If the SAML IDP has no logout URL in the metadata, logging out of UAA will leave
// the IDP still logged in, and when going back to the SAML login page, it will log
// the app back in automatically and immediately redirect to the post-login page.
public HomePage automaticSamlLogin() {
clickFirstSamlLoginLink();
return new HomePage(driver);
}

private void clickFirstSamlLoginLink() {
driver.findElement(By.className("saml-login-link")).click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ public LoginPage begin(String baseUrl) {
}

public LoginPage logout() {
clickLogout();
return new LoginPage(driver);
}

private void clickLogout() {
driver.findElement(By.cssSelector(".dropdown-trigger")).click();
driver.findElement(By.linkText("Sign Out")).click();
return new LoginPage(driver);
}
}