Thanks, Jarmo! I think I'll have to take a closer look at WatirSplash this weekend.
On Friday, April 6, 2012 3:14:14 AM UTC-7, Jarmo Pertman 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