I've been working on mapping our in house apps as part of a testing framework using Watir I'm working on, I was using YAML for the mapping -- here's an example :
 
example YAML:
form:  Customer
frame:  none
fields:
  - Label: Sales Customer Name
    Type: text_field
    Name: SalesCustomerName
    Id:  SalesCustomerName
  - Label: Short Name
    Type: text_field
    Name: ShortName
    Id: ShortName
  - Label: Legal Names
    Type: selectValuesDialog
    Name:
    Id:
    HelperId: Dbx_LegalNames
    HelperType: link
    HelperSymbol: id
  - Label: Other Names
    Type: selectValuesDialog
    Name:
    Id:
    HelperId: Dbx_OtherNames
    HelperType: link
    HelperSymbol: id
 
 
I purposely left out any test data to separate the page structure from the test data, allowing me to only have to update the YAML if/when the page changes, and allowing me to send in various permutations of test data.
 
I created a script to populate the form providing it with a Hash of Label => Value and the YAML, the labels are the actual labels the user sees in the page, making it easy to generate test data.  The Id and Name are taken from the HTML and used in the watir commands as needed.
 
example Hash:
testCustHash = {"Sales Customer Name" => "Test Company",
                         "Legal Names" => "Test Legal",
                         "Other Names" => " Test Other",
                        }
 
example Command:
populateForm(myTestHash, myTestYAML, ie)
 
-- which iterates through the Hash, finds the appropriate entry in the YAML and populates the field as desired.  (I have a populateForm and a populateField -- the populateField does a single field, and the populateForm does the entire page with multiple calls to the populateField method)
 
The populateField method calls the appropriate watir mehtod or a helper method if needed to populate the field/page for me.  Some of my fields bring up 2nd IE windows to do the entry (calendarWidget, Address mini-form, multi-value selects etc), so I created helper methods to populate these too using the same engine, only this time I trigger the action that brings it up first and then populate .  The trigger is usually a jscript(onClick) event on a button, image or link object.  I build a command to trigger the event based on the Helper entries in the YAML.  (Example provided below because I think there was another question about this topic earlier in the week where this might be applicable -- to use this I call eval(cmd) elsewhere in the script)
 
def buildJscriptCmd(fieldYaml)
   @symbol=fieldYaml["HelperSymbol"]
   @id=fieldYaml["HelperId"]
   @helper=fieldYaml["HelperType"]
   @cmd="@[EMAIL PROTECTED](:[EMAIL PROTECTED],\'[EMAIL PROTECTED]').fireEvent(\'onClick\')"
end 
 
I see this as a viable framework to help the team be productive producing working scripts early on while learning Ruby and Watir, without having to mine the HTML.  I also think it allows for easy maintenance if the pages change, I can update in the YAML and the scripts should be pretty good to go.  YAML also is very flexible, I can add/remove attributes if I identify other test modes that I'd like to support, I could add a required attribute to identify all the required fields for example, or dependency if fields are dependent on others, etc.  This can even be done at runtime using the YAML library I believe if your app so demands.  I'll probably extend my framework to use YAML to wrap the verifications too at some point, to improve maintainability.
 
I also envision using rubyFit or something like it to drive this in the future.
 
Sorry for the book, just thought I'd share on this topic.  :-)
 
 
 
 
 
 
 
 
 
 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bret Pettichord
Sent: Thursday, April 20, 2006 11:18 AM
To: [email protected]
Subject: Re: [Wtr-general] Application Map

I am thinking of adding a Map class to Watir. Here's how it would work...

On 4/20/06, Adrian Rutter <[EMAIL PROTECTED] > wrote:
Hi,

If we take a look at the 'googlesearch' example. we have two actions that
are sent to different objects

ie.text_field(:name, "q").set("pickaxe")       # q is the name of the
search field
ie.button(:name, "btnG").click   # "btnG" is the name of the Search button


I think what we'd have to map is this:

text_field(:name, "q")

so

SearchField="text_field(:name, 'q')"

map = Watir::Map.new
SearchField=map.text_field (:name, 'q')
 

Now.I was thinking of using the Ruby HashMap, so we could have

googlewin = {
"SearchField" => "text_field(:name, 'q')"
"SearchButon"  => "button(:name, 'btnG')"

... etc

}

SearchButton = map.button (:name, 'btnG')
 
We will need to keep all action methods in a collection as well (e.g .
click, set)

So the test table will look something like this

test,       win         object            Action      Arg         #header

T,    googlewin,  SearchField,      set,  "PickAxe"
T,    googlewin,  SearchButon,      click

We could read in and process the above input, so the script will look like

GUIAction = "ie." + object + "." + Action "." + Args

To use these objects you would first do
ie = Watir::IE.start('http://google.com')
map.bind(ie)

SearchField.set("PickAxe")
SearchButton.click

Questions

1. What do you think?
2. Should I put every GUIobject within 1 class with every window being a
different method or each window being a separate class?

If you wanted to, you could store these map-elements in a module named after the window:
  GoogleWin::SearchButton = map.button(:name, 'btnG')
 

3. I am not so sure on the Ruby syntax to get the value from a key? Is it
something like ' googlewin.key("SearchField")' ?

Aidy



---------------------------------------------------------------------------------------------------------------
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure.
If you are not the intended recipient, please telephone or email the sender and delete this message and any attachment from your system.
If you are not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.
---------------------------------------------------------------------------------------------------------------
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

The content contained in this electronic message is not intended to
constitute formation of a contract binding TWTC. TWTC will be
contractually bound only upon execution, by an authorized officer, of
a contract including agreed terms and conditions or by express
application of its tariffs.

This message is intended only for the use of the individual or entity
to which it is addressed. If the reader of this message is not the
intended recipient, or the employee or agent responsible for
delivering the message to the intended recipient, you are hereby
notified that any dissemination, distribution or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by replying to
the sender of this E-Mail or by telephone.
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to