You can pass this information in the URL so the dialog does not pop up. This will allow you to go to these websites with automation tools like Selenium.
For example, if you go to httpwatch and click on the Display Image button it will pop open a dialog asking you for a username and password. For this site you can enter httpwatch for the username and any string for the password. So if I go to:
http://httpwatch:password@www.httpwatch.com/httpgallery/authentication/
then click the Display Image button, it will not pop open a dialog. This is because I have already been authenticated on the website.
HOWEVER, this will not work with current web browsers.
The reason for this is because web browser manufacturers recognized the fact that people can use this URL format to create fake websites. For example, I could have a website at 10.23.56.234, turn on basic authentication and make the username www.microsoft.com. I then send out an email with the URL:
http://www.microsoft.com:80@10.23.56.234/survey.html
This URL will go to my fake website with the username:password of www.microsoft.com:80. Some people might be tricked into thinking they are going to www.microsoft.com.
Fortunately, you can turn this feature back on.
For Internet Explorer you can make it accept the above URLs. It does open you up to someone spoofing you. So do this to a test machine, used only for automation, is okay. Using this on the computer you use to surf the web is a back idea.
For Internet Explorer you can make it accept the above URLs. It does open you up to someone spoofing you. So do this to a test machine, used only for automation, is okay. Using this on the computer you use to surf the web is a back idea.
If you go to http://support.microsoft.com/kb/834489/EN-US it will explain all the above. At the bottom it will talk about how to enable using username:password in the URL. In a nutshell, do the following:
- Open regedit.exe
- Find the key HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
- Create the DWORD iexplore.exe=0
By setting iexplore.exe to 0 you are disabling the disabling of username:password, i.e. double negative.
If you are running 32-bit Windows this works as stated. If you are running 64-bit Internet Explorer on 64-bit Windows this works as stated. However, if you are running 32-bit Internet Explorer on 64-bit Windows this does not work. By default, 64-bit Windows 7 will run 32-bit Internet Explorer.
When you look in the registry, all the settings for 32-bit programs on a 64-bit computer will be in the WOW6432Node. So rather than HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft you want to go to HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft.
For Chrome & Firefox, they should support basic authentication through the URL.
For Safari, go into the Preferences, go to the Security tab and disable Warn when visiting a fraudulent website.
In summary, if I have the Selenium Java code:
driver.get("http://www.httpwatch.com/httpgallery/authentication/");
driver.findElement(By.cssSelector("#displayImage")).click();
WebElement img = driver.findElement(By.cssSelector("#downloadImg"));
It will never make it to the third line because the .click() will bring up an HTTP basic authentication dialog which will block Selenium. Instead, I would use:
driver.get("http://httpwatch:password@www.httpwatch.com/httpgallery/authentication/");
driver.findElement(By.cssSelector("#displayImage")).click();
WebElement img = driver.findElement(By.cssSelector("#downloadImg"));
.
No comments:
Post a Comment