首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为Selenium设置Allure报表

为Selenium设置Allure报表
EN

Stack Overflow用户
提问于 2016-12-16 19:19:22
回答 1查看 8.8K关注 0票数 1

我正在尝试为我的Selenium框架实现Allure报告。它不使用任何像TestNGJUnit这样的测试框架。基本上,我不需要TestNG或Junit,因为我处理整个框架,从excel表格中获取数据。

目前,我正在使用Java反射执行所有的测试步骤。测试步骤基本上是简单的java方法。我在一个类中定义了它们-为每个测试用例逐个执行它们。

示例:

代码语言:javascript
复制
[TC_0001, login, createUser, ModifyUser, deletUser]
          [TC_0002, createUser]

通过逐个执行每个测试步骤来执行每个测试用例- TC_0001。

TestCase Id - TC_0001步骤1- createUser步骤2- modifyUser步骤3- deletUser

我已经在一个java类中定义了这些方法,并计划为Allure报表添加@Step注释。想知道这是不是可能。

示例

代码语言:javascript
复制
   @Step
    public void login(String username, String password) {
        //TestSetup.test.log(LogStatus.INFO, "This step shows the Login Function");
        Log.info("Executing the Login method");
    }

...

看着Allure文档和报告示例,我有兴趣在我的测试报告框架中实现它。

然而,我不能这样做。有没有什么方法可以在没有TestNG或Junit适配器的情况下实现这一点?请参考下面我的pom.xml

代码语言:javascript
复制
<?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>

    <parent>
        <groupId>io.qameta</groupId>
        <artifactId>opensource-parent</artifactId>
        <version>1.3</version>
    </parent>

    <artifactId>allure-junit-example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <allure.version>1.4.23.HOTFIX1</allure.version>
        <aspectj.version>1.8.9</aspectj.version>
        <compiler.version>1.7</compiler.version>
    </properties>

    <name>Allure JUnit Example</name>
    <description>Allure JUnit and WebDriver Usage Example</description>

    <dependencies>
    <!--  Allure Junit Adaptor -->
        <dependency>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-junit-adaptor</artifactId>
            <version>${allure.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8-beta4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.10-FINAL</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>ru.yandex.qatools.allure.junit.AllureRunListener</value>
                        </property>
                    </properties>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

            <!--Needed only to show reports locally. Run jetty:run and
            open localhost:8080 to show the report-->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.10.v20150310</version>
                <configuration>
                    <webAppSourceDirectory>${project.build.directory}/site/allure-maven-plugin</webAppSourceDirectory>
                    <stopKey>stop</stopKey>
                    <stopPort>1234</stopPort>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- Allure Reporting -->
    <reporting>
        <excludeDefaults>true</excludeDefaults>
        <plugins>
            <plugin>
                <groupId>ru.yandex.qatools.allure</groupId>
                <artifactId>allure-maven-plugin</artifactId>
                <version>2.5</version>
            </plugin>
        </plugins>
    </reporting>

</project>

我执行了Maven clean install site jetty:运行,但无法获得报告。我确信我错过了很多东西,在这些方面的任何帮助我都很感激。

EN

回答 1

Stack Overflow用户

发布于 2016-12-31 23:50:15

简而言之,不是。

Allure报告框架将与开发人员定义了适配器的任何测试框架一起工作,适配器是附加到特定测试框架并知道如何将测试信息提取到XML的小型库。

有关如何使用任何可用的框架设置测试的更多信息,请访问- https://github.com/allure-framework/allure1/wiki

就您的单元而言,您似乎使用了没有版本的pom.xml -junit-adaptor,即${allure.version}。在没有版本的情况下,您希望如何解决依赖关系?

在你的例子中,有一个@Step注解,它肯定来自于TestNg,但是如果没有@ TEST,或者没有任何指定方法是测试的东西,jUnit将不能生成报告,因为它将不能断言哪些方法将测试信息提取到XML.

一旦你实现了适当的适配器,你可以做- mvn干净的测试站点,当测试运行完成后,只需转到你项目中的站点目录,在这个目录中打开以你实现的适配器命名的文件夹,在这里你会找到index.html,在浏览器中打开它,你将能够看到带有结果的报告,而不需要运行jetty。

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

https://stackoverflow.com/questions/41183268

复制
相关文章

相似问题

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