Skip to content

Commit

Permalink
refactor: page object method names
Browse files Browse the repository at this point in the history
* Based on review feedback, there's a need for the method names to make it easier to understand where a test is navigating to and what it's doing.
* Also removed the begin() method in the Page class, which was bad OO design since it referenced a child class.
  • Loading branch information
swalchemist committed Sep 20, 2023
1 parent 2b79ea6 commit a9b9f15
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.cloudfoundry.identity.uaa.account.UserInfoResponse;
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
import org.cloudfoundry.identity.uaa.integration.pageObjects.LoginPage;
import org.cloudfoundry.identity.uaa.integration.pageObjects.Page;
import org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils;
import org.cloudfoundry.identity.uaa.integration.util.ScreenshotOnFail;
import org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils;
Expand Down Expand Up @@ -329,10 +328,9 @@ public void testSimpleSamlPhpLogin() throws Exception {
createIdentityProvider(SAML_ORIGIN);

Long beforeTest = System.currentTimeMillis();
new Page(webDriver)
.begin(baseUrl)
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword());
LoginPage.go(webDriver, baseUrl)
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(testAccounts.getUserName(), testAccounts.getPassword());
Long afterTest = System.currentTimeMillis();

String zoneAdminToken = IntegrationTestUtils.getClientCredentialsToken(serverRunning, "admin", "adminsecret");
Expand All @@ -345,11 +343,11 @@ public void testSimpleSamlPhpLoginDisplaysLastLogin() throws Exception {
Long beforeTest = System.currentTimeMillis();
IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN);
LoginPage.go(webDriver, baseUrl)
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.logout()
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(testAccounts.getUserName(), testAccounts.getPassword())
.logout_goToLoginPage()
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(testAccounts.getUserName(), testAccounts.getPassword())
.hasLastLoginTime();

Long afterTest = System.currentTimeMillis();
Expand All @@ -362,12 +360,11 @@ public void testSimpleSamlPhpLoginDisplaysLastLogin() throws Exception {
public void testSingleLogout() throws Exception {
IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN);

LoginPage loginPage = new Page(webDriver)
.begin(baseUrl)
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.logout();
loginPage.startSamlLogin();
LoginPage.go(webDriver, baseUrl)
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(testAccounts.getUserName(), testAccounts.getPassword())
.logout_goToLoginPage()
.clickSamlLink_goToSamlLoginPage();
}

@Test
Expand Down Expand Up @@ -452,18 +449,18 @@ public void testSingleLogoutWithNoLogoutUrlOnIDP() throws Exception {
provider = IntegrationTestUtils.createOrUpdateProvider(zoneAdminToken, baseUrl, provider);

LoginPage.go(webDriver, baseUrl)
.startSamlLogin()
.login(testAccounts.getUserName(), testAccounts.getPassword())
.logout()
.automaticSamlLogin();
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(testAccounts.getUserName(), testAccounts.getPassword())
.logout_goToLoginPage()
.clickSamlLink_goToHomePage();
}

@Test
public void testGroupIntegration() throws Exception {
createIdentityProvider(SAML_ORIGIN);
LoginPage.go(webDriver, baseUrl)
.startSamlLogin()
.login(MARISSA4_USERNAME, MARISSA4_PASSWORD);
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(MARISSA4_USERNAME, MARISSA4_PASSWORD);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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() {
public SamlLoginPage clickSamlLink_goToSamlLoginPage() {
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() {
public HomePage clickSamlLink_goToHomePage() {
clickFirstSamlLoginLink();
return new HomePage(driver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Page {
protected WebDriver driver;
Expand All @@ -11,12 +10,7 @@ public Page(WebDriver driver) {
this.driver = driver;
}

public LoginPage begin(String baseUrl) {
driver.get(baseUrl + "/login");
return new LoginPage(driver);
}

public LoginPage logout() {
public LoginPage logout_goToLoginPage() {
clickLogout();
return new LoginPage(driver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public SamlLoginPage(WebDriver driver) {
assertThat("Should be on the SAML login page", driver.getCurrentUrl(), containsString("/module.php/core/loginuserpass"));
}

public HomePage login(String username, String password) {
public HomePage login_goToHomePage(String username, String password) {
final WebElement usernameElement = driver.findElement(By.name("username"));
usernameElement.clear();
usernameElement.sendKeys(username);
Expand Down

0 comments on commit a9b9f15

Please sign in to comment.