0

I am trying to access the har file from my project src folder and its not working. its not storing the file to the specified path. But when i try to save the file in local drive, i am able to store and get the values from the file.

     import java.io.*;
     import java.util.concurrent.TimeUnit;
     import java.util.concurrent.*;
     import java.lang.InterruptedException;
     import org.openqa.selenium.By;
     import org.openqa.selenium.WebDriver;
     import org.openqa.selenium.WebElement;
     import org.openqa.selenium.firefox.FirefoxDriver;
     import org.openqa.selenium.firefox.FirefoxProfile;

     import org.openqa.selenium.support.ui.Wait;
     import org.openqa.selenium.support.ui.WebDriverWait;

     public class Example  {
           public static void main(String[] args) {
           FirefoxProfile profile = new FirefoxProfile();

    File firebug = new File("firebug-1.10.0a11.xpi");
    File netExport = new File("netExport-0.8b22.xpi");

    try
    {
        profile.addExtension(firebug);
        profile.addExtension(netExport);
    }
    catch (IOException err)
    {
        System.out.println(err);
    }

    // Set default Firefox preferences
    profile.setPreference("app.update.enabled", false);

    String domain = "extensions.firebug.";

    // Set default Firebug preferences
    profile.setPreference(domain + "currentVersion", "2.0");
    profile.setPreference(domain + "allPagesActivation", "on");
    profile.setPreference(domain + "defaultPanelName", "net");
    profile.setPreference(domain + "net.enableSites", true);

    // Set default NetExport preferences
    profile.setPreference(domain + "netexport.alwaysEnableAutoExport", true);
    profile.setPreference(domain + "netexport.showPreview", false);
    profile.setPreference(domain + "netexport.defaultLogDir", "C:\\Downloads\\_har\\");

    WebDriver driver = new FirefoxDriver(profile);

    try
    {
        // Wait till Firebug is loaded
        Thread.sleep(5000);

        // Load test page
        driver.get("http://www.janodvarko.cz");

        // Wait till HAR is exported
        Thread.sleep(10000);
    }
    catch (InterruptedException err)
    {
        System.out.println(err);
    }

    driver.quit();
}

}

Instead of C:\Downloads\_har\ i need to have it in my src folder.

satheesh
  • 11
  • 4

1 Answers1

2
 path = File.join(File.join(Dir.pwd), 'new_har')
  if  Dir.exists? path
    FileUtils.rm_rf(path)
  end
  Dir.mkdir(path)
  profile['extensions.firebug.netexport.defaultLogDir'] = path.gsub('/', '\\')
  profile['update_preferences'] = true

You can use above code to save to your source folder.

The Rookie
  • 595
  • 9
  • 26