Thanks, Oscar!

This is all good food for thought.

On Friday, April 6, 2012 7:37:42 AM UTC-7, Oscar.Rieken wrote:
>
> As long as the object you are returning is still a kind of watir object 
> then you should have the .click method for it
>
>
> you can also check out how taza does it it allows you to do something 
> similar to
>
> page.rb
> element(:the_li_I want){ |name| browser.li(:text => name)}
> element(:some_button_for_my_li) { |name| the_li_I_want(name).button(:title 
> => "open")
>
> in my test
> page.some_button_for_my_li(the_li_name).click
>
> On Fri, Apr 6, 2012 at 6:14 AM, Jarmo Pertman <jarm...@gmail.com> wrote:
>
>> Yes, you can. It's Ruby :)
>>
>> You could do something like this:
>> def document(name)
>>  li = @browser.li(:text=>name)
>>  def li.open; li.button(:title=>"open").click end
>>  li
>> end
>>
>> It's not too beautiful. You could apply some clever meta-programming
>> to make it look better and implement these methods easier.
>>
>> If you'd use WatirSplash and its Page Objects then this support would
>> be already built in. I have written a blog post about WatirSplash Page
>> Objects where this is demonstrated:
>>
>> http://itreallymatters.net/post/12242886944/awesome-page-objects-in-testing
>>
>> If you're being nice then you can also "steal" the code, which would
>> give you the same support.
>>
>> I might release that Page Object support as a separate gem maybe, but
>> not sure yet.
>>
>> Jarmo
>>
>> On Apr 6, 4:10 am, Abe Heward <abe.hew...@gmail.com> wrote:
>> > I hesitate to ask this question because I feel like the answer will end 
>> up
>> > being blindingly obvious or else horribly complicated. Plus, I suppose 
>> it's
>> > more of a Ruby question than a Watir one.  I'll ask it anyway...
>> >
>> > I have a page that has a list of documents on it. You can do typical 
>> things
>> > to these documents--open, copy, delete... etc.
>> >
>> > Currently, I have a page class I've created with custom methods that 
>> look
>> > something like this:
>> >
>> > def open(name)
>> >   @browser.li(:text=>name).button(:title=>"open").click
>> > end
>> >
>> > So when I instantiate the page's class my test scripts look, for 
>> example,
>> > like this:
>> >
>> > library.open "file.txt"
>> >
>> > What I'm wondering, though, is if it's a simple matter to create a
>> > class/method structure that would allow code that would, instead, look 
>> like
>> > this:
>> >
>> > library.document("file.txt").open
>> >
>> > I thought I had a way to do this, but--in retrospect not surprisingly--I
>> > get an undefined method error because the class of the 
>> document("file.txt")
>> > object is Watir::LI. Duh.
>> >
>> > Still, it seems like if there's a simple way to do this it would DRY up 
>> my
>> > code quite a bit.
>> >
>> > Thanks for reading!
>>
>> --
>> Before posting, please read http://watir.com/support. In short: search 
>> before you ask, be nice.
>>
>> watir-general@googlegroups.com
>> http://groups.google.com/group/watir-general
>> watir-general+unsubscr...@googlegroups.com<http://groups.google.com/group/watir-general%0awatir-general+unsubscr...@googlegroups.com>
>>
>
>

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to