Josh
Josh

Reputation: 175

Automating authentication with Watir

I've searched and searched for this, but I can't seem to get this automation to work. Having used all of the basic authentication code on the OpenQA site, I still cannot get the authentication box to work.

I'm using IE8, with a website that has HTTPS enabled.

By using Watir I'm able to open IE to the correct page, but nothing I try allows me to enter any content into the login form.

Here is the code I've whittled it down to:

require 'watir'

url = 'https://thewebsite.com' 
@username = 'myusername'
@password = 'mypassword' 

browser = Watir::Browser.new
browser.goto url
sleep 5 
Watir.autoit.WinWait('Blank Page')
Watir.autoit.Send(@username)
Watir.autoit.Send('{TAB}')
Watir.autoit.Send(@password)
Watir.autoit.Send('{ENTER}')

Does anyone have any suggestions, or links? A lot of the information I've found on the OpenQA site seems quite out of date.

Thanks

Upvotes: 3

Views: 2062

Answers (3)

Stuart Brock
Stuart Brock

Reputation: 3892

I came here having the same problem, although it looks like the answer is different due to the latest version of Watir and watir-webdriver. I'll show what worked for me using:

watir (4.0.2 x86-mingw32)
watir-classic (3.6.0)
watir-webdriver (0.6.2)

Watir doesn't have autoit built in any more and it looks like the other suggestion I found (require 'watir/ie') doesn't work any more either. In the spirit of solving this with the original tech requested:

Make sure after installation AutoIT has been registered with windows. Go to the AutotIT dll (installed with the rautomation gem mentioned above, think Watir installed this)

cd C:\Ruby193\lib\ruby\gems\1.9.1\gems\rautomation-0.8.0\ext\AutoItX
regsvr32 AutoItX3.dll

Then the code below should work

require 'watir'
require 'win32ole'

$b = Watir::Browser.new :ie
begin
    $b.goto( 'http://10.254.157.34:8383/mywebsite/stuff.html');
rescue Exception => e
    puts "Trapped Error, expecting modal dialog exception"
    puts e.backtrace 
    puts "Continuing"
end

login_title = "Windows Security" #For Windows 7, dialog title for anything else
username = "myuser"
password = "mypassword"

sleep 1 #Just in case
au3 = WIN32OLE.new("AutoItX3.Control")
win_exists = au3.WinWait(login_title, "", 5)    

if (win_exists > 0)
    au3.WinActivate(login_title)
    au3.Send('!u')
    au3.Send(username)
    au3.Send('{TAB}')
    au3.Send(password)
    au3.Send('{ENTER}')
end

Upvotes: 0

astro2linus
astro2linus

Reputation: 11

Have you tried using the url with user and pass in it? like url = 'https://username:[email protected]', you can try visiting the url manually in a browser, if it works manually it should work in your script too.

Upvotes: 0

Željko Filipin
Željko Filipin

Reputation: 57312

Did you try RAutomation instead of autoit?

Upvotes: 1

Related Questions