使用loggingSelenium如何生成多个html log文件
seleniumRC:使用loggingSelenium可以生成html log文件。每个html log文件生成的时候都需要将selenium start,然后 selenium stop。
有多个TestCase时,想让selenium只start stop一次,一个TestCase生成一个html log文件,
请问 有什么方法可以实现?
packagecom.selenium.demo;
importcom.thoughtworks.selenium.*;
importcom.unitedinternet.portal.selenium.utils.logging.*;
importjava.io.*;
importjava.io.BufferedWriter;
importorg.apache.commons.lang.*;
importjava.util.Date;
importjava.text.SimpleDateFormat;
publicclassLogTestextendsSeleneseTestCase{
LoggingSeleniumselenium;
BufferedWriterloggingWriter;
Stringurl="http://mail.zzy.cn";
// Date now=new Date();
// SimpleDateFormat fnow=new SimpleDateFormat("yyyy-MM-dd HH_mm_ss");
// final String resultPath = "E:\\selenium\\SRC\\testDemo";
finalStringerrorLog="E:\\selenium\\SRC\\testDemo\\errorLog";
finalStringresultHtmlFileName=errorLog+ File.separator+ LoggingUtils.timeStampForFileName()+"result.html";
finalStringresultEncoding="UTF-8";
//覆盖setUp方法
publicvoidsetUp()throwsException {
if(!newFile(errorLog).exists())
{
newFile(errorLog).mkdirs();
}
loggingWriter= LoggingUtils.createWriter(resultHtmlFileName,resultEncoding);
LoggingResultsFormatter htmlFormatter =
newHtmlResultFormatter(loggingWriter,resultEncoding);
htmlFormatter.setScreenShotBaseUri("/");// this is for linking to the screenshots
htmlFormatter.setAutomaticScreenshotPath(errorLog);
// wrap HttpCommandProcessor from remote-control
LoggingCommandProcessor myProcessor =
newLoggingCommandProcessor(newHttpCommandProcessor("localhost", 4444,"*iexplore",url), htmlFormatter);
selenium=newLoggingDefaultSelenium(myProcessor);
selenium.start();
}
//覆盖teardown方法(在这里没有特别的设置)
publicvoidtearDown()throwsException {
selenium.stop();
try{
if(null!=loggingWriter) {
loggingWriter.close();
}
}catch(IOException e) {
// do nothing
}
}
在tearDown中,将selenium stop注释掉时,没有生成正常的log文件,html log文件为空。
页:
[1]