Allure Framework:无法在 TestNG 和 Maven 已经启用 AspectJ 的情况下使用 @Step 、@Parameter 和 @Attachments 注释
Allure Framework: unable to use @Step , @Parameter and @Attachments annotation with TestNG and Maven already AspectJ enabled
我正在尝试使用 @Step 、@Parameter 和 @Attachments 参数,但它们没有显示在报告中,@Title 和 @Feature 工作正常。
我的 pom.xml:
<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>NewLookSmoke</groupId>
<artifactId>NewLookSmoke</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>NewLookSmoke</name>
<description>Smoke Test Suite for NewLook</description>
<properties>
<aspectj.version>1.8.5</aspectj.version>
<allure.version>1.4.11</allure.version>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-testng-adaptor</artifactId>
<version>${allure.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}\org\aspectj\aspectjweaver${aspectj.version}\aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>${allure.results.directory}</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</reporting>
下面是我的classtestng.xmlclass:
<?xml version="1.0" encoding="UTF-8"?>
<test name="RegisterNewUser Test; locale: EUR">
<parameter name="locale" value="EUR" />
<classes>
<class name="project.RegisterNewUser" />
</classes>
</test> <!-- Test -->
<test name="RegisterNewUser Test; locale: GBP">
<parameter name="locale" value="GBP" />
<classes>
<class name="project.RegisterNewUser" />
</classes>
</test> <!-- Test -->
我的Java代码:
@Features("Register User")
public class RegisterNewUser 扩展 OpenAndCloseBrowser {
String baseURL;
String locale;
HomePage hp;
CLPPage clp;
CartPage cp;
ActionDriver ad;
HomePageElements hpe;
List<WebElement> we;
List<String> str_lst;
String str;
JavascriptExecutor jse;
boolean flag;
String locale_text;
Actions act;
PLPPage plp;
PDPPage pdp;
PickAPathPage pap;
List<String> prop;
@Parameter("Sign in successful: ")
private String flg2;
byte[] flg;
boolean flag1;
@Parameters({"locale"})
@BeforeMethod
public void init(String locale) {
//this.baseURL = baseURL;
this.locale = locale;
ad = new ActionDriver(wd);
prop = ad.loadProperties(locale);
this.baseURL = prop.get(1);
//this.CnCThreshold = CnCThreshold;
hp = new HomePage(wd);
clp = new CLPPage(wd);
hpe = new HomePageElements();
plp = new PLPPage(wd);
pdp = new PDPPage(wd);
cp = new CartPage(wd);
pap = new PickAPathPage(wd);
act = new Actions(wd);
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
flg2 = "";
/*
* FluentWait<WebDriver> wait = new FluentWait<WebDriver>(wd)
* .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(100,
* TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class);
*/
}
@Attachment("Sign in successful: ")
public byte[] signInStatus(){
return (flag1 + "").getBytes();
}
@Parameter("Test Parameter")
private String test;
@Title("Register user steps")
@Test(priority = 1)
public void test_SF_188to193() {
System.out.println("****************test_SF_188to193***************");
// HomePage Verification using value omniture variable "s.pageName"
flag1 = hp.registerUser();
flg = signInStatus();
flg2 = flag1 + "";
System.out.println(flg2);
System.out.println(flg);
test = " Passed";
Assert.assertTrue(flag1, "Unable to register User");
}
我已经彻底搜索过,包括 Allure 官方网站上的文档,但我无法找到解决方法。
当您 运行 直接使用 IDE 进行测试时,不会应用 pom.xml
中的 AspectJ 配置。因此,您需要将其指定为您的构建配置作为额外的 VM 选项。
我正在尝试使用 @Step 、@Parameter 和 @Attachments 参数,但它们没有显示在报告中,@Title 和 @Feature 工作正常。 我的 pom.xml:
<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>NewLookSmoke</groupId>
<artifactId>NewLookSmoke</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>NewLookSmoke</name>
<description>Smoke Test Suite for NewLook</description>
<properties>
<aspectj.version>1.8.5</aspectj.version>
<allure.version>1.4.11</allure.version>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-testng-adaptor</artifactId>
<version>${allure.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}\org\aspectj\aspectjweaver${aspectj.version}\aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>${allure.results.directory}</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</reporting>
下面是我的classtestng.xmlclass:
<?xml version="1.0" encoding="UTF-8"?>
<test name="RegisterNewUser Test; locale: EUR">
<parameter name="locale" value="EUR" />
<classes>
<class name="project.RegisterNewUser" />
</classes>
</test> <!-- Test -->
<test name="RegisterNewUser Test; locale: GBP">
<parameter name="locale" value="GBP" />
<classes>
<class name="project.RegisterNewUser" />
</classes>
</test> <!-- Test -->
我的Java代码:
@Features("Register User")
public class RegisterNewUser 扩展 OpenAndCloseBrowser {
String baseURL;
String locale;
HomePage hp;
CLPPage clp;
CartPage cp;
ActionDriver ad;
HomePageElements hpe;
List<WebElement> we;
List<String> str_lst;
String str;
JavascriptExecutor jse;
boolean flag;
String locale_text;
Actions act;
PLPPage plp;
PDPPage pdp;
PickAPathPage pap;
List<String> prop;
@Parameter("Sign in successful: ")
private String flg2;
byte[] flg;
boolean flag1;
@Parameters({"locale"})
@BeforeMethod
public void init(String locale) {
//this.baseURL = baseURL;
this.locale = locale;
ad = new ActionDriver(wd);
prop = ad.loadProperties(locale);
this.baseURL = prop.get(1);
//this.CnCThreshold = CnCThreshold;
hp = new HomePage(wd);
clp = new CLPPage(wd);
hpe = new HomePageElements();
plp = new PLPPage(wd);
pdp = new PDPPage(wd);
cp = new CartPage(wd);
pap = new PickAPathPage(wd);
act = new Actions(wd);
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
flg2 = "";
/*
* FluentWait<WebDriver> wait = new FluentWait<WebDriver>(wd)
* .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(100,
* TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class);
*/
}
@Attachment("Sign in successful: ")
public byte[] signInStatus(){
return (flag1 + "").getBytes();
}
@Parameter("Test Parameter")
private String test;
@Title("Register user steps")
@Test(priority = 1)
public void test_SF_188to193() {
System.out.println("****************test_SF_188to193***************");
// HomePage Verification using value omniture variable "s.pageName"
flag1 = hp.registerUser();
flg = signInStatus();
flg2 = flag1 + "";
System.out.println(flg2);
System.out.println(flg);
test = " Passed";
Assert.assertTrue(flag1, "Unable to register User");
}
我已经彻底搜索过,包括 Allure 官方网站上的文档,但我无法找到解决方法。
当您 运行 直接使用 IDE 进行测试时,不会应用 pom.xml
中的 AspectJ 配置。因此,您需要将其指定为您的构建配置作为额外的 VM 选项。