Capturing Network Traffic using NetExport in Selenium

What is NetExport?

  • NetExport is an extension to Firefox which helps in gerenating the report under the “Net” panel in firebug.
  • NetExport can be downloaded from “https://getfirebug.com/releases/netexport/ “.
  • An Export tab would be available under the Net panel after the extension is added into the browser.
  • The net traffic can be recorded and exported into a .har file for future reference.

HAR Viewer: 

Using Selenium with NetExport:

  • We can capture the network traffic for a web application while executing the selenium tests using the netexport extension by the following method:
  • Add the .xpi file for firebug.
    File firebug = new File(“Path to:\\firebug@software.joehewitt.com.xpi“);
  • Add the .xpi file for netexport.
    File netExport = new File(“Path to:\\netexport@getfirebug.com.xpi“);
  • Create a firefox profile.
    FirefoxProfile profile = new FirefoxProfile();
  • Add the firebug extension.
    profile.addExtension(firebug);
  • Add the firebug preferences.

    profile.setPreference(“extensions.firebug.currentVersion”, “2.0”);
    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”); 

  • Add the netexport extension.
    profile.addExtension(netExport);
  • Add the netexport preferences.

    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”, false);
    profile.setPreference(“extensions.firebug.netexport.defaultLogDir”, “<path to store the .har file generated>”); 

  • Add the 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); 

  • Navigate across your application web page using selenium.
  • The .har file would be generated and stored in the path provided by you and can be viewed by using HAR viewer.

 

Written By: – Jaya Mohanty, QA Engineer, Mindfire Solutions

Advertisements

Posted on April 8, 2014, in Automation Testing, Selenium Testing and tagged , , , , , , , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: