Allure2+Maven+Testng部署及使用详细教程
作者:互联网
AllureReport部署
前言:最近做自动化测试要用到AllureReport生成测试报告,网上逛了一下,发现有很多帖子,但是大家描述的都模棱两可,没有详细的步骤,因此编写此贴对部署方式进行记录;
一、Maven&Testng在eclipse中的安装部署不详述,百度比较丰富;
二、Allure的安装部署:
1、下载Allure,地址:https://bintray.com/qameta/generic/allure2
下载最新Allure版本的zip包,解压到本地如:D:\allure-2.6.0,在系统环境中添加ALLURE_HOME=D:\allure-2.6.0,并修改path在最后添加;%ALLURE_HOME%\bin
之后打开cmd命令窗口,输入allure --version,显示如下结果:
allure安装完成。
2、maven-testng-allure插件部署
在maven项目的pom.xml文件中添加如下内容
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ChromeTest</groupId>
<artifactId>ChromeTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
<webdriver.chrome>src/main/resources/chromedriver.exe</webdriver.chrome>
<aspectj.version>1.8.10</aspectj.version>
<allure.version>1.5.4</allure.version>
<!--<maven.surefire.plugin.version>2.20</maven.surefire.plugin.version>-->
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<!--allure的testng插件-->
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-testng-adaptor</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
</systemPropertyVariables>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
创建Testng class自动化测试代码:
public class FirstTest
{
String keyword="Hello World";
@Features("百度搜索")
@Stories("百度首页")
@Title("输入关键字")
@Test
@Step("输入内容")
@Description("测试百度搜索功能")
public void loginSalesForce() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://www.baidu.com/");
Thread.sleep(3000);
WebElement baidu = driver.findElement(By.id("kw"));
baidu.sendKeys("Allure Report");
baidu.sendKeys(Keys.RETURN);
}
}
保存后在工程目录对应的workspace下执行:mvn clean test命令,如下图所示:
maven test 通过后,输入:allure serve target/allure-results,回车后结果如下:
执行成功后自动打开浏览器,显示测试报告,如下图所示:
部署方法二:
此处只是pom.xml调用的依赖不一样,上一种方法在断言时没有找到更好方法
pom.xml内容
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ChromeTest</groupId>
<artifactId>ChromeTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<argLine>-Dfile.encoding=UTF-8</argLine>
<!--suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile-->
<webdriver.chrome>src/main/resources/chromedriver.exe</webdriver.chrome>
<aspectj.version>1.8.10</aspectj.version>
<allure.version>1.5.4</allure.version>
<!--<11maven.surefire.plugin.version>2.20</maven.surefire.plugin.version>-->
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.53.1</version>
</dependency>
<!--此处与之前方法引用的依赖不同,该依赖做断言更简便-->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.0-BETA19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
</systemPropertyVariables>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<!--重要配置:生成allure-result的目录-->
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>./target/allure-results</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Jenkins部署allurereport插件完成集成
1、安装Jenkins,默认安装推荐插件
2、安装Allure插件,如下图所示:
3、在“系统管理”->“全局工具配置”中配置jdk、Maven和Allure工具路径,如下图所示:
之后点击“保存”按钮进行保存。
标签:maven,Allure2,selenium,Testng,Maven,allure,org,testng,aspectj 来源: https://www.cnblogs.com/Bug-Hunter/p/14818426.html