51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2875|回复: 0

使用loggingSelenium如何生成多个html log文件

[复制链接]

该用户从未签到

发表于 2012-8-29 09:35:56 | 显示全部楼层 |阅读模式
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 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-3-29 09:53 , Processed in 0.074019 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表