首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Maven/ TestNg找不到allure @step注解

Maven/ TestNg找不到allure @step注解
EN

Stack Overflow用户
提问于 2018-06-07 02:14:42
回答 3查看 1.8K关注 0票数 0

在我的maven项目(tetsng,java)中实现@Step注解时遇到了问题。

(更新)共享pom文件:

代码语言:javascript
复制
eproject 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>src</groupId>
<artifactId>AutomationTestSuit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>

     <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.14.2</version>
         <scope>test</scope>
     </dependency>

    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.6.0</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

</dependencies>



<build>
    <resources>
        <resource>
            <directory>src\main\resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <testResources>
        <testResource>
            <directory>src\test\resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>


    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>

            <configuration>
                <suiteXmlFiles>
                    <file>${project.basedir}/suites/smoke.xml</file>
                </suiteXmlFiles>

                <systemPropertyVariables>
                    <environment.properties>/environment.properties</environment.properties>
                </systemPropertyVariables>

                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar"
                </argLine>
            </configuration>

            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>1.9.1</version>
                </dependency>
            </dependencies>
        </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>e

我试图将步骤注释添加到页面类中,但失败了:

代码语言:javascript
复制
package com.pages.login_page;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;


public class LoginPageElements {

private WebDriver driver;


@FindBy(how = How.ID, using = "test")
private WebElement logonID;

@FindBy(how = How.ID, using = "test")
private WebElement logonPassword;

@FindBy(how = How.ID, using = "test")
private WebElement logonSubmit;


public LoginPageElements(WebDriver driver)
{
    this.driver = driver;
    PageFactory.initElements(driver,this);
}

@Step("login step") //step is underlined on this place with can't resolve symbol Step error

public void Login_as(String sUsername, String sPassword) {
        logonID.sendKeys(sUsername);
        logonPassword.sendKeys(sPassword);
        logonSubmit.click();
}

@Step error example

在MytestListener类中实现@Attachments时,我遇到了同样的问题:

see the screenshot

请帮我弄清楚这个问题。

EN

回答 3

Stack Overflow用户

发布于 2018-06-07 15:47:07

我注意到您使用的是过时版本的Allure。这是正确的导入

代码语言:javascript
复制
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-testng</artifactId>
    <version>2.6.0</version>
</dependency>

使用Allure2,您不需要配置侦听器,而是需要配置AspectJ。在这里您可以找到Maven +TestNG的示例:https://docs.qameta.io/allure/#_testng

票数 0
EN

Stack Overflow用户

发布于 2018-06-12 04:05:24

问题出在idea社区版本上。它似乎不支持aspectj插件。如果有人正在为同样的问题而挣扎,请看一下:https://www.jetbrains.com/help/idea/java-compiler.html

票数 0
EN

Stack Overflow用户

发布于 2020-04-14 20:20:06

在我的案例中,问题出在<scope>test</scope>上。我把它从依赖项中删除了:

代码语言:javascript
复制
 <dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-testng</artifactId>
    <version>LAST_VERSION</version>
    <scope>test</scope>
</dependency>

并且@Step注解开始被识别。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50727019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档