Closed nreijmersdal closed 11 years ago
To analyse a flickering test I wrote a small log function to log the pageSource instead of fully implementing it in the framework. Lowering priority for now.
@Then("^I should not see the text \"([^\"]*)\"$")
public void I_should_not_see_the_text(String expectedText) throws Throwable {
String pageSource = getWebDriver().getPageSource();
if(pageSource.contains(expectedText)) {
log(pageSource);
fail("Found text I should not see: " + expectedText);
}
}
public void log(String text) {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_hhmmss");
String date = dateFormat.format( new Date() );
File file = new File("target/test-results/error_" + date + ".log");
try {
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.append(text);
output.close();
} catch (IOException e) {
}
}
We have SLF4J loggers using the log4j flavour available as well. Have a look at SeleniumManager how the private static Logger log is used.
Good idea.
Example of using the logger to log to a file: http://stackoverflow.com/questions/3967202/storing-log-into-log-file-using-slf4j-log4j We need to log to a file, because sometimes we want to zip and email the results, this is mainly if we use senbot as a monitoring tool in other cases the log can be viewed from the CI.