Table of Contents
Enroll in Selenium Training

Let's spend few minutes to understand what Proxy is, and the difference between Socks Proxy and HTTP Proxy. SOCKS uses a handshake protocol to inform the proxy software about the connection that the client is trying to make and may be used for any form of TCP or UDP socket connection, whereas an HTTP proxy analyses the HTTP headers sent through it in order to deduce the address of the server and therefore may only be used for HTTP traffic. The following examples demonstrate the difference between the SOCKS and HTTP proxy protocols:

SOCKS

Lakshay wishes to communicate with Viru over the internet, but a firewall exists on his network between them and Lakshay is not authorized to communicate through it himself. Therefore, he connects to the SOCKS proxy on his network and sends information about the connection he wishes to make to Viru. The SOCKS proxy opens a connection through the firewall and facilitates the communication between Lakshay and Viru.

HTTP

Lakshay wishes to download a web page from Viru, who runs a web server. Lakshay cannot directly connect to Viru's server, as a firewall has been put in place on his network. In order to communicate with the server, Lakshay connects to his network's HTTP proxy. His internet browser communicates with the proxy in exactly the same way it would the target server - it sends a standard HTTP request header. The HTTP proxy reads the request and looks for the Host header. It then connects to the server specified in the header and transmits any data the server replies with back to Lakshay.

I explained this because just like me most of the people get confused in the above terms. Until and unless you don't know what kind of authentication you are getting, it is difficult to find a right solution of it.

My Analysis:  I may or may not be correct, so please pardon me if in case you are not agreeing with my views, as I am not so technical. To handle Socks proxy we need to provide our system credentials what we use to log on to our windows system and to handle HTTP proxy we need to provide site credentials which has been set on the server side.

How to set HTTP Proxy with Username and Password

Let's see how does the Authentication window looks in different browsers:

Firefox Browser Authentication Window

Firefox Auth

Internet Explorer Browser Authentication Window

IE Authentication

Chrome Authentication

Chrome Browser Authentication Window

My idea is that if we want to handle HTTP Proxy Authentication, we can simply send Username & Password through URL and in most of the cases it works perfectly fine.

driver.get("https://UserName:[email protected]");

If the above code does not work then it can be a proxy settings issue which can be manually handled. Please see below section.

Firefox Browser Profile Settings

Before changing the default Firefox Profile settings it is always advisable to create a separate profile for Automation test. Kindly go through the section Custom Firefox Profile for Selenium for more understanding on why we need it, how to create it and how to use it.

  1. Type 'about:config' on the browser and press Enter.

Auth-4

  1. The moment you press Enter, you will get the below Warning Message. Hit 'I'll be careful, I promised!' and proceed further.

Auth-5

  1. Now type 'browser.safebrowsing.malware.enabled' on the Search field and set the Value to 'true' by double clicking it.

Auth-6

  1. From now on the Firefox should let you go through HTTP Authentication using User & Password in the Url. Now all you need to do is to Instantiate the newly created Custom Firefox Profile (profileToolsQA) to your Selenium Test script.
ProfilesIni profile = new ProfilesIni();

FirefoxProfile myprofile = profile.getProfile("profileToolsQA");

WebDriver driver = new FirefoxDriver(myprofile);

Note: In case your authentication server requires username with domain like "domainuser" you need to add double slash '' to the Url.

http://localdomain\user:[email protected]

If the problem is still not resolved please go through the below section of SOCKS Proxy to resolve it with another way. This would work fine without prompting any authentication.

Internet Explorer Browser Settings

  1. Press ' + R'  or click on the Windows Start Menu (bottom left button) and then select Run.

FF-Profile-2

  1. In the Run dialog box, type in: 'regedit.exe' and then Click OK.

  2. Now navigate to 'HKEY_LOCAL_MACHINE Software Microsoft Internet Explorer Main FeatureControl FEATURE_HTTP_USERNAME_PASSWORD_DISABLE'.

  3. On the right hand side, perform Right click and select New > DWORD VALUE and name it as 'iexplorer.exe'.

Auth-7

  1. Now Modify the value of 'iexplorer.exe' to '0'.

Auth-8

Auth-9

Restart the browser and the functionality should be available now.

Note: In case your authentication server requires username with domain like "domainuser" you need to add '%5C'  symbol to the Url.

http://domain%5Cuser:[email protected]

If the problem is not resolved please go through the below section to resolve it with another way. This would work fine without prompting any authentication.

How to set SOCKS Proxy with Username and Password

Firefox Browser Profile Settings

Before changing the default Firefox Profile settings it is always advisable to create a separate profile for Automation test. Kindly go through the section Custom Firefox Profile for Selenium for more understanding on why we need it, how to create it and how to use it.

  1. Type ‘about:config‘ on the browser and press Enter.

Auth-4

  1. The moment you press Enter, you will get the below Warning Message. Hit ‘I’ll be careful, I promised!‘ and proceed further.

Auth-5

  1. Now type ‘signon.autologin.proxy‘ on the Search field and set the Value to ‘true‘ by double clicking it.

Auth-10

4) Now all you need to do is to Instantiate the newly created Custom Firefox Profile (profileToolsQA) to your Selenium Test script.

ProfilesIni profile = new ProfilesIni();

FirefoxProfile myprofile = profile.getProfile("profileToolsQA");

WebDriver driver = new FirefoxDriver(myprofile);

This issue can be handled with the help of AutoIt tool. AutoIt is a third party tool for desktop automation. Please visit Uses of AutoIt in Selenium Webdriver.

Handle SSL Certificate in Selenium
Handle SSL Certificate in Selenium
Previous Article
Find Broken Links in Selenium
Find Broken Links in Selenium
Next Article
Lakshay Sharma
I’M LAKSHAY SHARMA AND I’M A FULL-STACK TEST AUTOMATION ENGINEER. Have passed 16 years playing with automation in mammoth projects like O2 (UK), Sprint (US), TD Bank (CA), Canadian Tire (CA), NHS (UK) & ASOS(UK). Currently, I am working with RABO Bank as a Chapter Lead QA. I am passionate about designing Automation Frameworks that follow OOPS concepts and Design patterns.
Reviewers
Virender Singh's Photo
Virender Singh

Similar Articles

Feedback