SDET- QA Automation Techie

Software Testing Blog

  • Home
  • Training
    • Online
    • Self-Paced
  • Video Tutorials
  • Interview Skills
    • HR Interview Questions Videos
    • Domain Knowledge
  • Career Guidance
  • Home
  • Software Testing
    • Manual Testing Tutorials
    • Manual Testing Project
    • Manaul Testing FAQS
    • ISTQB
    • AGILE
  • Web Automation Testing
    • Java Programmng
    • Python Programmng
    • Selenium with Java
    • Selenium with Python
    • Robot Framework(Selenium with Python)
    • selenium with Cucumber
    • TestNG+IntelliJ
    • Mobile App Testing(Appium)
    • JMeter
  • API Automation Testing
    • Rest Assured API Testing (BDD)
    • Rest Assured API Testing (Java+ TestNG)
    • Robot Framework(Rest API Testing with Python)
    • Postman
    • SoapUI
    • API Testing(FAQ's)
  • SDET|DevOps
    • Continuos Integration
    • SDET Essentials
    • AWS For Testers
    • Docker
  • SQL
    • Oracle(SQL)
    • MySQL for Testers
    • NoSQL
  • Unix/Linux
    • UNIX TUTORIALS
    • Linux Shell Scripting
  • ETL Testing
    • ETL Data warehouse Tutorial
    • ETL Concepts Tools and Templates
    • ETL Testing FAQ's
    • ETL Testing Videos
  • Big Data Hadoop
  • Video Tutorials
  • ApachePOI Video Tutorials
  • Downloads
    • E-Books for Professionals
    • Resumes
  • Automation Essencials
    • Cloud Technologies
      • Docker For Testers
      • AWS For Testers
      • Sub Child Category 3
    • Java Collections
    • Selenium Locators
    • Frequently Asked Java Programs
    • Frequently Asked Python Programs
    • Protractor
    • Cypress Web Automation

Handling Authentication Window with WebDriver (In Firefox, Chrome and IE)

 Chrome and IE), Handling Authentication Window with WebDriver (In Firefox   

When you are working in a test environment, Stage or Pre Production, there are cases where you may need to work with applications which are secured with Authentication (Basic Auth).
When ever you enter the URL, it will prompt you to enter the User name and the password and It will not allow to perform any further operations until you provide username and password. And this Authentication pop-up is not a JavaScript pop-up, it is a Browser dialog window which selenium cannot handle simply using sendKeys method which we do for normal JavaScript pop-ups..


To work with Basic Authentication pop-up (which is a browser dialogue window), you just need to send the user name and password along with the application URL.
Syntax:
driver.get("http://admin:admin@yoururl.com");

Check out the example below to execute in Firefox browser:

@Test
 public void testBasicAuth_Firefox() {

  WebDriver driver = new FirefoxDriver();
  driver.manage().window().maximize();
  driver.get("http://admin:admin@yoururl.com");
  //To check if we have landed in the correct place
  String text = driver.findElement(By.className("home")).getText();
  Assert.assertTrue(text.contains("Welcome"), "Basic Authentication failed");

 }

Check out the example below to work with Chrome browser:

@Test
 public void testBasicAuth_Chrome() {

  System.setProperty("webdriver.chrome.driver", "G:/Jars/chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  driver.manage().window().maximize();
  driver.get("http://admin:admin@yoururl.com");
  //To check if we have landed in the correct place
  String text = driver.findElement(By.className("home")).getText();
  Assert.assertTrue(text.contains("Welcome"), "Basic Authentication failed");
 }
The best way to make it work with IE is using AutoIt tool. If not, you may need to change the stuff in registry, To change for the current user, you need to edit in 'HKEY_CURRENT_USER...' and if you want to do that for all users, you can set the value of register keys as 'HKEY_LOCAL_MACHINE...' etc.
Once you open the URL in IE it will look like the below screen shot: -
Basic authentication in IE using Selenium

Check out the example to work with IE using AutoIt tool.

First create AutoIt script as below and save it as basicauth.au3
; To pass user name and password
WinWaitActive("Windows Security")
Send("admin")
Send("{TAB}")
Send("admin")
Send("{ENTER}")
After creating the above AutoIT script, compile the script and take the location of the script exe file. Now the selenium code should look like below :
@Test
 public void testBasicAuth_IE() {
  DesiredCapabilities caps = DesiredCapabilities.internetExplorer();   
  caps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "");

  System.setProperty("webdriver.ie.driver", "G:/Jars/IEDriverServer.exe");
        WebDriver driver=new InternetExplorerDriver(caps); 
  driver.manage().window().maximize();
  driver.get("http://yoururl.com");
  try {
   Runtime.getRuntime().exec("G:/basicauth.exe");
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home
popup

Popular Posts

  • How To Explain Project In Interview Freshers and Experienced
    “ Describe an important project you’ve worked on ” is one of the most common questions you can expect in an interview. The purpose of a...
  • MANUAL TESTING REAL TIME INTERVIEW QUESTIONS & ANSWERS
    1. How will you receive the project requirements? A. The finalized SRS will be placed in a project repository; we will access it fr...
  • API/Webservices Testing using RestAssured (Part 1)
    Rest Assured : Is an API designed for automating REST services/Rest API's Pre-Requisites Java Free videos: https://www.you...

Facebook Page

Pages

  • Home
  • Resumes
  • Job Websites India/UK/US
  • ISTQB
  • Selenium with Java
  • E-Books for Professionals
  • Manual Testing Tutorials
  • Agile Methodology
  • Manual Testing Projects

Live Traffic

YouTube


Blog Visitors

Copyright © SDET- QA Automation Techie | Powered by Blogger
Design by SDET | Blogger Theme by | Distributed By Gooyaabi Templates