Basic Authentication

1,013 views
Skip to first unread message

aidy lewis

unread,
Aug 12, 2008, 5:55:34 AM8/12/08
to watir-general
Hi,

On this page: http://wiki.openqa.org/display/WTR/Basic+Authentication,
there is a main.rb with this code.

<code>
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

</code>

It uses the system kernel method to run two Ruby files:
handle_logon.rb && handle_security_alert.rb.

I am not sure where these files exist or what they contain?

Aidy

Tim Koopmans

unread,
Aug 12, 2008, 6:31:34 AM8/12/08
to Watir General
They are on the same wiki page, immediately below the main.rb example
=)

Regards,
Tim

aidy lewis

unread,
Aug 12, 2008, 7:23:07 AM8/12/08
to watir-...@googlegroups.com
Tim,

Was early in the morning here:

helper = WindowHelper.new
helper.logon(login_title, username, password)

There doesn't seem to be a timeout on the WindowHelper logon method
and looking at the autoit functions there is no default.

Aidy

2008/8/12 Tim Koopmans <tim....@gmail.com>:

aidy lewis

unread,
Aug 12, 2008, 7:26:12 AM8/12/08
to watir-...@googlegroups.com
Tim,

And I have never got this to work in a Ruby thread

autoit.WinWait title, ""

Has anyone else?

Aidy

2008/8/12 aidy lewis <aidy....@googlemail.com>:

aidy lewis

unread,
Aug 12, 2008, 8:41:52 AM8/12/08
to watir-...@googlegroups.com
Hi,

<code>
autoit = WIN32OLE.new("AutoItX3.Control")
Thread.new(autoit) do
sleep 1
autoit.WinWait("Authentication Required", "")
autoit.Send(username)
autoit.Send("{TAB}")
autoit.Send(password)
autoit.Send("{ENTER}")
end
self.goto(url)
<code>

I think autoit.WinWait executes faster than browser.goto => a hang. We
need a sleep even if it is only for 0.1 secs

I don't think we need to explicitly create another thread for
self.goto as it is already in one.

Aidy

aidy lewis

unread,
Aug 12, 2008, 9:13:09 AM8/12/08
to watir-...@googlegroups.com
Hi,

2008/8/12 aidy lewis <aidy....@googlemail.com>:

Sorry, we don't need to create a thread for browser.goto and .join
because browser.goto(url) will never complete unless the autoit thread
in executed.

Aidy
> Aidy
>

MEDBEDb

unread,
Apr 19, 2013, 5:39:49 AM4/19/13
to watir-...@googlegroups.com, aidy....@googlemail.com
Tried the above, didn't worked... I found a workaround for this - setting the timeout to minimum will do the thing: 

client = Selenium::WebDriver::Remote::Http::Default.new 
client.timeout = 2
b = Watir::Browser.new :firefox, :http_client => client

after this autoit will handle any requests easily.

b.goto url #time outs after 2 seconds and then

autoit = WIN32OLE.new("AutoItX3.Control")
autoit.WinWait("Authentication Required", "")
autoit.WinActivate("Authentication Required", "")
autoit.Send(@user)
autoit.Send("{TAB}")
autoit.Send(@pass)
autoit.Send("{ENTER}")

Voila :)
Reply all
Reply to author
Forward
0 new messages