Skip to content

Commit

Permalink
refactor: use page objects for favicon test
Browse files Browse the repository at this point in the history
* The purpose of this test was difficult to understand until I removed the code that fixed the bug that this test is testing for.
* It should now be easier to understand why this test exists.
  • Loading branch information
swalchemist committed Sep 22, 2023
1 parent 177c93f commit d0f53e9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.cloudfoundry.identity.uaa.ServerRunning;
import org.cloudfoundry.identity.uaa.account.UserInfoResponse;
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
import org.cloudfoundry.identity.uaa.integration.pageObjects.FaviconElement;
import org.cloudfoundry.identity.uaa.integration.pageObjects.LoginPage;
import org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils;
import org.cloudfoundry.identity.uaa.integration.util.ScreenshotOnFail;
Expand Down Expand Up @@ -465,8 +466,11 @@ public void testGroupIntegration() throws Exception {

@Test
public void testFavicon_Should_Not_Save() throws Exception {
webDriver.get(baseUrl + "/favicon.ico");
testSimpleSamlLogin("/login", "Where to?", MARISSA4_USERNAME, MARISSA4_PASSWORD);
createIdentityProvider(SAML_ORIGIN);
FaviconElement.getDefaultIcon(webDriver, baseUrl);
LoginPage.go(webDriver, baseUrl)
.clickSamlLink_goToSamlLoginPage()
.login_goToHomePage(MARISSA4_USERNAME, MARISSA4_PASSWORD);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.cloudfoundry.identity.uaa.integration.pageObjects;

import org.hamcrest.Matchers;
import org.openqa.selenium.WebDriver;

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

public class FaviconElement extends Page {

// The favicon.ico URL is not present on the server because we specify a custom icon URL
// in the headers, but browsers try to hit it and tests need to hit this default URL.
static public FaviconElement getDefaultIcon(WebDriver driver, String baseUrl) {
driver.get(baseUrl + "/favicon.ico");
return new FaviconElement(driver);
}

// Expect a 404 error when landing on the favicon URL.
public FaviconElement(WebDriver driver) {
super(driver);
assertThat("Should be on the favicon image", driver.getCurrentUrl(), endsWith("/favicon.ico"));
assertThat(driver.getPageSource(), Matchers.containsString("Something went amiss."));
}
}

0 comments on commit d0f53e9

Please sign in to comment.