-1

I am trying to save an extent report to my documents folder. I am getting an access is denied problem.

I have tried giving java full control, through all the user groups. I have given jetbrains full control as well but still access is denied.

This is where I am trying to save the file.

    public void beforeSuite() {
        extent = ExtentManager.createInstance("MobileCustomerCare_" + fileName + ".html");
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(System.getProperty("user.home") + "//Documents/ExtentReport//");

        extent.attachReporter(htmlReporter);

I have added the ExtentManager class where the instance gets created

public class ExtentManager {

    private static ExtentReports extent;
    private static String fileName = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date());


    static ExtentReports createInstance(String fileName) {
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
        htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setTheme(Theme.DARK);
        htmlReporter.config().setDocumentTitle(fileName);
        htmlReporter.config().setEncoding("utf-8");
        htmlReporter.config().setReportName(fileName);

        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);

        return extent;
    }
}

EDIT: I have now changed to use ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(System.getProperty("user.home") + "//Documents/ExtentReport//"); But still getting (access is denied)

I am expecting it to save the file in the location specified. What it's actually doing is saving it in my project.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
Tom Cockram
  • 217
  • 2
  • 16

2 Answers2

0

I think there is no path separator between the folder name and the file name, please try adding a path separator while creating ExtentHtmlReporter Object

ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("C:\\Users\\tom.cockram\\Documents\\ExtentReport\\");

Try not to keep spaces in the file name, it will help you in future

public static ExtentReports getInstance() {
    if (extent == null)
        createInstance("MobileCustomerCare_" + fileName + ".html");

        return extent;
    }

Avinash
  • 4,115
  • 2
  • 22
  • 41
-1

i had this problem when i was generating an XML file try this : ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("C://Users//tom.cockram//Documents//ExtentReport");

Mourad9
  • 5
  • 5