Basic Authentication
Created by
Alan Baird.
If you try and visit a site that uses basic authentication, this is the box you will appear. This wont appear in any unit tests, and its difficult to show working code, as we need a site that is secure, and we would need to supply passwords etc.

One way to handle this is using WindowHelper.rb. This script is basically just a wrapper around AutoIt to help you deal with pop ups. The following code to implements this in an example using Test::Unit. Also, since you frequently see the Security Alert dialog along with Basic Authentication, this example deals with this pop up as well. You will need to have two other files, handle_logon.rb and handle_security_alert.rb in the same directory as your main script. These scripts are launched in additional threads to deal with the Basic Authentication pop up and the Security Alert pop up.
One problem with this script is that if you leave the Security Alert pop up thread in-tact and the script does not encounter this dialog box, the script will hang waiting for a Security Alert pop up that will never happen. To correct this, simply remove variable b and the b.join statement from main.rb.
require 'unittests/setup'
require 'watir'
require 'watir/WindowHelper'
class TC_Logon_Test < Test::Unit::TestCase
def setup
@url = 'yoursite.com'
@login_title = "Connect to #{@url}"
@username = 'uname'
@password = 'pass'
end
def test_logon
a = Thread.new {
system("ruby handle_logon.rb \"#{@login_title}\" \"#{@username}\" \"#{@password}\"")
}
b = Thread.new {
system('ruby handle_security_alert.rb')
}
$ie.goto(@url)
a.join
b.join
# continue code here...
end
end
require 'watir'
require 'watir/WindowHelper'
helper = WindowHelper.new
helper.push_security_alert_yes
puts "done with security alert"
require 'watir'
require 'watir/WindowHelper'
# these parameters are passed to the logon method in WindowHelper.rb
login_title = ARGV[0]
username = ARGV[1]
password = ARGV[2]
helper = WindowHelper.new
helper.logon(login_title, username, password)