【问题标题】:Setup Allure Report for Selenium为 Selenium 设置 Allure 报告
【发布时间】:2017-05-02 04:24:35
【问题描述】:

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

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

例子:

[TC_0001, login, createUser, ModifyUser, deletUser]
          [TC_0002, createUser]

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

测试用例 ID - TC_0001 第 1 步 - 创建用户 第 2 步 - 修改用户 第 3 步 - 删除用户

我已经在 java 类中定义了这些方法,并计划为 Allure Report 添加@Step 注解。想知道这是否可能。

例子

   @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

<?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 全新安装站点 jetty:run 但无法获取报告。我确信我遗漏了很多东西,感谢您对这些内容的任何帮助。

【问题讨论】:

    标签: java maven selenium allure


    【解决方案1】:

    总之NO.

    Allure Reporting 框架将与开发人员为其定义了适配器的任何测试框架一起使用,这是一个附加到特定测试框架并知道如何将测试信息提取到 XML 的小型库。

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

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

    在您的示例中,@Step 注释肯定来自 allure,但是在没有来自 TestNg 或 jUnit 的 @Test 或任何指定该方法是 TEST 的东西的情况下,Allure 将无法生成报告,因为它无法断言将测试信息提取到 XML 的方法。

    一旦你实现了合适的适配器,你可以做 - mvn clean test site,当测试运行完成时,只需进入你项目中的站点目录,在里面打开以你实现的适配器命名的文件夹,在这里您会找到 index.html,在浏览器中打开它,您将能够在不运行 jetty 的情况下看到带有结果的报告。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多