我尝试过的是,
final String Screenshot =((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
SCENARIO.attach(Screenshot,"image/png","BASE64");
或
SCENARIO.attach(Screenshot,"image/png:base64","Test 1");
详情:
io.cucumber - 6.9.1
Report - net.masterthought cucumber-reporting -5.6.1
Language -- Java
要将屏幕截图附加为 Base 64 图像,您需要将其捕获为
byte[]
而不是 String
@AfterStep
public void takeScreenShotAfterStep(Scenario scenario) throws IOException {
if (scenario.isFailed()) {
final byte[] screenShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenShot, "image/jpg", scenario.getName());
}
}
它对我有用,如下所示
public static void screenshotinBASE64() {
String getscreenshot = ((TakesScreenshot) BasePage.getDriver()).getScreenshotAs(OutputType.BASE64);
lstScreenshotsInBase64.add(getscreenshot);
}
然后
@After
public void afterScenario(Scenario scenario) throws IOException, InterruptedException {
if (lstScreenshotsInBase64 == null || lstScreenshotsInBase64.size() == 0) {
}else{
for(int i =0;i < lstScreenshotsInBase64.size();i++) {
scenario.write("<img src=\"data:image/png;base64,"+lstScreenshotsInBase64.get(i)+"\"/>");"image/png");
}
}}