Wednesday, June 17, 2015

Passing values to a "Authentication Required" alert box on selenium automation

Below is a sample "Authentication Required" alert box which we need to pass values.
In standard selenium automation we cant find the elements on "Authentication Required" alert directly, there for we cant communicate with the alert box and our test case will fail.Because cant move ahead without giving the correct credentials to the  "Authentication Required" alert box.
There are several defendant methods which are widely use in java and .net .Some methods might not successfully work based on the development framework or the selected web driver.

I will be given a easy way to pass values to Authentication alert box in .net development framework.
To do this we need to have a 3rd party library called "AutoItX3.dll".Download the latest EXE from here,().
  1. Install the AutoIt.exe and keep the installed location in your mind in order to get the AutoItX3.dll as a reference to our project in latter part of this article.
  2. In your selenium project create a separate class to do all the steps in order to handle the  "Authentication Required" alert box.
  3. Add the AutoItX3.dll as a reference to the selenium project.(as default this dll file will be available under the (C:\Program Files (x86)\AutoIt3\AutoItX ).
  4. Use the reference by adding the namespace "using AutoItX3Lib" at the top of the class.
  5. Now by using AutoIt.dll we can communicate with the "Authentication Required" alert box using below piece of code.

     var AutoIT = new AutoItX3();
     IWebDriver driver = new FirefoxDriver();
     Thread.Sleep(1000);
     driver.Url ="your desired wep page url/default.aspx";//required web page.
    //Wait for the authentication window to appear, then send username and password
     AutoIT.WinWait("Authentication Required");
     AutoIT.WinActivate("Authentication Required");
     AutoIT.Send("chathura");//username
     AutoIT.Send("{TAB}");//TAB key on the key board
     AutoIT.Send("Welcome@123");//password
     AutoIT.Send("{ENTER}");//enter key on the key board.
  6. Now user will directed to the required web page with the given credentials.

No comments:

Post a Comment