Reputation: 1081
Is it possible to drive PhantomJS with WebDriver, but also when navigating through various pages, log the network traffic of each page using PhantomJS?
I can't seem to figure out a solution, or find one on the net.
Upvotes: 2
Views: 254
Reputation: 5113
Yes, certainly.
Start up a proxy server like Browsermob, set it as your Selenium proxy, and for the pages / URL patterns you're interested in, call:
proxy.newHar("<name>");
driver.get(url);
Har har = proxy.getHar();
as per the example on the previous link.
That HAR file will contain the entire content of every individual request and response associated with your page request, which you can then persist, visualise, or query via an API.
Obviously you could automate this, schedule the PhantomJS test runs, and either produce your own custom metrics with your own code; pipe the HAR into a JSON-savvy database for querying (say Elasticsearch) and visualisation, or just save the HARs for offline querying and diffing.
You can visualise the output by obtaining the HAR in string form and pasting into http://www.softwareishard.com/har/viewer/. It gives you an output almost identical to Chrome's Network tab, which goes to show that the data captured is pretty much the same.
Upvotes: 2