I tried of following code for attaching screen shot to Allure report and nothing works.
@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;
}
}
Can anyone help me in this? If possible please share the sample code.
You can try this option:
@Attachment(type = "image/png")
public byte[] takeScreenshot() {
System.out.println("taking screenshot");
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
If it doesn't work add more information about your pom.xml and the dependencies.
pom dependencies:
<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>
I use testNG but I have to add the Junit4 dependency.
If you are using Maven, maybe the problem is related to -javaagent . for features like attachment and steps you have to specify -javaagent . you can find more explanation in this answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.