From d0f53e92a7eebc50c66a6297a4f6fc36f075531e Mon Sep 17 00:00:00 2001 From: Danny Faught Date: Fri, 22 Sep 2023 12:44:17 -0700 Subject: [PATCH] refactor: use page objects for favicon test * 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. --- .../uaa/integration/feature/SamlLoginIT.java | 8 +++++-- .../pageObjects/FaviconElement.java | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/pageObjects/FaviconElement.java diff --git a/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/feature/SamlLoginIT.java b/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/feature/SamlLoginIT.java index 38128136799..057b17a9c8e 100644 --- a/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/feature/SamlLoginIT.java +++ b/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/feature/SamlLoginIT.java @@ -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; @@ -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); } diff --git a/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/pageObjects/FaviconElement.java b/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/pageObjects/FaviconElement.java new file mode 100644 index 00000000000..944b1345bbc --- /dev/null +++ b/uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/pageObjects/FaviconElement.java @@ -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.")); + } +} \ No newline at end of file