Снимок экрана не прикреплен к отчету Allure, запущенному с testNG - PullRequest
0 голосов
/ 08 ноября 2018

Я попробовал следующий код для прикрепления снимка экрана к отчету Allure, но ничего не работает.

@Attachment(value = "{0}", type = "image/png")
public byte[] makeScreenshotOnFailure(String fail, WebDriver driver) {
    return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
}

 public byte[] makeScreenshot(String path) throws IOException {
 Path content = Paths.get(path);
 try (InputStream is = Files.newInputStream(content)) {
 Allure.addAttachment("My attachment", is); }
return null;
 }

@Attachment(value = "{0}", type = "image/png")
public byte[] getScreenShot(String name, WebDriver driver)
{
    ru.yandex.qatools.ashot.Screenshot s = new AShot().takeScreenshot(driver);

    try
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ImageIO.write(s.getImage(), "png", stream);
        stream.flush();
        byte[] image = stream.toByteArray();
        stream.close();
        System.out.println("Get screen shot method");
        return image;
    }
    catch (IOException e)
    {
        e.printStackTrace();
        return null;
    }
}

Может ли кто-нибудь помочь мне в этом? Если возможно, поделитесь примером кода.

1 Ответ

0 голосов
/ 08 ноября 2018

Вы можете попробовать эту опцию:

@Attachment(type = "image/png")
public byte[] takeScreenshot() {
System.out.println("taking screenshot");
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

Если это не работает, добавьте больше информации о вашем pom.xml и зависимостях.

пом зависимости:

    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-maven</artifactId>
        <version>${allure-maven.version}</version>
        <scope>compile</scope>
    </dependency>
    <!--        https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>${allure-testng.version}</version>
        <scope>compile</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-junit4 -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-junit4</artifactId>
        <version>${allure-junit4.version}</version>
        <scope>compile</scope>
    </dependency>

Я использую testNG, но мне нужно добавить зависимость Junit4.

...