Selenium for Java [java] Checking network traffic

2,765 views
Skip to first unread message

Something Something

unread,
Mar 1, 2011, 12:53:48 AM3/1/11
to seleniu...@googlegroups.com
Hello,

We have a webpage which, when served, hits a URL.  I am trying to write a selenium testcase to check the value of this URL.  In other words, when I use HTTPFox I can see that this URL is getting triggered when the webpage is served.

How do I do this in Selenium?

For example:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.xyz.com/server/pr?type=xxx&part=yyy");

This will trigger the URL.  I would like to check the value of this URL.

Aniket Deshpande

unread,
Mar 3, 2011, 2:33:21 AM3/3/11
to seleniu...@googlegroups.com, Something Something
You can use captureNetworkTraffic.

selenium.start(.......);
selenium.open("http://yoursite.com");
String traffic = selenium.captureNetworkTraffic(<option>); //<option> can be either "plain", "xml" or "json"

traffic will save the entire session for http://yoursite.com

If you choose xml, you can write a simple XML parser for the variable traffic above to get what you want.

P.S.: You need to confirm whether captureNetworkTraffic is intrinsic to your driver or not. AFAIK, it has been inbuilt for the java driver ONLY. For others, it has to be added to the source.

--
- ANIKET


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Something Something

unread,
Mar 3, 2011, 4:55:50 PM3/3/11
to Aniket Deshpande, seleniu...@googlegroups.com
Thanks, Aniket.  I am using WebDriver.  Can we do something similar using just WebDriver?  Please let me know.  Thanks.

Aniket Deshpande

unread,
Mar 4, 2011, 3:15:30 AM3/4/11
to Something Something, seleniu...@googlegroups.com
I haven't used Webdriver yet... but theoretically it should work provided you have the captureNetworkTraffic setup in your driver source.

--
- ANIKET
--
- ANIKET

Mark Collin

unread,
Mar 4, 2011, 4:11:28 AM3/4/11
to seleniu...@googlegroups.com

Last time I checked network traffic capture wasn’t available natively in webDriver so you would have to use webDriver backed selenium to get it working (when I say get it working bear in mind that network traffic capture only used to work in FireFox, so unless the code has been tweaked this is FireFox specific)

 

public static Selenium sel = new WebDriverBackedSelenium(<driver>, <siteHomePage>);

sel.captureNetworkTraffic("xml")

sel.open(<url>);

String trafficCaptured = sel.captureNetworkTraffic("xml")

WebDriver driverInstance = ((WebDriverBackedSelenium) sel).getUnderlyingWebDriver();

<driver> = driverInstance;

 

Where <driver> is your driver object

 

Every time you use captureNetworkTraffic it resets the buffer, hence why above I have used it before and after navigating to the page to ensure buffer is clear.

 

Regards

 

Mark


-- This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error please notify postm...@ardescosolutions.com

Something Something

unread,
Mar 4, 2011, 11:39:25 PM3/4/11
to seleniu...@googlegroups.com, Mark Collin
This line:  sel.captureNetworkTraffic("xml") throws UnsupportedOperationException:

java.lang.UnsupportedOperationException: captureNetworkTraffic
at org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:271)
at org.openqa.selenium.WebDriverCommandProcessor.getString(WebDriverCommandProcessor.java:245)
at com.thoughtworks.selenium.DefaultSelenium.captureNetworkTraffic(DefaultSelenium.java:727)


Also, getUnderlyingWebDriver method is deprecated.

Mark Collin

unread,
Mar 7, 2011, 5:16:09 AM3/7/11
to seleniu...@googlegroups.com

Strange…

 

What version are you using?  I’m on 2.0b1 and it’s not showing as deprecated here (I’ve not updated to 2.0b2 yet).  As for the exception try using just a:

 

sel.captureNetworkTraffic()

 

Does it still give you issues if you do that?

Something Something

unread,
Mar 7, 2011, 7:14:03 PM3/7/11
to seleniu...@googlegroups.com
I am using 2.0b2.  Tried using sel.captureNetworkTraffic().  Got same exception.

Mark Collin

unread,
Mar 8, 2011, 1:11:53 AM3/8/11
to seleniu...@googlegroups.com

I’ll have to update to 2.0b2 and have a look…

vid401t

unread,
Mar 8, 2011, 2:27:15 PM3/8/11
to Selenium Users
Hi Mark,

I'm facing the same issue, I'm using 2.0.b1 and copied what you had
exactly, but getting the error:

"java.lang.UnsupportedOperationException: captureNetworkTraffic"

This was working for you on 2.0.b1 though right? Did you do anything
extra?

Thanks

On Mar 7, 10:11 pm, "Mark Collin" <m...@ardescosolutions.com> wrote:
> I'll have to update to 2.0b2 and have a look.
>
> From: seleniu...@googlegroups.com
> [mailto:seleniu...@googlegroups.com] On Behalf Of Something Something
> Sent: 08 March 2011 00:14
> To: seleniu...@googlegroups.com
> Subject: Re: [selenium-users] Selenium for Java [java] Checking network
> traffic
>
> I am using 2.0b2.  Tried using sel.captureNetworkTraffic().  Got same
> exception.
>
> On Mon, Mar 7, 2011 at 2:16 AM, Mark Collin <m...@ardescosolutions.com>
> wrote:
>
> Strange.
> On Fri, Mar 4, 2011 at 1:11 AM, Mark Collin <m...@ardescosolutions.com>
> On Wed, Mar 2, 2011 at 11:33 PM, Aniket Deshpande <meetani...@gmail.com>
> wrote:
>
> You can use captureNetworkTraffic.
>
> selenium.start(.......);
> selenium.open("http://yoursite.com");
> String traffic = selenium.captureNetworkTraffic(<option>); //<option> can be
> either "plain", "xml" or "json"
>
> traffic will save the entire session forhttp://yoursite.com
>
> If you choose xml, you can write a simple XML parser for the variable
> traffic above to get what you want.
>
> P.S.: You need to confirm whether captureNetworkTraffic is intrinsic to your
> driver or not. AFAIK, it has been inbuilt for the java driver ONLY. For
> others, it has to be added to the source.
>
> --
> - ANIKET
>
> On 1 March 2011 11:23, Something Something <mailinglist...@gmail.com> wrote:
>
> Hello,
>
> We have a webpage which, when served, hits a URL.  I am trying to write a
> selenium testcase to check the value of this URL.  In other words, when I
> use HTTPFox I can see that this URL is getting triggered when the webpage is
> served.
>
> How do I do this in Selenium?
>
> For example:
>
> WebDriver driver = new FirefoxDriver();
>
> driver.get("http://www.xyz.com/server/pr?type=xxx
> <http://www.xyz.com/server/pr?type=xxx∂=yyy> &part=yyy");
>
> This will trigger the URL.  I would like to check the value of this URL.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com
> <mailto:selenium-users%2Bunsu...@googlegroups.com> .
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> -- This message contains confidential information and is intended only for
> the individual named. If you are not the named addressee you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this e-mail by mistake and delete
> this e-mail from your system. If you are not the intended recipient you are
> notified that disclosing, copying, distributing or taking any action in
> reliance on the contents of this information is strictly prohibited. If you
> have received this email in error please notify
> postmas...@ardescosolutions.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com
> <mailto:selenium-users%2Bunsu...@googlegroups.com> .
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> -- This message contains confidential information and is intended only for
> the individual named. If you are not the named addressee you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this e-mail by mistake and delete
> this e-mail from your system. If you are not the intended recipient you are
> notified that disclosing, copying, distributing or taking any action in
> reliance on the contents of this information is strictly prohibited. If you
> have received this email in error please notify
> postmas...@ardescosolutions.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com
> <mailto:selenium-users%2Bunsu...@googlegroups.com> .
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

James Byrer

unread,
Mar 23, 2011, 11:52:38 AM3/23/11
to Selenium Users
I seem to be having the same problems you are. I am seeing these
errors with .b1, .b2 and .b3 (selenium-server-standalone-2.0b3.jar).

Rob Barreca

unread,
Dec 7, 2011, 10:01:12 PM12/7/11
to seleniu...@googlegroups.com
Anyone have any updates on this? I want to write a unit test to verify that a JavaScript tracking pixel (i.e. new Image().src = 'http://some.tracking.server.com/track.gif?abc...';) goes out on a particular automated interaction. I tried with ChromeDriver and FirefoxDriver and get same exception as above with both. This would be radical to do. I will give anyone a trophy who figures out how to do this without having to setup a proxy and run these assertions on a separate system asynchronously. 

Rob Barreca

unread,
Dec 8, 2011, 10:00:26 PM12/8/11
to seleniu...@googlegroups.com
Nevermind, I see that https://github.com/lightbody/browsermob-proxy/blob/master/README.md will actually do what I want. I didn't realize the proxy was immediately available for queries to asset tracking pixels fired. I'm doing it like this. It works fine with FirefoxDriver but the addRequestInterceptor isn't getting triggered for ChromeDriver which is a blocker.

@Test
    public void testSetPropertyTrackingLabel() throws Exception {
        // start the proxy
        ProxyServer server = new ProxyServer(9090);
        server.start();

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

        // configure it as a desired capability
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, proxy);
        WebDriver driver = new FirefoxDriver(capabilities);
        
        // create a new HAR with the label "yahoo.com"sco
        server.addRequestInterceptor(new HttpRequestInterceptor() {

            public void process(
                    final HttpRequest request,
                    final HttpContext context) throws HttpException, IOException {
                
                String req = request.getRequestLine().getUri();
                System.out.println(req);
            }

        });

        server.newHar("yahoo.com");
        driver.get("http://yahoo.com");
    }

Venkata Prasad Reddy

unread,
Aug 16, 2016, 2:36:52 AM8/16/16
to Selenium Users, mailing...@gmail.com
Hello All,

I have requirement called capture the network data with browser(Chrome, PhantomJS and IE) using Selenium web driver. Do we have solution to capture network using selenium web driver, if so please provide the steps for the same.

Thanks in advance.

⇜Krishnan Mahadevan⇝

unread,
Aug 16, 2016, 2:43:30 AM8/16/16
to Selenium Users
This is what you are looking for.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0449b69c-efdb-45f3-a5fa-985300875c8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Venkata Prasad Reddy

unread,
Aug 16, 2016, 3:11:16 AM8/16/16
to Selenium Users
Hello Krishnan,

First fall thanks for quick response.

I have gone through the url which you provided. I have few questions please clarify.

Q1. Is this Api supports only firefox driver or other drivers also
Q2. Do we have any C# api for capturing network traffic data.

Thanks in advance.




On Tuesday, 16 August 2016 12:13:30 UTC+5:30, Krishnan wrote:
This is what you are looking for.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Tue, Aug 16, 2016 at 12:06 PM, Venkata Prasad Reddy <bhumir...@gmail.com> wrote:
Hello All,

I have requirement called capture the network data with browser(Chrome, PhantomJS and IE) using Selenium web driver. Do we have solution to capture network using selenium web driver, if so please provide the steps for the same.

Thanks in advance.




On Tuesday, 1 March 2011 11:23:48 UTC+5:30, Something Something wrote:
Hello,

We have a webpage which, when served, hits a URL.  I am trying to write a selenium testcase to check the value of this URL.  In other words, when I use HTTPFox I can see that this URL is getting triggered when the webpage is served.

How do I do this in Selenium?

For example:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.xyz.com/server/pr?type=xxx&part=yyy");

This will trigger the URL.  I would like to check the value of this URL.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Aug 16, 2016, 3:53:41 AM8/16/16
to Selenium Users
Yes, it can be used as a proxy server for all the browser flavors and is not specific to firefox alone.

If you are using a client binding that is NOT java, then you would need to have the BMP server spin off in standalone mode [https://github.com/lightbody/browsermob-proxy#getting-started-standalone] and then using its REST APIs : https://github.com/lightbody/browsermob-proxy#rest-api

For additional questions, you can post on the BMP forum : https://groups.google.com/forum/#!forum/browsermob-proxy

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/32a00819-4e38-4374-a088-7c297e5441b5%40googlegroups.com.

Venkata Prasad Reddy

unread,
Aug 16, 2016, 5:23:21 AM8/16/16
to Selenium Users
Thanks Krishnan!

Reply all
Reply to author
Forward
0 new messages