• Disclaimer

Developer Concepts

Monthly Archives: November 2014

You are browsing the site archives by month.

Automating NTLM logins with Selenium

November 21, 2014 3:07 pm / Steve

We have been automating the testing of our application using Selenium and TeamCity to automate the testing of an application we are developing. One of the challenges we have come across is how to automate logging on the test users when the application use NTLM authentication.

 

Problem:

Authentication_popup
Since the windows is not part of a web page but a separate window attached to the main firefox window, we can use a selenium to log in.

Solution:

uspy

 

To get around this issue, we used USpy to find out details about the Form. To do this see the screenshot above. We found the firefox window, selected that, found the authentication popup and selected the username textbox.

After that it became a little bit trickier. Using the UI automation framework and ATU_Handler we were able to send text to the textboxes and click the button.

Here is the code we used:

private void LogUserIn(string username, string password)
{
    WindowsHandler handler = new WindowsHandler();
    AutomationElement window = null;
    for (int i = 0; i < 20; i++)
    {
        try
        {
            // This works by selecting user name then pressing tab to get to other elements
            window = handler.FindWindowByName("Mozilla Firefox");
            AutomationElement authWindow = handler.GetElementByName(window, "Authentication Required");
            AutomationElement element = handler.GetElementByName(authWindow, "User Name:");
            handler.SendTextUsingUIAutomation(element, username);
            handler.SendTextUsingUIAutomation(element, char.ConvertFromUtf32(9));
            handler.SendTextUsingUIAutomation(element, password);
            handler.SendTextUsingUIAutomation(element, char.ConvertFromUtf32(9));
            handler.SendTextUsingUIAutomation(element, char.ConvertFromUtf32(32));
            break;
        }
        catch
        {
            //Do nothing
        }
        Thread.Sleep(1000);
    }
}

This works well up to the point that you cant click away when debugging this code since it wont focus on the textbox again. The other issue is that we battled to get it to find the password textbox and button. To fix this we send the tab command and the spacebar command to click the button.

This is based on a Blog post we found: http://automationtestingutilities.blogspot.co.uk/p/handling-windows-authentication.html

The Utilities can be found here: https://drive.google.com/folderview?id=0B7rZvkq9tkwPRmp5UG9DMUlJVDA&usp=sharing

Posted in: Selenium / Tagged: NTLM, Selenium

Recent Posts

  • Unrecognized element folderLevelBuildProviders
  • Using Javascript to Load Blog Posts From WordPress
  • An introduction to KnockoutJS Observables
  • Automating NTLM logins with Selenium
  • KnockoutJS and Web API

Recent Comments

    Archives

    • July 2015
    • April 2015
    • March 2015
    • November 2014
    • October 2014
    • June 2014
    • May 2014
    • March 2014
    • February 2014
    • November 2013
    • August 2013
    • January 2013
    • November 2012
    • May 2012
    • September 2011
    • July 2011
    • May 2011
    • March 2011
    • November 2010
    • September 2010
    • February 2010
    • December 2009
    • November 2009
    • October 2009

    Categories

    • Architecture
    • Caching
    • Code Smells
    • Html 5
    • IOC
    • Javascript
    • Jquery
    • JSON
    • KnockoutJS
    • Linq
    • Linq To Xml
    • Mocking
    • MVC
    • MVVM
    • MySql
    • NHibernate
    • Selenium
    • Silverlight
    • Solving Errors
    • Sql
    • TDD
    • Uncategorized
    • Unit Testing
    • Visual Studio 2010
    • WCF

    Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    © Copyright 2018 - Developer Concepts
    Infinity Theme by DesignCoral / WordPress