Thursday, September 12, 2019

Post#28.Handle Basic Authentication Pop Up


Handling Authentication Popup Window:

What is Authentication Popup window and why these Authentication Popup windows showed up while opening few websites.



Authentication popup window looks like the below mentioned image.



Companies have their own proxy settings to access some servers. If you open a server in the browser a popup window will load and force you to enter user credentials to do login to access the server. Even while accessing the same server using selenium script we need to handle the popup before hand accessing the server. If we can’t handle this, we couldn’t do further testing.

Approach 1: Handling Authentication/Login Popup Window using Selenium WebDriver

By passing user credentials in URL. Its simple, append your username and password with the URL.

e.g., http://Username:Password@SiteURL

Approach 2: Handling Authentication/Login Popup Window using Selenium WebDriver

By using AutoIt, we could handle authentication pop up. We will discuss it later.

Let's handle it by Approach 1 for below authentication pop up.




Java Code:

package pack2;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenWebSite
{
             
              public static void main(String[] args) throws Exception
              {
System.setProperty("webdriver.gecko.driver", "D:\\BrowserDrivers\\geckodriver.exe");
                             WebDriver driver=new FirefoxDriver();

                             // tries to open application
                             driver.get("https://admin:admin@the-internet.herokuapp.com/basic_auth");
                             //here 1st admin is user name and 2nd one is password
              }
}


No comments:

Post a Comment