获取连接到诱惑报告的控制台输出屏幕截图-selenium webdriver、testng、maven

获取连接到诱惑报告的控制台输出屏幕截图-selenium webdriver、testng、maven,maven,selenium,allure,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:/

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

以下是我的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>

4.0.0
com.testproject
它显示状态通过/失败/中断以及运行测试所花费的时间。但控制台输出并没有附加到它。此外,失败测试用例的屏幕截图存储在文件夹surefire reports/screenshots中。我也需要附上它们来吸引报告。有人能帮我知道我需要添加什么来获得这个输出吗


谢谢

我假设您正在使用TestNG listener获取失败屏幕截图,并且您可以访问TestNG listener。否则,请参见如何通过重写TestListenerAdapter来创建TestNG侦听器()

  • 看起来您可以创建一个如下的方法来保存屏幕截图

    @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);
    }
    
  • 要获取要报告的控制台输出,请创建以下方法

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

  • 我假设您正在使用TestNG listener获取故障屏幕截图,并且您可以访问TestNG listener。否则,请参见如何通过重写TestListenerAdapter来创建TestNG侦听器()

  • 看起来您可以创建一个如下的方法来保存屏幕截图

    @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);
    }
    
  • 要获取要报告的控制台输出,请创建以下方法

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

  • 如果您不打算在问题中添加足够的细节,说明您所做的工作(您需要共享代码片段,其他人可能会执行这些代码片段来模拟您遇到的问题)、您遇到的困难以及希望得到的帮助,你的问题很有可能被关闭。请使用上下文详细信息来帮助丰富您的问题。如果您不打算在您所做的事情方面为您的问题添加足够的详细信息(您需要共享代码片段,其他人可能会执行这些代码片段来模拟您遇到的问题)、您遇到的困难以及您希望得到的帮助,你的问题很有可能被关闭。请用上下文细节来丰富你的问题。