firebug / netexport

Firebug extension - export data from the Net panel
http://www.softwareishard.com/blog/netexport/
Other
35 stars 17 forks source link

Firebug 3.0.0-alpha.13 - "extensions.firebug.netexport.defaultFileName" not working #21

Closed thegreyfawkes closed 9 years ago

thegreyfawkes commented 9 years ago

Hello,

I have been following this previous thread (https://github.com/firebug/netexport/issues/9#issuecomment-95105384) in attempting to name an exported HAR file to my Selenium/Java script that was previously working with Firebug 2.x that I was using before. Per the suggestions from the linked page above, I updated to the newest Firebug (3.0.0-alpha.130), and updated my code to point to this XPI. Looking in "about:config", I cannot find the defaultFileName extension. I confirmed within the plugin list that it is indeed using the newest Firebug.

Furthermore, after changing my code to the XPI name of the newest Firebug, no longer captures the HAR files as it did before. There simply is no record of the HAR files in either the assigned directory in the code, nor any previously used folder.

As a java beginner, I am confused how such a little change would break my ability to download the HAR files.

For reference, here is my code. Please let me know if I'm just making a stupid mistake or if I have actually encountered a bug!

_____-

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.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.firefox.internal.ProfilesIni;

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

public class UsingBMP {
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir"));

    // auto-install FireBug and NetExport into Firefox profile
    File firebug = new File("firebug-3.0.0-alpha.13.xpi");
    File netExport = new File("netExport-0.9b7.xpi");

    FirefoxProfile profile = new FirefoxProfile();
    try {
        profile.addExtension(firebug);
        profile.addExtension(netExport);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Setting Firebug preferences
    profile.setPreference("extensions.firebug.currentVersion", "3.0.0-alpha.13");
    profile.setPreference("extensions.firebug.addonBarOpened", true);
    profile.setPreference("extensions.firebug.console.enableSites", true);
    profile.setPreference("extensions.firebug.script.enableSites", true);
    profile.setPreference("extensions.firebug.net.enableSites", true);
    profile.setPreference("extensions.firebug.previousPlacement", 1);
    profile.setPreference("extensions.firebug.allPagesActivation", "on");
    profile.setPreference("extensions.firebug.onByDefault", true);
    profile.setPreference("extensions.firebug.defaultPanelName", "net");

    // Setting netExport preferences
            // see exported HAR in new tab? doesn't seem to be working...
    profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
    profile.setPreference("extensions.firebug.netexport.autoExportToFile", true);
    profile.setPreference("extensions.firebug.netexport.Automation", true);
    profile.setPreference("extensions.firebug.netexport.showPreview", true);
    profile.setPreference("extensions.firebug.netexport.defaultLogDir", "C:\\Users\\myid\\OneDrive @ My Company\\HAR_Exports");
    // this preference does not seem to be in "about:config"
             profile.setPreference("extensions.firebug.netexport.defaultFileName", "testHar");

    // Launch Firefox with the desired capabilities
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName("firefox");
    capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    WebDriver driver = new FirefoxDriver(capabilities);

    // Wait until Firebug is loaded - 5s
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 

    // Load tested website mainpage
    driver.get("http://www.example.com");

    // Wait for page to load (10s)
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Clicking "Login" from the main page
    driver.findElement(By.cssSelector("#login-block a")).click();

    // Wait until tested website's login page is loaded - 10s
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Enter username
    driver.findElement(By.id("username")).sendKeys("myusername");

    // Waiting after entering in Username, 5s (increase if script failing persists)
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 

    // Enter password
    driver.findElement(By.id("password")).sendKeys("mypassword");

    // Clicking "Sign in" after entering UN and PW
    driver.findElement(By.name("loginbutton")).click();

    // Waiting for page to load - implicitly wait 10s
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);    

    // Capture traffic
    try {
        //arbitrary wait time to avoid "issues"
        Thread.sleep(3000);

        //searching for product
        driver.findElement(By.id("parts")).sendKeys("searchable_product");
        driver.findElement(By.cssSelector("#keyword-button-div button")).click();

        //Time to process request, print to file, and quit.
        Thread.sleep(6000);
        } catch(InterruptedException ie) {
        ie.printStackTrace();
        }

            driver.quit();

    }

}


janodvarko commented 9 years ago

HAR export is now natively supported by Firefox, plus there is an extension HAR Export Trigger that makes the automation quite flexible. Please read this page: http://www.softwareishard.com/blog/har-export-trigger/

Does it work for you?

I am not planning to work on NetExport anymore. Its functionality should be fully replaced by native support + HAR Export Trigger extension and I am happy to fix any related issues of this new combo.

Honza

thegreyfawkes commented 9 years ago

Hi, Hanza - thank you for replying!

This looks like it might work - I'll have to tinker my current script around it and see what I can do.

Is there a way to enable the HAR export trigger after I have already made the page visit a site and login? Essentially, I'm creating a Firefox profile with nothing but what I need loaded, but I only want to capture (and export) a single event that records a tracking pixel request.

I realize that this outside of the scope of this support question, but I figured I'd ask while I have you here. :)

janodvarko commented 9 years ago

I think it's valid requirement, but I don't think it's supported now. So, if I understand correctly, you don't wan't to export HAR after every page load, but only if special condition happens correct? But, it would be ok to have the extension installed and trigger the export only when needed, no?

Honza

thegreyfawkes commented 9 years ago

That would be correct. I have no need to capture anything but the 3rd page loaded (which is to simulate a user searching for a product), which triggers a tracking pixel - I wish to generate a HAR for that search to verify a query string value equals what it is supposed to. I previously had this working in the old firebug/netexport setup, but realized that I was going to need to actually specify a file name in order to get it systematically uploaded to the online HAR viewer. And that's where I'm at now. :)

Quick question - is there a location that shows how the variables should be set up? The test page linked on the HAR Export Trigger site wasn't working for me, and I couldn't find any other example pages or sample script.

janodvarko commented 9 years ago

ok, please file a new report for me in har export issue list: https://github.com/firebug/har-export-trigger/issues (but, it might require change on the Fx platform)

The only example page I know about is: http://janodvarko.cz/har/tests/har-export-trigger/har-export-api.html

What doesn't work on the page? I'll fix it too. Please also file a report for it in the same issue list, so it's not forgotten.

Thanks! Honza

janodvarko commented 9 years ago

I am closing this one.

The focus is entirely going to HAR Export Trigger.

Honza