Ho to Catch http requests using Selenium

97 views
Skip to first unread message

Alexander R

unread,
Aug 25, 2016, 8:14:38 AM8/25/16
to Selenium Users
Hi,
We are working with Selenium Webdriver using C#
Most of our tests run on Chrome and PhantomJS.
Is there any way to catch http requests in these browsers?
If not, is there any way to do it with Firefox?
Thanks!

Jim Evans

unread,
Aug 25, 2016, 8:18:44 AM8/25/16
to Selenium Users
Short answer, use a proxy. A blog post series with examples can be found here: http://jimevansmusic.blogspot.com/2013/08/implementing-webdriver-http-status.html

Alexander R

unread,
Aug 28, 2016, 2:25:35 PM8/28/16
to Selenium Users
Thank you very much, Jim!
Can you recommend any resource with good documentation of fiddler API?
Thanks!

⇜Krishnan Mahadevan⇝

unread,
Aug 29, 2016, 2:01:34 AM8/29/16
to Selenium Users

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/4d37e159-4fa4-42bf-8868-a7196af77ec7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander R

unread,
Aug 29, 2016, 10:50:28 AM8/29/16
to Selenium Users
Thank you, Krishnan.

I started working on it, but I encountered a problem: if I run a test using proxy, I cannot run with this test in parallel other tests that don't use proxy.
Can  I do something with it?

Thanks


On Monday, August 29, 2016 at 9:01:34 AM UTC+3, Krishnan wrote:

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 Sun, Aug 28, 2016 at 11:55 PM, Alexander R <r.g....@gmail.com> wrote:
Thank you very much, Jim!
Can you recommend any resource with good documentation of fiddler API?
Thanks!


On Thursday, August 25, 2016 at 3:18:44 PM UTC+3, Jim Evans wrote:
Short answer, use a proxy. A blog post series with examples can be found here: http://jimevansmusic.blogspot.com/2013/08/implementing-webdriver-http-status.html

--
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 30, 2016, 12:31:55 AM8/30/16
to Selenium Users
Alex,

Can you please share your code which shows how you are forming the proxy instance object, packing it into the DesiredCapabilities object and then using it to instantiate the webdriver object ?

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/ff36b668-2771-417e-85de-49ab33f110fd%40googlegroups.com.

Alexander R

unread,
Aug 30, 2016, 10:02:48 AM8/30/16
to Selenium Users
Thank you, Krishnan,
I succeeded to run tests in parallel, but now the issue is: I cannot run the test in remote machine using selenium grid.
The code is:

int proxyPort = StartFiddlerProxy(8888);
FiddlerApplication.BeforeRequest += delegate (Session targetSession)
                        {
                            Console.WriteLine("Requested resource from URL {0}",
                                              targetSession.fullUrl);
                        };



                        OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
                        proxy.HttpProxy = string.Format("{{IP address}}:{0}", proxyPort);

                        ChromeOptions profile = new ChromeOptions();
                        profile.Proxy = proxy;

 ICapabilities caps = profile.ToCapabilities();
                        driver = new RemoteWebDriver(new Uri(http://{{IP address}}:4444/wd/hub), caps, TimeSpan.FromSeconds(600));


  private static int StartFiddlerProxy(int desiredPort)
        {
            FiddlerApplication.Startup(desiredPort, true, true, true);
            int proxyPort = FiddlerApplication.oProxy.ListenPort;
            return proxyPort;
        }

Thanks a lot!

⇜Krishnan Mahadevan⇝

unread,
Sep 2, 2016, 2:41:46 PM9/2/16
to Selenium Users
Alex,
One of the reasons behind you not being able to run in remote mode (against a grid that runs on a different machine) maybe due to the IP address that you are packing in your desired capabilities.

How are you forming the IP address ? Are you resorting to 127.0.0.1 (loop back address) ? 
You also can check if there are any port related issues.


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/0cf0b762-fef2-4c85-87df-1e0b1e4d977b%40googlegroups.com.

Alexander R

unread,
Dec 13, 2016, 6:51:18 AM12/13/16
to Selenium Users
Thank you, very much, Krishnan.
Here is my script

RemoteWebDriver driver;
ChromeOptions chromeOptions = new ChromeOptions();
FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.Default);
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy = "{IP of the different machine}:8888";
chromeOptions.Proxy = proxy;
DesiredCapabilities capabilities = (DesiredCapabilities)chromeOptions.ToCapabilities();
driver = new RemoteWebDriver(new Uri({IP of the different machine}:4444/wd/hub), capabilities, TimeSpan.FromSeconds(600));
FiddlerApplication.AfterSessionComplete += CollectDataThroughProxy;



private static List<string> dataStr = new List<string>();


private static void CollectDataThroughProxy(Session sess)
        {
            if (sess == null || sess.oRequest == null || sess.oRequest.headers == null)
                return;
            string headers = sess.oRequest.headers.ToString();
            var reqBody = sess.GetRequestBodyAsString();
            dataStr.Add(reqBody);
        }

When I change IP in the code and run it on my local machine, it works fine. However, when I change IP to different machine, I don't get the http traffic from this machine.
I checked "allow remote computers to connect" in Fiddler options.
When I replace proxy.HttpProxy = "{IP of the different machine}:8888"; by proxy.HttpProxy = "127.0.0.1:8888"; nothing changes

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages