Re: [Wtr-general] New Watir User Guide (beta)

2007-05-19 Thread Željko Filipin

On 5/18/07, Chris McMahon [EMAIL PROTECTED] wrote:


include Watir  (it's magic anyway, it won't hurt)
ie = IE.new (let people see a blank browser)



I have just checked my test suite, and I have only one

ie = Watir::IE.new

After that i just use ie variable. I guess that others may have different
usage pattern for this.

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

Re: [Wtr-general] New Watir User Guide (beta)

2007-05-19 Thread jim_matt
I do the same sort of thing now except that I normally do

$br = Water::IE.new

in one place.  I do this for the time I might want to point $br to FireFox and 
run the same script with it.

Jim Matthews
  - Original Message - 
  From: Željko Filipin 
  To: wtr-general@rubyforge.org 
  Sent: Saturday, May 19, 2007 1:41 AM
  Subject: Re: [Wtr-general] New Watir User Guide (beta)


  On 5/18/07, Chris McMahon [EMAIL PROTECTED] wrote:
include Watir  (it's magic anyway, it won't hurt)
ie = IE.new (let people see a blank browser)

  I have just checked my test suite, and I have only one 


  ie = Watir::IE.new

  After that i just use ie variable. I guess that others may have different 
usage pattern for this.

  Zeljko



--


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

Re: [Wtr-general] New Watir User Guide (beta)

2007-05-19 Thread jim_matt
Since I now normally do a separate 

$br = Watir::IE

I do a '.new' and then a 'goto' elsewhere.  In this case it brings up 
'about:blank' and does not have to wait for a lot of junk to load.  If you are 
not on a LAN that has access to WWW, then you will wait a long time for 
http://www.google.com.

Jim


  - Original Message - 
  From: Željko Filipin 
  To: wtr-general@rubyforge.org 
  Sent: Saturday, May 19, 2007 1:45 AM
  Subject: Re: [Wtr-general] New Watir User Guide (beta)


  On 5/18/07, Chris McMahon [EMAIL PROTECTED] wrote:
ie = IE.new (let people see a blank browser)
ie.goto(http://www.google.com;)

  I have been thinking about this again. Do you ever do something with an empty 
browser? Every time I open a browser, I immediately go to a web page. I am 
thinking in changing it back to 


  ie = Watir::IE.start(http://www.google.com;)

  Zeljko



--


  ___
  Wtr-general mailing list
  Wtr-general@rubyforge.org
  http://rubyforge.org/mailman/listinfo/wtr-general___
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-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-19 Thread Chris McMahon
You might be interested in my venerable Perl controller below.  It
launches a ruby script using system(1,), which returns control to the
calling process.  A short explanation of how system() does this is
here: http://perlmonks.org/?node_id=547218



use warnings;
use strict;
use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendKeys );

my $x = 0;

system (1, ruby c:/myscript.rb);
while (1) { #INFINITE LOOP
sleep 2; #CHECK FOR NEW WINDOW EVERY 2 SEC
my @windows = FindWindowLike(0, ^Logon Right Here);
for (@windows) {
SetForegroundWindow($_); #BRING THE RIGHT WINDOW IN FOCUS JUST IN CASE
SendKeys(user);
SendKeys({TAB});
SendKeys(password);
SendKeys({ENTER});
$x = 1;
}
exit if $x == 1;
}
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general