Media not found - Exception on attaching file - Relative path
ortoni opened this issue · 5 comments
Issue while attaching file into HTML reports
Exception occurred: java.io.IOException: Media was not found at [./a.jpg]
package reportsTest;
import java.io.IOException;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.MediaEntityBuilder;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
public class ReportsExt {
public static void main(String[] args) throws IOException {
ExtentHtmlReporter html = new ExtentHtmlReporter("./reportsFolder/reports.html");
ExtentReports extent = new ExtentReports();
extent.attachReporter(html);
ExtentTest test = extent.createTest("Attach ScreenShot");
// this does not through any error but snap is not attaching to reports.
test.pass("Passed",
MediaEntityBuilder.createScreenCaptureFromPath("./reportsFolder/a.jpg").build());
// This attach the file in HTML but throwing exception as media not found
test.pass("Passed", MediaEntityBuilder.createScreenCaptureFromPath("./a.jpg").build());
extent.flush();
}
}
Code from Media class, relative path is not working.
Instead of getPath, getAbsolutePath can be used.
if(getPath() != null) {
System.out.println("I am not null");
}
if(!new File(getPath()).exists()) {
System.out.println("File does not exist");
}else {
System.out.println("File exist");
}
if (getPath() != null && !new File(getPath()).exists()) {
throw new IOException("Media was not found at [" + getPath() + "]");
}
public static String getPath() {
return "./a.jpg";
}
This would only be thrown if the image is not available at the given path. Is a.jpg
available at reportsFolder
and the root folder of your project?
file path is available and also it getting attached in the html file, problem is even though its getting attached its throwing error.
Hmm, can you create a small snippet that I can use to reproduce?
Please check with version 4.0.1, this should now work as expected. I have disabled this check until I am able to reproduce and find the root cause.
In V 4.0.1 it got resolved. Thanks you.
Just another question how to append report.
In 3 we have,
ExtentHtmlReporter html =
new ExtentHtmlReporter("");
html.setAppendExisting(true);
but in V4 I couldn't find anything.