From esh at qualitytree.com Tue Oct 18 07:59:19 2005 From: esh at qualitytree.com (Elisabeth Hendrickson) Date: Tue, 18 Oct 2005 04:59:19 -0700 Subject: [Wtr-core] late binding is very cool! Message-ID: Greetings all! I was going to drop Bret a private note, then I realized that this is just the sort of message that ought to go on the wtr-core list... Bret: huge thanks for late binding! Everyone else: here's what I mean... Back at the Agile conference in August, I showed Bret some code I'd been working on that enabled me to create much more maintainable Watir scripts. One of the keys to improving maintainability is to isolate the literal field names. That way if "j_username" ever becomes "username," you only have to make the change in one place. One common approach is to use constants like so: USERNAME = "j_username" ie.text_field(:name, USERNAME) But I wanted to take it further. I wanted to be able to say: username_field = ie.text_field(:name, "j_username") It didn't work. If the field wasn't on the current page when the declaration statement was executed, Watir threw an exception when I tried to use the username_field variable to do anything. To make this work, I ended up creating classes for all the form objects that wrapped the Watir classes. When I explained what I wanted to Bret, he said, "Oh. You want late binding. Yeah, I can do that." Well, I've started playing with the latest build, and sure enough, late binding works, at least for text fields, select lists, buttons, and frames. I still have more playing to do, but I can see that there's lots of code I won't have to write next time I do a major Watir project. Less code == more good! By the way, my next big Watir/Ruby project starts in a couple weeks, and there's a good shot that I'll be doing another one in a couple months. So thank you thank you thank you thank you! Elisabeth --------------------------- Elisabeth Hendrickson Quality Tree Software, Inc. http://www.qualitytree.com --------------------------- From esh at qualitytree.com Tue Oct 18 08:25:29 2005 From: esh at qualitytree.com (Elisabeth Hendrickson) Date: Tue, 18 Oct 2005 05:25:29 -0700 Subject: [Wtr-core] Request: consistent set methods Message-ID: I have a request: can all form entity types support a set method that takes a parameter? Let me explain why I want this: In my last message, I mentioned that I wrote classes to wrap all the Watir form object classes because I was concerned about maintainability. That wasn't the only reason. I also found I needed a consistent interface for setting values in fields. I'm hoping to make this reason go away too. Let me explain further... I can fill out forms with a bunch of procedural statements: ie.select_list(:id, "user_type").select("Admin") ie.text_field(:name, "username").set("my_new_user") ie.text_field(:name, "password").set("my_password") ie.text_field(:name, "fullName").set("J. Random User") ie.checkbox(:name, "roles", "rolename=admin").set And I can refactor by creating variables to reference the fields, like so: user_type = ie.select_list(:id, "user_type") user_name = ie.text_field(:name, "username") password = ie.text_field(:name, "password") full_name = ie.text_field(:name, "fullName") admin_role = ie.checkbox(:name, "roles", "rolename=admin") And then I can write my script as: user_type.select("Admin") user_name.set("my_new_user") password.set("my_password") full_name.set("J. Random User") admin_role.set That's lovely. But what I REALLY want to be able to do is create a data structure like this: my_new_user_data = { :user_type => "Admin", :user_name => "my_new_user", :password => "my_password", :full_name => "J. Random User", :admin_role => TRUE } And then use a single method to iterate through the keys in the hash to set the fields set_form_values(my_new_user_data) set_form_values is a method that lives in a page class, like so: def set_form_values(values_hash) for field_id in values_hash.keys if @form_objects.has_key?(field_id) @form_objects[field_id].set(values_hash[field_id]) else raise "Field '" + field_id.to_s + "' not in Form Objects" end end end And each page has a map of the form elements it contains, the @form_objects instance variable that looks like: @form_objects = { :user_type => ie.select_list(:id, "user_type"), :user_name => ie.text_field(:name, "username"), :password => ie.text_field(:name, "password"), :full_name => ie.text_field(:name, "fullName"), :admin_role => ie.checkbox(:name, "roles", "rolename=admin") } This means that my test scripts just worry about the data, and the logic to fill out the form is isolated in a single location. The problem now is that I have to special case all the different form element types...if it's a select field, call "select"; if it's a checkbox, call set with no parameter, etc. Ick. I'd much rather call a standard interface, set(value). Many many thanks...and sorry I don't have time to contribute this code myself...(soon, soon...) Elisabeth --------------------------- Elisabeth Hendrickson Quality Tree Software, Inc. http://www.qualitytree.com --------------------------- From bret at pettichord.com Thu Oct 20 00:22:12 2005 From: bret at pettichord.com (Bret Pettichord) Date: Wed, 19 Oct 2005 23:22:12 -0500 Subject: [Wtr-core] Request: consistent set methods In-Reply-To: Message-ID: <5.1.0.14.2.20051019231930.035292d0@pop.gmail.com> I like this suggestion. One thing that would really help would be a list of the methods and a description of what the set method should do if there is the possibility of any ambiguity. If the list doesn't cover all controls, that is ok with me, but it sounds like you have thought this through and may have a longer list than simply those controls mentioned in your note here. It would be great to see this written up as a feature request. My guess is that there are some people who would like to contribute, but would like some guidance as to what they might do. True? Bret At 07:25 AM 10/18/2005, Elisabeth Hendrickson wrote: >I have a request: can all form entity types support a set method that takes >a parameter? > >Let me explain why I want this: > >In my last message, I mentioned that I wrote classes to wrap all the Watir >form object classes because I was concerned about maintainability. That >wasn't the only reason. I also found I needed a consistent interface for >setting values in fields. I'm hoping to make this reason go away too. > >Let me explain further... > >I can fill out forms with a bunch of procedural statements: > >ie.select_list(:id, "user_type").select("Admin") >ie.text_field(:name, "username").set("my_new_user") >ie.text_field(:name, "password").set("my_password") >ie.text_field(:name, "fullName").set("J. Random User") >ie.checkbox(:name, "roles", "rolename=admin").set > >And I can refactor by creating variables to reference the fields, like so: > >user_type = ie.select_list(:id, "user_type") >user_name = ie.text_field(:name, "username") >password = ie.text_field(:name, "password") >full_name = ie.text_field(:name, "fullName") >admin_role = ie.checkbox(:name, "roles", "rolename=admin") > >And then I can write my script as: > >user_type.select("Admin") >user_name.set("my_new_user") >password.set("my_password") >full_name.set("J. Random User") >admin_role.set > >That's lovely. But what I REALLY want to be able to do is create a data >structure like this: > >my_new_user_data = { > :user_type => "Admin", > :user_name => "my_new_user", > :password => "my_password", > :full_name => "J. Random User", > :admin_role => TRUE >} > > >And then use a single method to iterate through the keys in the hash to set >the fields > >set_form_values(my_new_user_data) > >set_form_values is a method that lives in a page class, like so: > > def set_form_values(values_hash) > for field_id in values_hash.keys > if @form_objects.has_key?(field_id) > @form_objects[field_id].set(values_hash[field_id]) > else > raise "Field '" + field_id.to_s + "' not in Form Objects" > end > end > end > >And each page has a map of the form elements it contains, the @form_objects >instance variable that looks like: > >@form_objects = { > :user_type => ie.select_list(:id, "user_type"), > :user_name => ie.text_field(:name, "username"), > :password => ie.text_field(:name, "password"), > :full_name => ie.text_field(:name, "fullName"), > :admin_role => ie.checkbox(:name, "roles", "rolename=admin") >} > >This means that my test scripts just worry about the data, and the logic to >fill out the form is isolated in a single location. > >The problem now is that I have to special case all the different form >element types...if it's a select field, call "select"; if it's a checkbox, >call set with no parameter, etc. Ick. I'd much rather call a standard >interface, set(value). > >Many many thanks...and sorry I don't have time to contribute this code >myself...(soon, soon...) > >Elisabeth > >--------------------------- >Elisabeth Hendrickson >Quality Tree Software, Inc. >http://www.qualitytree.com >--------------------------- > > > >_______________________________________________ >Wtr-core mailing list >Wtr-core at rubyforge.org >http://rubyforge.org/mailman/listinfo/wtr-core _____________________ Bret Pettichord www.pettichord.com From bret at pettichord.com Thu Oct 20 00:17:37 2005 From: bret at pettichord.com (Bret Pettichord) Date: Wed, 19 Oct 2005 23:17:37 -0500 Subject: [Wtr-core] late binding is very cool! In-Reply-To: Message-ID: <5.1.0.14.2.20051019231046.035055c8@pop.gmail.com> Elisabeth, I'm glad you like it. I've been calling this late binding or lazy evaluation. Both are common terms that more or less map to what is happening here. It is not yet fully implemented. I think i still need to make it work for table objects, and also containers -- which is more complicated. One of the reasons that i've been wanting to make this happen (other than urging from you) has been that many new users expect Watir to work this way. When i first suggested that i add this, i said that it would also allow you to create window declarations or window maps, which is really what you are doing. That created a surprising amount of objections because people feared that i would be requiring this kind of intermediate layer (as do SilkTest and WinRunner) rather than just allowing it for people who want to have it. A consistent design goal has been to make Watir work the way that naive users expect it to. Sometimes this means doing a lot of behind the scenes work, but i think it tends to be worth it. Bret At 06:59 AM 10/18/2005, Elisabeth Hendrickson wrote: >Greetings all! > >I was going to drop Bret a private note, then I realized that this is just >the sort of message that ought to go on the wtr-core list... > >Bret: huge thanks for late binding! >Everyone else: here's what I mean... > >Back at the Agile conference in August, I showed Bret some code I'd been >working on that enabled me to create much more maintainable Watir scripts. > >One of the keys to improving maintainability is to isolate the literal field >names. That way if "j_username" ever becomes "username," you only have to >make the change in one place. One common approach is to use constants like >so: > >USERNAME = "j_username" >ie.text_field(:name, USERNAME) > >But I wanted to take it further. I wanted to be able to say: > >username_field = ie.text_field(:name, "j_username") > >It didn't work. If the field wasn't on the current page when the >declaration statement was executed, Watir threw an exception when I tried to >use the username_field variable to do anything. To make this work, I ended >up creating classes for all the form objects that wrapped the Watir classes. > >When I explained what I wanted to Bret, he said, "Oh. You want late >binding. Yeah, I can do that." > >Well, I've started playing with the latest build, and sure enough, late >binding works, at least for text fields, select lists, buttons, and frames. >I still have more playing to do, but I can see that there's lots of code I >won't have to write next time I do a major Watir project. Less code == more >good! > >By the way, my next big Watir/Ruby project starts in a couple weeks, and >there's a good shot that I'll be doing another one in a couple months. So >thank you thank you thank you thank you! > >Elisabeth >--------------------------- >Elisabeth Hendrickson >Quality Tree Software, Inc. >http://www.qualitytree.com >--------------------------- > > >_______________________________________________ >Wtr-core mailing list >Wtr-core at rubyforge.org >http://rubyforge.org/mailman/listinfo/wtr-core _____________________ Bret Pettichord www.pettichord.com From bret at pettichord.com Tue Oct 25 13:32:52 2005 From: bret at pettichord.com (Bret Pettichord) Date: Tue, 25 Oct 2005 12:32:52 -0500 Subject: [Wtr-core] my status Message-ID: <5.1.0.14.2.20051025123128.03aca1e0@pop.gmail.com> Greetings, I know that we're getting a backlog of bugs and things and i haven't been attending to them much. If you see something that needs to be done, please go ahead and do it. Actually, i'm going through a job change at the moment. I'll have more to announce soon. Bret _____________________ Bret Pettichord www.pettichord.com From jeff.darklight at gmail.com Thu Oct 27 19:27:47 2005 From: jeff.darklight at gmail.com (Jeff Wood) Date: Thu, 27 Oct 2005 16:27:47 -0700 Subject: [Wtr-core] ... questions about Watir::ElementCollections Message-ID: I just had an idea for WATiR and I'd like to see what you all think.... I'd like Watir to dig through the html and build the object tree so that in memory is all of the Watir::Element derivatives for the entire document. It would make doing some things like ( finding the table that contains a specific link ) a LOT easier. I've got some VERY ugly HTML that I'm trying to dig through ... tables inside tables, etc ... no names, no ids, nothing to make life easier... ( all dynamically generated ). So, I need to find a table that has a link with specific text, because there is OTHER text in the same cell that I need to validate. What do people think about something like that ??? I think it would be quite helpful for anybody that has to deal with some of this mess. I look forward to responses/feedback. Let me know. j. -- "http://ruby-lang.org -- do you ruby?" Jeff Wood From bret at pettichord.com Fri Oct 28 00:31:06 2005 From: bret at pettichord.com (Bret Pettichord) Date: Thu, 27 Oct 2005 23:31:06 -0500 Subject: [Wtr-core] ... questions about Watir::ElementCollections In-Reply-To: Message-ID: <5.1.0.14.2.20051027232956.039bfe68@pop.gmail.com> At 06:27 PM 10/27/2005, Jeff Wood wrote: >So, I need to find a table that has a link with specific text, because >there is OTHER text in the same cell that I need to validate. Does this do what you want (in head): ie.cell(:text, /specific text/).text =~ /other text/ Bret _____________________ Bret Pettichord www.pettichord.com From raghu at qantom.com Fri Oct 28 01:26:28 2005 From: raghu at qantom.com (Raghu Venkataramana) Date: Fri, 28 Oct 2005 10:56:28 +0530 Subject: [Wtr-core] ... questions about Watir::ElementCollections In-Reply-To: References: Message-ID: <4361B684.2090107@qantom.com> Jeff Wood wrote: >I just had an idea for WATiR and I'd like to see what you all think.... > >I'd like Watir to dig through the html and build the object tree so >that in memory is all of the Watir::Element derivatives for the entire >document. > > I agree that it is a useful utility to have. It would make scripting for Watir a lot easier. >It would make doing some things like ( finding the table that contains >a specific link ) a LOT easier. > >I've got some VERY ugly HTML that I'm trying to dig through ... tables >inside tables, etc ... no names, no ids, nothing to make life >easier... ( all dynamically generated ). > >So, I need to find a table that has a link with specific text, because >there is OTHER text in the same cell that I need to validate. > >What do people think about something like that ??? > >I think it would be quite helpful for anybody that has to deal with >some of this mess. > >I look forward to responses/feedback. Let me know. > >j. > >-- >"http://ruby-lang.org -- do you ruby?" > >Jeff Wood > >_______________________________________________ >Wtr-core mailing list >Wtr-core at rubyforge.org >http://rubyforge.org/mailman/listinfo/wtr-core > > > -- Qantom Software http://www.qantom.com Ph : 91-80-26799269 Xtn. 125 sip : raghu at sip411.com -- From bret at pettichord.com Fri Oct 28 01:14:16 2005 From: bret at pettichord.com (Bret Pettichord) Date: Fri, 28 Oct 2005 00:14:16 -0500 Subject: [Wtr-core] ... questions about Watir::ElementCollections In-Reply-To: <4361B684.2090107@qantom.com> References: Message-ID: <5.1.0.14.2.20051028001132.035dcee8@pop.gmail.com> At 12:26 AM 10/28/2005, Raghu Venkataramana wrote: > >I'd like Watir to dig through the html and build the object tree so > >that in memory is all of the Watir::Element derivatives for the entire > >document. > > > > >I agree that it is a useful utility to have. It would make scripting for >Watir a lot easier. Can you give examples of what you want to do? One thing that needs to be changed with Watir is that the collections objects should iterate over Watir objects rather than COM objects. I think this might give you what you need. But i need to know what problem you are trying to solve. Bret _____________________ Bret Pettichord www.pettichord.com From raghu at qantom.com Fri Oct 28 02:08:44 2005 From: raghu at qantom.com (Raghu Venkataramana) Date: Fri, 28 Oct 2005 11:38:44 +0530 Subject: [Wtr-core] ... questions about Watir::ElementCollections In-Reply-To: <5.1.0.14.2.20051028001132.035dcee8@pop.gmail.com> References: <5.1.0.14.2.20051028001132.035dcee8@pop.gmail.com> Message-ID: <4361C06C.4060604@qantom.com> Bret Pettichord wrote: > At 12:26 AM 10/28/2005, Raghu Venkataramana wrote: > >> >I'd like Watir to dig through the html and build the object tree so >> >that in memory is all of the Watir::Element derivatives for the entire >> >document. >> > >> > >> I agree that it is a useful utility to have. It would make scripting for >> Watir a lot easier. > > > Can you give examples of what you want to do? > > One thing that needs to be changed with Watir is that the collections > objects should iterate over Watir objects rather than COM objects. I > think this might give you what you need. But i need to know what > problem you are trying to solve. Precisely what you said above. If there were to be some sort of a 'watir tree' collection, that would make life easier. An example watir(ized) representation for a html page could be body ---| title = New webpage; url=http://example.org/watir | - image ; id = img1, alt=oneimage | - table | id = tbl1 | - textfield; name=tf1; id=id_tf1 | - checkbox; name=cb1; id=id_cb1 | - image ; id = img2, alt=another | ....... ...... | ....... | - table | id = tbl2 | ....... ...... | ....... | - link ; text = mylink; id=... If such a representation is created internally when Watir loads a page, then you could print out the objects in a more 'watir' like fashion. For example, if you say show_images, it could show something like. ie(:title, "New webpage) -> image(:id=img1, :alt=oneimage) ie(:title, "New webpage) -> table(:id=tbl1) -> image(:id=img2, :alt=another) and so on. Raghu > > Bret > > > _____________________ > Bret Pettichord > www.pettichord.com > > -- Qantom Software http://www.qantom.com Ph : 91-80-26799269 Xtn. 125 sip : raghu at sip411.com --