We often come across testing requirements when we need to analyze the network traffic to find -
worth using solutions available for Selenium 2 (WebDriver). I have come across two solution of capturing n/w traffic with WebDriver -
Manual operations of exporting HAR file can be automated using WebDriver.
WebDriver can easily configure firefox plug-in and step through the application to get the required HAR file generated. Refer this excellent example of configuring Firefox driver with firebug and netexport add ons. Once you get the HAR file then HarLib can be used to fetch the required data from HAR file.
- HTTP status of page
- Analyze header information to find if right information is passed
- Validating parameters related to ajax requests etc
worth using solutions available for Selenium 2 (WebDriver). I have come across two solution of capturing n/w traffic with WebDriver -
- Browser Mob Proxy (BMP) - which acts as proxy server b/w WebDriver and your application, captures all the transactions b/w browser and application and creates a HAR file. Sounds interesting? But I came across a few issues using BMP -
- Test execution goes sluggish because of using proxy server
- Test steps go abrupt at times, for example you may have to click same button twice/thrice to perform operation
- BMP does not support capturing n/w traffic against application running on localhost (at least not at the time of writing this post.)
If you get to work with BMP then bigger advantage is its capability of capturing network traffic across all browsers. But if your test require you to use only Firefox then there is more elegant solution available, that is to use
Firebug
is as popular tool among selenium users as it is among developers.
NetExport is add on to firebug which captures network traffic in form of
HAR files. HAR file is json based file, refer HAR specification for more. NetExport can export all the n/w traffic in HAR format as detailed in image here Manual operations of exporting HAR file can be automated using WebDriver.
WebDriver can easily configure firefox plug-in and step through the application to get the required HAR file generated. Refer this excellent example of configuring Firefox driver with firebug and netexport add ons. Once you get the HAR file then HarLib can be used to fetch the required data from HAR file.
Hi, I tried this and it is working fine for the normal sites like facebook and so but when i am running this for my company site walmart.com then its not generating .har file.
ReplyDeleteCan you please help me with this? I am stuck here.
Is there some ajax driven operation for which you are gathering data? If so then ajax has been pain to capture n/w traffic. If it is a normal page then should have worked. In either case, I would ask you to add more details.
DeleteHi Tarun,
ReplyDeleteAfter adding some more preferences like
profile.setPreference(domain + "currentVersion", "2.0");
profile.setPreference(domain + "allPagesActivation", "on");
profile.setPreference(domain + "defaultPanelName", "net");
profile.setPreference(domain + "net.enableSites", true);
profile.setPreference(domain + "addonBarOpened", true);
profile.setPreference(domain + "console.enableSites", true);
profile.setPreference(domain + "script.enableSites", true);
profile.setPreference(domain + "previousPlacement", 1);
profile.setPreference(domain + "allPagesActivation", "on");
profile.setPreference(domain + "onByDefault", true);
Now i am able to get har file of www.walmart.com but still for websites like www-e4.walmart.com(which is internal test env, replica of production site ), not able generate har file.
Architecture and design wise both are same, so could it be some security related issue.
Does not seem any thing explicitly wrong. Could you post this question here - https://groups.google.com/forum/#!forum/firebug
DeleteThis is official forum for firebug.