Tuesday 15 March 2016

How to Capture Network Traffic and Http Requests From WebDriver

How to Capture Network Traffic and Http Requests From WebDriver:
===================================================

Selenium 1 has a built-in mechanism to record network traffic and http requests by setting the selenium.start(“captureNetworkTraffic=true”);

Unfortunately this solution is not available “out of the box” in Selenium 2 or WebDriver.

You can capture network traffic using a proxy, such as the BrowserMob Proxy (http://proxy.browsermob.com)

To configure the use of the proxy with a webdriver instance, set the CapabilityName.PROXY value to a org.openqa.selenium.Proxy instance:



package com.rameshselenium.blogspot;

     Proxy proxy = new Proxy();
     // The URL here is the URL that the browsermob proxy is using
     proxy.setHttpProxy("localhost:9100");

     DesiredCapabilities capabilities = DesiredCapabilities.firefox();
     capabilities.setCapability(CapabilityType.PROXY, proxy);

     WebDriver driver = new FirefoxDriver(capabilities);

No comments:

Post a Comment