获取控制台输出附加到allure report- selenium webdriver,testng,maven的屏幕截图

时间:2017-09-26 11:17:12

标签: maven selenium allure

我正在使用诱惑报道。我的报告生成正确,但我的屏幕截图和控制台输出没有附加到报告。

这是我的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>com.testproject</groupId>
    <artifactId>tests</artifactId>
    <version>0.1-SNAPSHOT</version>
    <properties>
        <aspectj.version>1.8.10</aspectj.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.0-BETA14</version>
            <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.16</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.16</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</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.20</version>
                <configuration>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

请查找allure report附带的屏幕截图 它显示状态通过/失败/损坏以及运行测试所花费的时间。但控制台输出没有附加到它。失败的测试用例的屏幕截图也存储在surefire-reports / screenshots文件夹中。我也需要将它们附加到诱惑报告中。有人可以帮忙知道我需要添加什么来获得此输出吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

我假设您使用TestNG侦听器获取失败屏幕截图,并且您可以访问testNG侦听器。否则,请查看如何通过覆盖TestListenerAdapter来创建TestNG侦听器(http://testng.org/doc/documentation-main.html#listeners-testng-xml)。

  1. 您似乎可以创建以下方法来保存屏幕截图

    {
      "channel": {
        "id": 301726,
        "name": "Testing ESP8266",
        "description": "Water meter pulse count",
        "latitude": "0.0",
        "longitude": "0.0",
        "field1": "Water Pulse",
        "created_at": "2017-07-12T12:19:38Z",
        "updated_at": "2017-09-26T08:41:17Z",
        "elevation": "54",
        "last_entry_id": 151
      },
      "feeds": [
        {
          "created_at": "2017-08-15T13:14:28Z",
          "entry_id": 52,
          "field1": "13.00\r\n\r\n"
        },
        {
          "created_at": "2017-08-15T13:14:44Z",
          "entry_id": 53,
          "field1": "13.00\r\n\r\n"
        },
        {
          "created_at": "2017-08-15T13:14:59Z",
          "entry_id": 54,
          "field1": "13.00\r\n\r\n"
        }
      ]
    }
    

    然后,您可以在testNG侦听器中调用此方法,该侦听器用于在测试失败时截取屏幕截图。

    @Attachment(value = "Page screenshot", type = "image/png")
    public byte[] saveScreenshot() {
        // Use selenium screenshot code to take screenshot and convert into     byte[]
        return byte[];
    }
    
  2. 要使控制台输出报告,请创建以下方法

    @Override
    public void onTestFailure(ITestResult testResult) {
        saveScreenshot();
        super.onTestFailure(testResult);
    }
    

    在testNG侦听器中调用onTest(成功,失败,跳过)和onConfiguration(成功,失败,跳过)方法

    @Attachment
    public String logOutput(List<String> outputList) {
        String output = ""; 
        for (String o : outputList) 
            output += o + "<br/>"; 
        return output
    }
    
  3. https://github.com/allure-framework/allure1/wiki/Attachments