I am facing an issue with the Prompt for logging in to the application which uses windows authentication. Using Selenium Web-driver with C# to drive my test automation.
Scenario: I am testing a web application, which is based on windows authentication. My requirement is to test with different windows user (for security/roles based testing). For Chrome browser, I am able to pass the Windows user details (Domain, User name and Password) directly to the URL, which succeeds.
For IE browser, passing the credentials through URL does not work. I tried manually to Prompt login screen (Windows Security) by using Internet Options -> Security -> Zone -> Custom Level -> user Authentication option. It did work.
I am planning to do it through code using registry keys. My code below
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{
long setPrompt = -1;
string regEditKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1";
using (RegistryKey regKeys = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64).OpenSubKey(regEditKey, true))
{
if (regKeys != null)
{
setPrompt = Convert.ToInt64(regKeys.GetValue("1A00"));
if (setPrompt != 65536)
{
regKeys.SetValue("1A00", (object)65536, RegistryValueKind.QWord);
regKeys.Close();
regKeys.Flush();
}
}
}
}
I am trying to invoke the above method before the test execution starts, which should be one time for the entire test run. And set it back to original in the Assembly clean up. The code works fine, it updates the registry key to '65536'. But when I launch IE browser, it does not ask for login credentials, it directly uses my windows credentials.
For reference, Registry Key details document.
Any help would be highly appreciated.
Thanks,
Sham_
EDIT: Update code to include the solution. Issue was a mentioned by @Ron, IExplore was 32-bit. To work on 32-bit IExplore on 64-bit machine. Note: Wow6432Node in the regEditKey string.
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{
long setPrompt = -1;
string regEditKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1";
using (RegistryKey regKeys = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(regEditKey, true))
{
if (regKeys != null)
{
setPrompt = Convert.ToInt64(regKeys.GetValue("1A00"));
if (setPrompt != 65536)
{
regKeys.SetValue("1A00", (object)65536, RegistryValueKind.DWord);
regKeys.Close();
regKeys.Flush();
}
}
}
}