selenium-Excel report plug-in development

expected result:
1. The name of the case is the java class of the test case
2. If the test result is successful, it is displayed as: Passed and the background color is blue; if it is failed, it is displayed as Failed and the background color is red; if the test is abnormally interrupted, it is displayed as Skipped and the background color is yellow.
3. The complete log will record the log of the execution of this use case, whether it succeeds or fails. Click the log name to open it for viewing. Note that the log here is not uploaded in the form of an attachment but linked in the form of a hyperlink.
Come, it points to the log path locally or on the server.
4. Screenshots, only the failed use cases and the use cases that successfully captured the image will display the screenshot, click the image name to view the detailed screenshot, if no image is captured, this box will display "This use case has no screenshot"
Implementation principle
1. TestNG is developed, it can be used in an automated testing framework based on TestNG, it can collect test results and store them in excel
2. The IReporter class in TestNG is responsible for collecting test data and generating reports, and the TestListenerAdapter class is responsible for monitoring the test process of each test case
A class that counts test results and generates test reports,
You need to implement the IReporter interface and implement the method generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {}, (Write the specific code for generating the excel file in the body of this method, see: CreateExcelForResult .java.)
The listening test result class needs to inherit the TestListenerAdapter class and override the state of each stage of the test case you need, such as the following code: (TestResultListener.java.)
Implementation steps:
1。首先确保您的自动化框架pom.xml文件中有以下如下的pox,查看文件
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.2</version>
</dependency>
<dependency>
<artifactId>commons-configuration</artifactId>
<version>1.9</version>
</dependency>
2.本章节中已经打包好的excel测试报告插件的jar包:excelReporter.jar。将此jar包添加到你的项目path中
3.然后在testNg的配置文件中加入监听
<listeners>
<listenerclass-name="com.incito.excelReporter.TestResultListener"/>
<listenerclass-name="com.incito.excelReporter.ExcelReporter"/>
</listeners>
4.最后通过testNG的xml文件执行测试即可生成excel报告。
生成的报告存储于TestNG的报告目录(一般默认为test-output,可自定义)下的excelReports目录下,命名规则为:
“TestReport_yyyy-MM-dd_HH-mm-项目名称.xlsx”,如下图所示:
注意:如果你不想直接使用jar包,可以直接导入源码直接使用,源码请到网盘中获取:“excelReporter-src.zip”


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325763485&siteId=291194637
Recommended