On the ExtentReports automated test report

  During our test automation, often require a corresponding test reports, such as junit, testng, reportng and so on, there will be built-in test reports, why I want to mention ExtentReports here? First of all, let's look at other several test report is what it looks like

     1.junit

  

  2.testng

  

  3.reportng

  

   The report comes less attractive, poor readability, this report estimated that no one wants to go out and see, of course, we are talking about more than just a few reports, if you want to get a very beautiful reports can only do it yourself, this You must have good coding skills. Fischer did not talk much to say that we look at today talk about ExtentReports, first on the map

                              Figure I

 

Figure II

Figure III

  What ExtentReports exactly? Let's see, official address: http: //extentreports.relevantcodes.com/,ExtentReports is based on the creation of a Anshoo Arora HTML5 report, which provides a Java and .NET class libraries, very easy to use and create a beautiful automated test report. Both show details Test Test Summary step (status, error, etc.) can also provide analysis Dashbord, these pages using the Tab tags separated easily and quickly switch the link to see the advantages. I use here is the 2.41.1 version, but the report shows is 2.41.0, the empty look back, does not affect this project. Go to the official website to download extentreports-java-v2.41.1.jar

  We create a maven project, added in pom.xml

  <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
  <dependency>
  <groupId>com.aventstack</groupId>
  <artifactId>extentreports</artifactId>
  <version>2.41.1</version>
  </dependency>

  1.初始化一些ExtentReports,其中配置了报告的生成路径,以及一些其他一些信息,这里为了在监听中调用extent我在这里写了一个get方法

  2.重写testng监听

  

  上面是把extentreports的报告的初始方法写在driver的初始方法中,写报告的方法在testng的 onTest中,这次将这些方法全都拆出来,写在一个方法类中,这个类重现实现了testng IReporter接口中的 generateReport 方法同时加入了失败自动截图方法。

  1.首先说一下自动截图方法的实现(截图实现类):

  2.为了在testng 的监听中调用截图方法,所以封装了一个BaseTestcase类 。

  3.实现extentreports生成的监听类ExtentReporterNGListener

  4.testng.xml 文件配置:

  下面我们再说一下extent的一个服务 extentX,这是一个web程序,可以读取数据库(mongodb、redis)中的数据,来生成报告,只要我们把测试的数据都存储在数据库中,就会看到一个很完美的集合报告,先下载安装node.js和mongodb,然后安装两个软件,node.js安装比较简单,这边就不介绍了,我们来看下安装mongodb,下载mongodb安装文件,安装完成后,在根目录下新建db文件夹,用来存放mongodb的数据库文件,执行以下命令(D:\Program Files\MongoDB\Server\3.2\bin>mongod -dbpath "D:\Program Files\MongoDB\db"),启动mongodb。你也可以在浏览器中查看mongodb是否启动。

 

下面我们来安装extentX,下载地址:https://github.com/anshooarora/extentx,下载完成后解压,先进入connections.js,修改以下内容

extent: {
  adapter: 'sails-mongo',
  host: 'localhost', // host where MongoDB is running
  port: 27017, // port where MongoDB is running
  database: 'extent'
}

命令行进入到extentx根目录,执行以下命令:npm install,安装进程比较慢,慢慢等。

以上操作都完成后我们直接运行testng.xml,下面是eclipse控制台显示的内容和cmd命令行显示的内容

数据库中如下图所示

 

注:参考文章地址:http://www.cnblogs.com/llining/p/5669981.html,作者:笑笑唔莱

Guess you like

Origin www.cnblogs.com/mrjade/p/6237721.html