Running Script in Multiple Threads

73 views
Skip to first unread message

Dhrubojyoti Biswas

unread,
Jul 30, 2007, 10:13:42 AM7/30/07
to watir-...@googlegroups.com
We have our custom automation framework in which we use a lot of scripts which are written in WATIR 1.4.
 
Additionally we have a script despatcher that is written in Java. This despatcher creates multiple Java Threads and runs WATIR 1.4 scripts in each of these threads.
 
Recently, we tried running/porting these scripts against WATIR 1.5. We also started using the no_wait method which would allow us to take care of security dialogs and other popups.
 
But as soon as we did that our scripts started hanging up whenever a popup comes.
 
Does the function in the latest WATIR version which clears Security Dialog PopUps use threads internally?
 
Some help/comment on this would be a lifesaver for us.
 
Thanx.
 
--
Dhruv

Russ DeWolfe

unread,
Jul 30, 2007, 10:52:34 AM7/30/07
to watir-...@googlegroups.com
This is an example of the only version of this script I have found to work (gives some pause as it works, so be patient):
 
#~ Begin: Method  #########################################################
def openWebsite(test_site)
    puts "  Action: Open Internet Explorer and go to the test site: " + test_site
#handles IE6 Security alert    
    #start 2 threads so, if the Security alert dialog appears, Ruby will be able to close it
    t = Thread.new(){
  begin
     wc = WinClicker.new
   hwnd = wc.getWindowHandle("Security Alert")
   if(hwnd == -1) then
   num = 0
        while( num < 1)
          hwnd = wc.getWindowHandle("Security Alert")
          num = num + 1
        end
   end
   if(hwnd != -1) then
    wc.clearSecurityAlertBox()
      end
      rescue => e
   handleFail e
  end
    }
   
    ie=Watir::IE.new()
 
    m = Thread.new(ie){
    ie.goto(test_site)
    ie.set_fast_speed
    }
 
    m.join
    t.join
 
#handles IE7 Security alert
  if ie.contains_text("Continue to this website (not recommended).")
    ie.link(:text, "Continue to this website (not recommended).").click
    puts    "Action: Click Continue to this website link because of test cert"
    end
 
    ie.maximize
    ie.bring_to_front
    return ie 
end
#~ End: Method  #########################################################


From: watir-...@googlegroups.com [mailto:watir-...@googlegroups.com] On Behalf Of Dhrubojyoti Biswas
Sent: Monday, July 30, 2007 9:14 AM
To: watir-...@googlegroups.com
Subject: [wtr-general] Running Script in Multiple Threads

Dhrubojyoti Biswas

unread,
Jul 30, 2007, 11:09:54 AM7/30/07
to watir-...@googlegroups.com
Hi Russ,
 
Thanx for your quick response.
 
But did u ever try to invoke this script within a thread itself.
 
What I mean is that... lets say your code snippet lies in a file called xyz.rb.
 
Now you have multiple such test scripts around and what u want to do is despatch each of these scripts in separate threads all at once.
 
Further lets say that u're script despatch code is in Java (given that Java has good thread support).
 
My question was is it safe/allowable to run a multi-threaded code (as your current implementation below is) inside another thread?
 
I am completely foxed at this and am not sure how to proceed as I cannot find any reason why our scripts that contain code to handle popups freezes when run within Java Threads/LWPs.
 
Some light on this would be gr8.
 
--
Dhruv

 

Russ DeWolfe

unread,
Jul 30, 2007, 11:25:42 AM7/30/07
to watir-...@googlegroups.com
Well over my head, if I can find out something from a programmer, I will let you know.


From: watir-...@googlegroups.com [mailto:watir-...@googlegroups.com] On Behalf Of Dhrubojyoti Biswas
Sent: Monday, July 30, 2007 10:10 AM
To: watir-...@googlegroups.com
Subject: [wtr-general] Re: Running Script in Multiple Threads

Ubaldo Villaseca

unread,
Jul 30, 2007, 10:41:03 PM7/30/07
to watir-...@googlegroups.com
First of all I found that WinClicker has some defects, as any non
stable code, but easy to fix. If you have strange things happening
check WinClicker.
In the other hand I suggest you to have a win32 call in charge of
close any popup. The following code close any window with the given
popupTitle using WinClicker, Ruby, and standard win32 calls like
PostMessage (http://msdn2.microsoft.com/en-us/library/ms644944.aspx):

wc = WinClicker.new
popupTitle = /Windows Internet Explorer/
hwnd = wc.getWindowHandle(popupTitle)
user32 = DL.dlopen("user32")
postMessage = user32['PostMessage', 'ILILL']
postMessage.call(hwnd, 0x0010, 0, 0)

An improvement would be getting all IE children of type popup and then
close them using a win32 call like EnumChildWindows.

Dhrubojyoti Biswas

unread,
Jul 31, 2007, 3:14:29 AM7/31/07
to watir-...@googlegroups.com
Thanx Ubaldo.
 
I'll try out your suggestions.
 
--
Dhruv

 

Bret Pettichord

unread,
Jul 31, 2007, 6:41:27 PM7/31/07
to watir-...@googlegroups.com
Dhrubojyoti Biswas wrote:
> My question was is it safe/allowable to run a multi-threaded code (as
> your current implementation below is) inside another thread?
>
> I am completely foxed at this and am not sure how to proceed as I
> cannot find any reason why our scripts that contain code to handle
> popups freezes when run within Java Threads/LWPs.
>
> Some light on this would be gr8.
The short answer is no. The winclicker code is not thread-safe.

Bret

Paul Rogers

unread,
Jul 31, 2007, 7:43:07 PM7/31/07
to watir-...@googlegroups.com
to expand on what Bret said, tehe winclicker looks for windows that have a certain title and are of a certain type.
If you have multiple browsers I dont think there is anyway to easily tell if apopup belongs to a certain browser.
If its only javascript alerts that you are doing, then you could modify winclicker to just click any that it sees
If its something like a file download, then you really are in trouble - as we would need to give focus before filling in the fields, and that is likely to be problematic when there are potentially several of them being displayed

Paul
Reply all
Reply to author
Forward
0 new messages