3

I would like to record HTTP traffic to HAR file when using Selenium Web Driver.

One way is to use BrowserMob Proxy. This works perfectly fine locally but not when in Selenium Grid, because Selenium Grid is not able to access a proxy instance run locally, at least in our company.

Are there any alternatives?

2

2 Answers 2

1

This is the suitable tool for your problem - BrowserMobProxy. With this, you could capture the traffic as a Har file. You could also block and bypass any request after analyzing the response to decrease the page load time for your automated testing services (if you are doing web automation). It is easily integrated with selenium.

Sample code from git :

// start the proxy
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);

// get the Selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);

// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);

proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

// create a new HAR with the label "yahoo.com"
proxy.newHar("yahoo.com");

// open yahoo.com
driver.get("http://yahoo.com");

// get the HAR data
Har har = proxy.getHar();

Hope that will helps.

0

This is answered here on SO.

I posted the answer below for quick reference: I found a google groups discussion on the topic, these links look like promising an alternative to Browsermob.

Reference link

supermind

theautomatedtester

hope those help.

Alternately if those don't work you can have Wireshark running on the server and setup the rules to specifically record the target traffic you are after. You just want to make sure you clear it first and then pull it after the test activity. That, of course, is more manual instead of putting it into your automated test.

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.