diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPage.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPage.java index 7af2375475..2e5836e501 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPage.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/page/AbstractPage.java @@ -36,7 +36,7 @@ import org.openqa.selenium.WebDriver; public abstract class AbstractPage { protected final Logger log = Logger.getLogger(this.getClass()); - + private final Map uriParameters = new HashMap<>(); @Drone diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java index 5c3a906798..a15cdb6687 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java @@ -59,6 +59,7 @@ import org.keycloak.testsuite.auth.page.login.OIDCLogin; import org.keycloak.testsuite.auth.page.login.UpdatePassword; import org.keycloak.testsuite.util.WaitUtils; import static org.keycloak.testsuite.admin.Users.setPasswordFor; +import org.keycloak.testsuite.util.TestEventsLogger; /** * @@ -119,6 +120,8 @@ public abstract class AbstractKeycloakTest { setDefaultPageUriParameters(); driverSettings(); + + TestEventsLogger.setDriver(driver); if (!suiteContext.isAdminPasswordUpdated()) { log.debug("updating admin password"); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/TestEventsLogger.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/TestEventsLogger.java index aa517904f6..23a8138f24 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/TestEventsLogger.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/TestEventsLogger.java @@ -14,13 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.keycloak.testsuite.util; +import java.io.File; +import java.io.IOException; +import org.apache.commons.io.FileUtils; import org.jboss.logging.Logger; import org.junit.runner.Description; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; +import org.openqa.selenium.WebDriver; /** * @@ -29,6 +32,13 @@ import org.junit.runner.notification.RunListener; */ public class TestEventsLogger extends RunListener { + + private static WebDriver driver; + + public static void setDriver(WebDriver driver) { + TestEventsLogger.driver = driver; + } + private Logger log(Description d) { return Logger.getLogger(d.getClassName()); } @@ -45,6 +55,7 @@ public class TestEventsLogger extends RunListener { @Override public void testFailure(Failure f) throws Exception { Description d = f.getDescription(); + createPageSrcFile(d); log(d).error(getMessage(d, "FAILED")); } @@ -58,4 +69,11 @@ public class TestEventsLogger extends RunListener { log(d).info(getMessage(d, "FINISHED\n\n")); } + private void createPageSrcFile(Description d) throws IOException { + if (driver != null && driver.getPageSource() != null) { + String pageSourceLocation = System.getProperty("page.source.location", "target/failed-tests/page-source/"); + FileUtils.writeStringToFile(new File(pageSourceLocation + d.getTestClass().getSimpleName() + "/" + d.getMethodName() + ".html"), + driver.getPageSource()); + } + } }