19

If yes, how is it called, or where can I find more info about it? (I'm not talking about using WebDriverBackend.)

If not, what alternatives are there?

2
  • I may eventually do that, but rather look for native webdriver solutions.
    – Roni Yaniv
    Commented Jun 27, 2011 at 11:26
  • Question has been answered, but many people on SQA cannot find answer to this problem, and are duplicating the question. Could we add more context to the question regarding the problem. For instance, this [sqa.stackexchange.com/questions/2915/… question) describes it very clearly and from more general perspective, IMHO.
    – dzieciou
    Commented Nov 1, 2012 at 7:50

5 Answers 5

17

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:

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);

Once the test is finished, you can extract the data from the browsermob proxy using the mechanisms it provides. Notice that you can also use any proxy you want: it need not be the browsermob one!

2
  • Does using a proxy slow down the test?
    – A.J
    Commented May 16, 2012 at 19:57
  • and then how do you check the value from the proxy in the test? ...yet another whole system to maintain and to add false positives.
    – gcb
    Commented Oct 26, 2012 at 23:08
4

No there is no native solution at the moment. If you use webDriverBackedSelenium you can try to utilise the captureNetworkTraffic functionality, however there were issues with it last time I heard it talked about (See here for more info - https://groups.google.com/d/topic/selenium-users/fMSHeH9ZVqU/discussion).

It's also worth noting that captureNetworkTraffic only works in FireFox due to the way it was implemented so it's not a cross browser solution.

*Update*

Based on some information that came through the selenium/webdriver mailing lists you can use a proxy instead (Suggested one is http://bmp.lightbody.net/, although there are others).

To configure it:

 Proxy proxy = new Proxy();
 proxy.setHttpProxy(<proxyAddress>);
 DesiredCapabilities cap = DesiredCapabilities.firefox();
 cap.setCapability(CapabilityType.PROXY, proxy);
 WebDriver driver = new FirefoxDriver(cap);

This should currently work for FireFox and IE. It looks like this is going to be the way to capture network traffic moving forward.

Note: "new Proxy()" - Needs org.openqa.selenium.Proxy.

1

I've been using a combination of Charles Proxy and window.performance.getEntriesByType('resource') inside an executeScript. Performance does not capture POST data, so that is why I also use Charles. I export the Charles session as a .har file and then use a nodejs script to merge the data.

Collect window performance data, filtered to get Adobe Analytics ("b/ss"), and then just returning the name aka the GET or POST url string .

let getPerformance = () => {
    return  (window.performance.getEntriesByType('resource').filter(function(entry){
        return /b\/ss/i.test(entry.name);
    })).map( entry => { return decodeURIComponent(entry.name) }).join("\n");
}

driver.executeScript( getPerformance ).then( windowPerformance => { /* do something with window.performance data */ })
0

Haven't looked through it all yet, but I did find a post that seems related. Also, haven't tried it out, but, have you looked at any of the fiddler libraries? Although I have plans on trying them out, it's not going to be for a few months yet.

1
  • Looks interesting, but I'm looking for a more complete solutions, maybe requiring the usage of two tools (like selenium and gson, in my case). This looks like a lot of work to accomplish this thing.
    – Roni Yaniv
    Commented Jun 27, 2011 at 11:25
0

Yes you can automate it using BrowserMob Proxy. [Please use the below mentioedn link to test Network traffic using BrowserMob Proxy

https://keshavtechinfo.wordpress.com/web-automation/selenium/web-page-load-testing-using-selenium-and-browsermob-proxy/ ]1

2
  • 1
    How about writing the answer here and using the link as reference? Commented Jun 13, 2016 at 8:00
  • Using BrowserMob Proxy, we capture performance data How to use BrowserMob Proxy? Download BrowserMob Proxy 2.Start BrowserMob Proxy Create a new Project and import BrowserMob Proxy with Selenium Standalone Server Jar Run the script. After running the script, you will see the proxy server is started, and respective logs are generated. As the script stops, an HTTP achieve file is also generated with Performance Log of the desired web application. Now you can import that HAR file and see the results at pcapperf.appspot.com. It will show the fetched performance data. Commented Jun 14, 2016 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.