io.qameta.allure
allure-testng
2.16.0
import io.qameta.allure.Allure;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
public class MyTest {
public void myTestMethod() {
// some test code here ...
// Take screenshot and save to folder
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
Allure.addAttachment("screenshot", new ByteArrayInputStream(screenshot));
}
}
需要注意的是,使用Allure API自动将截图保存到Allure报告的默认文件夹中。如果要将截图保存到指定文件夹中,可以使用“addAttachment”方法的第二个参数指定文件名和路径,如下所示:
Allure.addAttachment("screenshot", new FileInputStream("path/to/folder/screenshot.png"));