On 4/27/06, John Castellucci <[EMAIL PROTECTED]> wrote:
Bret Pettichord wrote:
>I am thinking of adding a Map class to Watir. Here's how it would work...

I found this an interesting problem, and as it applied to something I was
doing at work, I wanted to give it a stab.  Below is my "hack" at a Map
class.  It only works in Watir 1.5.  So, how many rules did I break?  ;)

Only one: don't complicate things unnecessarily. You can do the same thing directly with Watir itself!
 
# Watir 1.5 ONLY!!!
require 'watir'

module Watir
  class Map
    def initialize(ie)
      @ie = ie
      Watir::Container.instance_methods.each do |method|
        Map.class_eval("def #{method}(k,v); @ie.#{method}(k,v); end") if
method !~/=/
      end
    end
  end
end

ie = Watir::IE.start('http://google.com')
map = Watir::Map.new(ie)

If leave out the Map class and instead do

  map = Watir::IE.start('http://google.com')

the following will still work fine:
 
SearchField = map.text_field(:name, 'q')
SearchButton = map.button(:name, 'btnG')

SearchField.set('PickAxe')
SearchButton.click()

I think the Map idea makes sense when you define it  *before* the IE class has been instantiated. That's the scenario that is a challenge to support.

Bret

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to