[Wtr-general] Application Map
Bret Pettichord
bret at pettichord.com
Fri Apr 28 15:48:57 EDT 2006
On 4/27/06, John Castellucci <johnc at testdev.net> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060428/d8c03f92/attachment.html
More information about the Wtr-general
mailing list