Monday Sep 14, 2009

How to Test External Sites (Internet Sites) using Selenium

[Article by shariff.king@sun.com]

    Problem :

    If your testing site (ex: google.com / yahoo.com) is behind the proxy then selenium fails to access the site. 

    Because selenium itself acts as proxy to AUT (Application Under Test) and which fails to resolve internet sites behind proxy.

    seleniumhq.org site says using proxy options, while starting the server will help to resolve the external sites.

    i.e java -jar selenium-server.jar -Dhttp.proxyHost=<proxyHostName> -Dhttp.proxyPort=<proxyPort>


    But the above solution doesn't resolve the issue.

    Before jumping in to solution let us see how selenium server invokes browser and access the internal/external sites.

    When we invoke NewBrowserSession Request to selenium server (i.e selenium.start()) the following background steps are performed.


    For \*firefox/\*chrome:

    1)Extract the CustFirefoxProfile bundled with selenium server.

    2)This will make sure clean firefox session for every new browser session.

    3)Command line jvm proxy settings does not affect to the new firefox session.


    For \*iexplore:

    In case of Internet Explorer , it will simply create custom profile from the current IE instance settings.

    So, for IE simply set the browser proxy to access the internet sites and running tests on internet sites will work. We need solution only for firefox/chrome browser sessions. 

   

Solution :

    1) Extract the selenium-server.jar using WinRAR/7zip/Winzip archive tool.

    2) Copy "customProfileDirCUSTFF" to a new folder as "MyProxyFirefox"

    3) Under "MyProxyFirefox" folder create firefox user settings file.

       (i.e create a New Text File with Name "prefs.js" with out quotes. Extension of File Should be .js)


    4) Now copy the following properties to prefs.js file.

       user_pref("network.proxy.type", 1);

       user_pref("network.proxy.ftp", "webcache.central.sun.com");

user_pref("network.proxy.ftp_port", 8080);

user_pref("network.proxy.gopher", "webcache.central.sun.com");

user_pref("network.proxy.gopher_port", 8080);

user_pref("network.proxy.http", "webcache.central.sun.com");

user_pref("network.proxy.http_port", 8080);

user_pref("network.proxy.share_proxy_settings", true);

user_pref("network.proxy.socks", "webcache.central.sun.com");

user_pref("network.proxy.socks_port", 8080);

user_pref("network.proxy.ssl", "webcache.central.sun.com");

user_pref("network.proxy.ssl_port", 8080);

user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, .india.sun.com");


   5) Now replace "webcache.central.sun.com" with your Web Proxy and also replace "8080" port with the webproxy port.

   6) For By Pass the Proxy for Internal Sites then update last property value with comma as separator.

      i.e network.proxy.no_proxies_on


   7) Now start the Selenium server with the following options.

   i.e java -jar selenium-server.jar -firefoxProfileTemplate MyProxyFirefox

 

About

I'm a Quality Engineer at Sun Microsystems. Here in this blog, you may find information about Software Testing, Portal Server, Virtualization, Web2.0 and Misc Technical topics. The views expressed here are personal and does not reflect that of my employer

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today