Скриншоты не отображаются в Allure Reports (Maven + Junit 5) - PullRequest
0 голосов
/ 27 января 2020

После запуска mvn test и allure serve allure-results отчет генерируется, но скриншоты не отображаются.

Вот мой pom. xml

<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>de.friday.hello</groupId>
    <artifactId>sales-funnel</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sales-funnel</name>

    <properties>
        <maven.compiler.target>8</maven.compiler.target>
        <maven.compiler.source>8</maven.compiler.source>
        <junit.jupiter.version>5.6.0</junit.jupiter.version>
        <runSuite>**/SalesFunnelTestSuite.class</runSuite>
        <allure-maven.version>2.10.0</allure-maven.version>
        <allure-junit5.version>2.13.1</allure-junit5.version>
        <aspectj.version>1.9.5</aspectj.version>



    </properties>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit5</artifactId>
            <version>${allure-junit5.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.0-alpha1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>${allure-maven.version}</version>
                <configuration>
                    <reportVersion>${allure-maven.version}</reportVersion>
                    <allureDownloadUrl>https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/${allure.version}/allure-commandline-${allure.version}.zip</allureDownloadUrl>
                </configuration>
            </plugin>


        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <outputName>salesFunnelReport</outputName>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>

Здесь это класс, который реализует TestWatcher

package listener;

import java.util.Optional;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

import core.DriverFactory;
import io.qameta.allure.Attachment;

public class AllureTestWatcher implements TestWatcher {

    // Screenshot attachment for Allure

//  @Attachment(value = "Page screenshot", type = "image/png")
//  public byte[] saveScreenshot(WebDriver driver) {
//      TakesScreenshot ss = (TakesScreenshot) DriverFactory.getDriver();
//      return ss.getScreenshotAs(OutputType.BYTES);
//  }


    @Attachment(value = "Page screenshot", type = "image/png")
    public byte[] saveScreenshot(byte[] screenShot) {
        return screenShot;
    }

    @Override
    public void testAborted(ExtensionContext arg0, Throwable arg1) {
        System.out.println("Test aborted");

    }

    @Override
    public void testDisabled(ExtensionContext arg0, Optional<String> arg1) {
        System.out.println("Test Disabled");

    }

    @Override
    public void testFailed(ExtensionContext arg0, Throwable arg1) {
        byte[] screenshot = ((TakesScreenshot) DriverFactory.getDriver()).getScreenshotAs(OutputType.BYTES);
        saveScreenshot(screenshot);
//      Allure.addAttachment("Screenshot", "image/png");
//      Path content = Paths.get("allure-results");
//      try (InputStream is = Files.newInputStream(content)) {
//          Allure.addAttachment("My attachment", is);
//      } catch (IOException e) {
//          e.printStackTrace();
//      } 

    }

    @Override
    public void testSuccessful(ExtensionContext arg0) {
        System.out.println("Test Sucessful");

    }

}

В папке allure-results есть файлы, которые создаются с -attachment в их именах, но без расширение.

файл вложения без расширения

Наконец, когда я запускаю отчет, снимок экрана не отображается:

отчет об очаровании без скриншота

...