Merge pull request #2398 from vramik/master-KEYCLOAK-2690
KEYCLOAK-2690 - create page source file when test fails
This commit is contained in:
commit
ca67e8a764
3 changed files with 23 additions and 2 deletions
|
@ -36,7 +36,7 @@ import org.openqa.selenium.WebDriver;
|
||||||
public abstract class AbstractPage {
|
public abstract class AbstractPage {
|
||||||
|
|
||||||
protected final Logger log = Logger.getLogger(this.getClass());
|
protected final Logger log = Logger.getLogger(this.getClass());
|
||||||
|
|
||||||
private final Map<String, Object> uriParameters = new HashMap<>();
|
private final Map<String, Object> uriParameters = new HashMap<>();
|
||||||
|
|
||||||
@Drone
|
@Drone
|
||||||
|
|
|
@ -59,6 +59,7 @@ import org.keycloak.testsuite.auth.page.login.OIDCLogin;
|
||||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||||
import org.keycloak.testsuite.util.WaitUtils;
|
import org.keycloak.testsuite.util.WaitUtils;
|
||||||
import static org.keycloak.testsuite.admin.Users.setPasswordFor;
|
import static org.keycloak.testsuite.admin.Users.setPasswordFor;
|
||||||
|
import org.keycloak.testsuite.util.TestEventsLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -119,6 +120,8 @@ public abstract class AbstractKeycloakTest {
|
||||||
setDefaultPageUriParameters();
|
setDefaultPageUriParameters();
|
||||||
|
|
||||||
driverSettings();
|
driverSettings();
|
||||||
|
|
||||||
|
TestEventsLogger.setDriver(driver);
|
||||||
|
|
||||||
if (!suiteContext.isAdminPasswordUpdated()) {
|
if (!suiteContext.isAdminPasswordUpdated()) {
|
||||||
log.debug("updating admin password");
|
log.debug("updating admin password");
|
||||||
|
|
|
@ -14,13 +14,16 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.keycloak.testsuite.util;
|
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.jboss.logging.Logger;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
import org.junit.runner.notification.Failure;
|
import org.junit.runner.notification.Failure;
|
||||||
import org.junit.runner.notification.RunListener;
|
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 {
|
public class TestEventsLogger extends RunListener {
|
||||||
|
|
||||||
|
|
||||||
|
private static WebDriver driver;
|
||||||
|
|
||||||
|
public static void setDriver(WebDriver driver) {
|
||||||
|
TestEventsLogger.driver = driver;
|
||||||
|
}
|
||||||
|
|
||||||
private Logger log(Description d) {
|
private Logger log(Description d) {
|
||||||
return Logger.getLogger(d.getClassName());
|
return Logger.getLogger(d.getClassName());
|
||||||
}
|
}
|
||||||
|
@ -45,6 +55,7 @@ public class TestEventsLogger extends RunListener {
|
||||||
@Override
|
@Override
|
||||||
public void testFailure(Failure f) throws Exception {
|
public void testFailure(Failure f) throws Exception {
|
||||||
Description d = f.getDescription();
|
Description d = f.getDescription();
|
||||||
|
createPageSrcFile(d);
|
||||||
log(d).error(getMessage(d, "FAILED"));
|
log(d).error(getMessage(d, "FAILED"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,4 +69,11 @@ public class TestEventsLogger extends RunListener {
|
||||||
log(d).info(getMessage(d, "FINISHED\n\n"));
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue