Reputation: 121
In selenium I am auto mailing the extent reports through javamail API. I am using base 64 encoder to generate screenshots and attach to the report. The issue is the screenshot is visible as thumbnail but when i zoom it, it displays the encoded image.enter image description here
String scnShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
String s="data:image/png;base64,"+scnShot;
test.log(LogStatus.INFO,test.addScreenCapture(s));
Upvotes: 3
Views: 4962
Reputation: 1026
the error is coming because of below code. you are using test.addScreencapture
which expects screencapture file path as parameter and you are passing base64 string.
test.log(LogStatus.INFO,test.addScreenCapture(s));
To pass base64string in the extent log just use below code
test.info("your message "+ s)
where s is your base64 string
Upvotes: 0
Reputation: 49
I have done this in selenium C#, you can modify to use this in Java:
You just need to convert the image to Base64 image and use Media entity builder.
Screenshot file = ((ITakesScreenshot)driver).GetScreenshot();
string image = file.AsBase64EncodedString;
exTest.Pass(msg, MediaEntityBuilder.CreateScreenCaptureFromBase64String(image).Build());
System.Diagnostics.Trace.WriteLine("PASS >>>> " + msg);
Upvotes: 0
Reputation: 401
If you are using ExtentTest then this function would defienietly works, You can add screenshot with description...
public void LOGWithScreenshot(ExtentTest logger, String status, String TestDescription) throws IOException, InvalidFormatException {
String Base64StringofScreenshot="";
File src = ((TakesScreenshot) driverThread).getScreenshotAs(OutputType.FILE);
byte[] fileContent = FileUtils.readFileToByteArray(src);
Base64StringofScreenshot = "data:image/png;base64,"+Base64.getEncoder().encodeToString(fileContent);
if(status.equalsIgnoreCase("pass"))
logger.log(LogStatus.PASS, TestDescription+"\n"+logger.addBase64ScreenShot(Base64StringofScreenshot));
else
logger.log(LogStatus.FAIL, TestDescription+"\n"+logger.addBase64ScreenShot(Base64StringofScreenshot));
}
Upvotes: 2
Reputation: 480
From extent_reports GIT - you can check here
Base64 images are currently not supported in this version due to issues they have caused on the previous versions and ....
Upvotes: 0