Merge pull request #2398 from vramik/master-KEYCLOAK-2690

KEYCLOAK-2690 - create page source file when test fails
This commit is contained in:
Stian Thorgersen 2016-03-21 15:26:30 +01:00
commit ca67e8a764
3 changed files with 23 additions and 2 deletions

View file

@ -36,7 +36,7 @@ import org.openqa.selenium.WebDriver;
public abstract class AbstractPage {
protected final Logger log = Logger.getLogger(this.getClass());
private final Map<String, Object> uriParameters = new HashMap<>();
@Drone

View file

@ -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");

View file

@ -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());
}
}
}