【问题标题】:Get console output an screenshot attached to allure report- selenium webdriver, testng, maven获取控制台输出附加到魅力报告的屏幕截图-selenium webdriver、testng、maven
【发布时间】:2017-09-26 11:17:11
【问题描述】:

我正在使用魅力报告。我的报告生成正确,但我的屏幕截图和控制台输出未附加到报告中。

这是我的 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>

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

谢谢!!

【问题讨论】:

  • 如果您不打算就您所做的事情向您的问题添加足够的细节(您需要共享代码 sn-ps 可能由其他人执行以模拟问题你正在经历的),你被困在哪里以及你期待什么帮助,你的问题很有可能会被关闭。请通过上下文详细信息帮助丰富您的问题。

标签: maven selenium allure


【解决方案1】:

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

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

    @Attachment(value = "Page screenshot", type = "image/png")
    public byte[] saveScreenshot() {
        // Use selenium screenshot code to take screenshot and convert into     byte[]
        return byte[];
    }
    

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

    @Override
    public void onTestFailure(ITestResult testResult) {
        saveScreenshot();
        super.onTestFailure(testResult);
    }
    
  2. 为了让控制台输出报告,创建以下方法

    @Attachment
    public String logOutput(List<String> outputList) {
        String output = ""; 
        for (String o : outputList) 
            output += o + "<br/>"; 
        return output
    }
    

    在testNG监听器中调用onTest(success, failure, skip)和onConfiguration(success, failure, skip)方法

    @Override
    public void onTestSuccess(ITestResult testResult) {
        // Reporter.getOutput(testResult)will give the output logged in testng reporter
        logOutput(Reporter.getOutput(testResult));
        super.onTestSuccess(testResult);
    }
    

https://github.com/allure-framework/allure1/wiki/Attachments

【讨论】:

    猜你喜欢
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-16
    • 2020-05-31
    • 2015-06-16
    • 1970-01-01
    • 2019-03-11
    相关资源
    最近更新 更多