Re: [Wtr-general] Controlling IE popups with stock Watir: simplest way?

2007-05-19 Thread Brian Marick
I played around with win32-utils code, but I was getting odd results.  
(It appeared that the fork() was really exec()ing the program in a  
subprocess, rather than continuing the subprogram from the point of  
the fork.) So I went back to popen.

I ran into a further problem. One button press would generate two  
confirmation dialogs, one after the other, without control returning  
to Watir between them. So I needed to invent some new syntax. I'm not  
wildly fond of it, but it works. It looks like this:

$ie.after {
   button(:name, action).click
}.dismiss_windows(
 Choose a digital certificate = [{Tab}, {Space}],
 Signing = [{Space}]
   )

Code below. I should write tests for it. Realistically, though, I  
won't have time to be a good submitter for the near future. I have to  
learn both Rails and Selenium next week for a different client, and  
I'll be going flat out for at least all of June.

This code should probably invoke the watcher scripts using ruby -S.  
Right now, it assumes the watcher script is in the same directory as  
the test, which is sloppy.

===


class IE
   def after(block)
 @block = block
 self
   end

   def grab_window(window_title)
 @window_title = window_title
 self
   end

   def and_send(*keys)
 launch_watcher(@window_title, keys)
 continue_script(@block)
   end


   def dismiss_windows(hash)
 hash.each do | title, keys |
   launch_watcher(title, keys)
 end
 continue_script(@block)
   end

   private

   def launch_watcher(window_title, keys)
 commandline = [/ruby/bin/ruby,
   watcher-popen.rb,
   ' + window_title + '] +
   keys
 IO.popen(commandline.join(' '))
   end

   def continue_script(block)
 instance_eval(block) if block
   end

end

 watcher.rb =

require 'watir'

# Do this in JMock style, just because DSLs are all the rage.

class Watcher

   private_class_method :new

   def self.after_seeing(title)
 new(title)
   end

   def initialize(title)
 @autoit = Watir.autoit
 @title = title
   end

   def send(keys)
 @keys = keys
 do_await_window
 do_send_keys
 self
   end

   private

   def do_await_window
 @autoit.WinWait @title, 
   end

   def do_send_keys
 @keys.each do | key |
   sleep 1  # Just to watch it happen.
   @autoit.Send key
 end
   end

end

if $0 == __FILE__
   title = ARGV[0]
   keys = ARGV[1..-1]
   # $stderr.puts title, keys.inspect; $stderr.flush

   Watcher.after_seeing(title).send(keys)
end


-
Brian Marick, independent consultant
Mostly on agile methods with a testing slant
www.exampler.com, www.exampler.com/blog


___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


Re: [Wtr-general] Controlling IE popups with stock Watir: simplest way?

2007-05-17 Thread Brian Marick

On May 16, 2007, at 11:43 PM, Bret Pettichord wrote:
 3. Have the parent process spin, waiting for that file to be created,
 then continue.

 I wonder whether this is really what is happening. My guess is that it
 is blocked...
 [...]
 I don't think you actually need to have the file polling system. The
 reason why is that the click method will not return until the  
 dialog has
 been closed. So you don't need a second synchronization method.

Well duh. Removing the creation of, and checking for, the sentinel  
file certainly seems to work as you describe. Much cleaner.

 Like i said these win32utils seem to provide everything you need and
 wrap a lot of the win32api nonesense, so you really would be better
 looking at that.

I'll check it out. The only advantage over using popen is that you  
don't have to have an executable ruby file (and know where to find  
it). You can just require a watcher file and do the work without any  
implicit or explicit exec.


-
Brian Marick, independent consultant
Mostly on agile methods with a testing slant
www.exampler.com, www.exampler.com/blog


___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general