Authentication is a process for verifying the identity of an object. Let’s consider that object as a website here. When we load URL of a website then that website may ask you to authorize yourself before getting access to its content. One of the authentication method is Window Authentication. It is also called as basic authentication. Something as below :-
Handling window authentication in Selenium WebDriver is tricky. Mostly people understand authentication pop up as a Javascript alert and try by switching to it using Alert interface. Everything that pops up , is not a Javascript alert.
However, Selenium 3.4.0 version added a new method named authenticateUsing() in Alert interface to authenticate these authentication pop up but it was not successful and removed from later versions.
Reference – https://github.com/SeleniumHQ/selenium/blob/selenium-3.4.0/java/client/src/org/openqa/selenium/Alert.java
There are some solutions to it with certain limitations :-
- By using third party tools such as Sikuli and AutoIt. These solutions have limitations like Sikuli will not work on Jenkins if headless. AutoIt is only for windows and have problem in running on Jenkins.
- Passing or encoding username and password within URL as http://username:password@url mostly works for a non secure websites (http) and fails for secure sites (https).
Manually whenever you load that URL you may need to enter username and password every time which is pain. You may be access of multiple such websites and remembering credentials for each is not possible. A browser extension can help you to remember these credentials and grant access automatically when you access such websites. Something like password management of any browser.
You can handle authentication pop up in Chrome browser using Multipass extension provided by chrome. In this extension we can setup username and password for a URL in advance so that whenever you launch that URL then it will not ask you to authorize. The same extension is available for Firefox and Opera as well.
Learn here to add a chrome extension manually and using Selenium WebDriver in simple steps here.
Steps to handle basic authentication popup in Selenium WebDriver are as below:-
- Add Multipass extension to chrome browser.
- Open extension webpage.
- Locate URL, Username and Password fields and pass values and click on Add button.
- You are done.
These steps will be more clear in a video tutorial which you can find below:-
Chrome extension download link –
https://chrome.google.com/webstore/detail/multipass-for-http-basic/enhldmjbphoeibbpdhmjkchohnidgnah
Grab the source code with extension –
https://github.com/ortoniKC/letCode/tree/master/auth
This post is contributed by :-
Koushik Chatterjee who is a QA Engineer and Chrome extension developer (Ruto – XPath Finder) and YouTuber @ https://youtube.com/letcode. Connect with him on LinkedIn @ https://www.linkedin.com/in/ortoni
You can download/clone above sample project from here.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning
Find all Selenium related post here, all API manual and automation related posts here and find frequently asked Java Programs here.
Many other topics you can navigate through menu.
Hi , Can we use this Crx file and run from Jenkins