if expression within a thread

A

aidy

Hi,

I am using Watir and Autoit (win32 test tool)

Here is my code


autoit = WIN32OLE.new("AutoItX3.Control")
t = Thread.new(autoit) {
if autoit.WinWait("Authentication Required", "", 5) ==
1
autoit.Send(username)
autoit.Send("{TAB}")
autoit.Send(password)
autoit.Send("{ENTER}")
end
}
m = Thread.new(self) {self.goto(url)}
m.join; t.join


When a user navigates to a url, an authentication dialog may appear.

If this appears I would like to enter a username and password

If I manually type the url and run this

require 'win32ole'
autoit = WIN32OLE.new("AutoItX3.Control")
autoit.WinWait("Authentication Required", "", 5)

A success of 1 is returned.

I wonder if I can use if expressions in Ruby threads, as the if
block is never executed. Maybe the winwait function in autoit is not
able to thread.

Any ideas, please?

Thanks

Aidy
 
B

Bret Pettichord

[Note: parts of this message were removed to make it a legal post.]

Calls to windows API's will block *all* threads in Ruby. This is why Watir's
click_no_wait method spawns a process and not merely a thread.

Bret

Hi,

I am using Watir and Autoit (win32 test tool)

Here is my code


autoit = WIN32OLE.new("AutoItX3.Control")
t = Thread.new(autoit) {
if autoit.WinWait("Authentication Required", "", 5) ==
1
autoit.Send(username)
autoit.Send("{TAB}")
autoit.Send(password)
autoit.Send("{ENTER}")
end
}
m = Thread.new(self) {self.goto(url)}
m.join; t.join


When a user navigates to a url, an authentication dialog may appear.

If this appears I would like to enter a username and password

If I manually type the url and run this

require 'win32ole'
autoit = WIN32OLE.new("AutoItX3.Control")
autoit.WinWait("Authentication Required", "", 5)

A success of 1 is returned.

I wonder if I can use if expressions in Ruby threads, as the if
block is never executed. Maybe the winwait function in autoit is not
able to thread.

Any ideas, please?

Thanks

Aidy


--
Bret Pettichord
CTO, WatirCraft LLC, http://www.watircraft.com
Lead Developer, Watir, http://wtr.rubyforge.org
Blog (Essays), http://www.io.com/~wazmo/blog
MiniBlog (Links), http://feeds.feedburner.com/bretshotlist
 
A

aidy

Bret,

[Note:  parts of this message were removed to make it a legal post.]

Calls to windows API's will block *all* threads in Ruby. This is why Watir's
click_no_wait method spawns a process and not merely a thread.

Bret

Thanks for getting back

<code>
autoit = WIN32OLE.new("AutoItX3.Control")
m = Thread.new(self) {self.goto(url)}
t = Thread.new(autoit) do
sleep 3
autoit.Send(username)
autoit.Send("{TAB}")
autoit.Send(password)
autoit.Send("{ENTER}")
end
m.join; t.join
</code>

The 'goto' method waits for the page to load.

If winole blocks threads in Ruby then the autoit thread would not get
executed as there is an indefinite wait in the 'goto' method.

Aidy
 
A

aidy

Bret,

[Note:  parts of this message were removed to make it a legal post.]
Calls to windows API's will block *all* threads in Ruby. This is why Watir's
click_no_wait method spawns a process and not merely a thread.

Sorry for cross posting but I spawned this thread on Watir general as
well

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top