Save
parameter: the name to give the current elementThe current element is saved in the hash map with the given name. This is especially useful in naming the root element. Most other ways to access an element (Element, for example) have a way to name the retrieved element. An optional third cell in the row will be filled with the XML of the element named.
Example
| HtmlFixture | |
| http://csis.pace.edu/~bergin/gandhi.html | |
| Save | homePage |
Element Focus
parameters are exactly those of Element and it behaves the same way except that it also sets this element to be the focus of subsequent rows. It is a shorthand for an Element command followed by a Focus command except that it won't set the current element to null. There is no need to set a name for the element to obtain the focus, though you may to allow returning focus to this element in a subsequent test.Example:
| HtmlFixture | |||
| homePage | |||
| Element Focus | 2 | body | pageBody |
Exactly like the Focus example above. Subsequent rows focus on the body of the page.
Note that Element Focus is useful for quick drilling deep into page structure. Element alone is better if you want to do a broad testing of a single element. You can then drill down into its children with Focus.
Text (applies to nodes such as anchor or title tags that contain a text node as a child)
parameter: The text in the element (example: title element) (opt)Assert that the text in the element has the given text, or query for the text. Requires an exact match.
Has Text (applies to nodes such as anchor or title tags that contain a text node as a child)
parameter: Any substring of the expected text of the element. (opt)Assert that the parameter is a substring of the actual text.
Matches Text (applies to nodes such as anchor or title tags that contain a text node as a child)
parameter: A regular expression intended to be matched by the text in the element.Assert that the RE is matched by the actual text.
e.g.
| HtmlFixture | |||
| homePage | |||
| Element Focus | 1 | head | pageHead |
| Type Focus | title | 1 | titleText |
| Text | Gandhi Biography | ||
| Has Text | hi Bio | ||
| Matches Text | ^Gandhi | ||
Attribute (applies to any element with an enclosed attribute)
parameters(3)(1) name of the attribute
(2) value of the attribute (opt)
(3) an optional symbolic name for the value of the attribute (saved as a symbol)
Assert that the element has an attribute with the given name and value or assert that there is an attribute with the name and query for its value.
e.g.
| HtmlFixture | |||
| http://csis.pace.edu/~bergin/patterns | |||
| Type Focus | frame | 2 | |
| Attribute | src | select.html | select |
| Focus Relative | symbol select | ||
The following three tokens/keywords are not assertions, but used to manipulate things on the page
Execute (applies to script nodes)
parameter: a condition on which to run this java script element. e.g. onClickFire the condition if it is defined for this script element.
Note that the underlying htmlUnit still has only partial support for javascript.
Set Value (applies to input, textarea, and select nodes)
parameter: Text to be entered into this (input, textarea, or select) element.For a submit the text is used to set the selected attribute of the element. For the others the text is entered.
You can "check" a checkbox using Set Value to checked. If you set it to an empty string it will be unchecked.
Submit (applies to the current element when it is an anchor or form node)
parameter: The name of the page returned.Click this link or submit this form and capture the resulting page. Give it the specified name for further processing. An optional third cell in the row will be filled with the XML of the retrieved page.
Click
A synonym for Submit. Works exactly the sameSubmit (and Click) has two side effects. First, it sets the focus (current element) to the page returned by the submission. Second, it clears the hash map, so all names saved till then are lost. You start fresh. The name in the parameter is inserted in the newly emptied hash map along with the page returned. You can toggle this clearing behavior off (and on again) with the Preserve command.
Preserve
parameters (none)Normally the hash map of element names is cleared whenever you Submit. You can give the Preserve command to change the behavior back and forth from its default behavior. One application of Preserve and the map will no longer be cleared on Submit. The second application will set you back to the default behavior, etc.
You can use this feature to permit complex navigation from page to page (submitting forms, for example) and still be able to return to an earlier page with a minimum of set up for additional tests.
Javascript
parameters (none)In some cases an "onload" javascript can cause a page to fail to load generating an exception. Therefore javascript execution has been turned off for the retrieval of urls. This command can be used to toggle it back on and off again if this is important to you. Note that even with it off, the Execute command still works. The value is preserved across tables (and pages).
Clear
parameters (none)Clear the hash map of names immediately. You may want to do this for sub pages in some cases so as to "forget" the names defined earlier.
Types
parameters (2)(1) A valid type (tag) name (e.g. table or a)
(2) An integer: the asserted number of descendants of the given type (opt)
Assert that the current element has a certain number of descendant elements of the given type. If the third column is blank it will query for the number of descendants of that type. Note that this command considers all descendants of the current element, not just children. See Elements for a comparison operator option on the second parameter.
Type
parameters (3)(1) A valid type (tag) name (e.g. table or a)
(2) An integer index (one based)
(3) A name for the resulting element (opt)
Assert that there are at least "index" descendant elements with the given type. Give the name to the one at "index". Note that this drills all the way down the tree starting at the current element so it searches all descendants, not just children. It has no query capability. If the third parameter (fourth cell) is missing or is present and blank, no name will be given to the resulting element. An optional fifth cell in the row will be filled with the XML of the specified element.
Example:
| HtmlFixture | |||
| homePage | |||
| Type | p | 3 | third |
| Type | table | 3 | filler |
| Focus | third | ||
| Matches Text | laborers.$ | ||
One way to think of Type is that it takes a "depth first" or "pre order" view of the html tree. Another is that it just works in textual order on the html code. Element, on the other hand, takes a structural or "breadth first" or "level order" view of the tree.
Type Focus
parameters: Exactly like Type but it also sets the current focus to the element specified unless that would make it null. Similar to the relationship between Element and Element Focus.Nodes (applies to any element or page)
parameter: the number of child nodes of this item (opt)Assert that the item has the specified number of children or query for the number if blank. Note that this one counts all nodes, not just Element nodes. See Elements for a comparison operator option on the parameter.
Node (applies to any element or page)
parameters(2)(1) the node index relative to the beginning (one based)
(2) the node (type) name (e.g head,.#text ,...) (opt)
Assert that the specified node has the given type. Or query for the type if blank.
Blank Token (meta)
parameter: Any word that you want to use to specify that an element should consist of blank text. The default token is $blank$. The parameter may not be the empty string, however.Note that the query feature means that if you want to assert that something (a title, perhaps) is really blank, you cannot just leave the table cell blank as it will then be interpreted as a query. To indicate that a certain element should be "blank" specify the (default) token $blank$ to cover this case. To assert an element consists of empty text use this token in the corresponding value cell. The Blank Token command changes the blank token from the default $blank$ to whatever you like.
e.g.
| HtmlFixture | |||
| http://csis.pace.edu/~bergin/hello.html | |||
| Type Focus | title | 1 | titleText |
| Text | $blank$ | ||
| HtmlFixture | |
| titleText | |
| Blank Token | __blank__ |
| HtmlFixture | |
| titleText | |
| Text | __blank__ |
Last Element Token (meta)
parameter: A string that you want to use as the last element contained within the focus (or the last type within the focus)Note that it is possible to index the elements in Element and Type commands either forward from the first or backward from the last. The forward indexing is 1, 2, 3, ... The backward indexing is 0, -1, -2, ... where 0 is the last element. If you find this irksome, then just define a last element token (say *) using this command and then your token is the name of the last, and the backward indexing will then be *, *-1, *-2, etc. Note that defining the token does not invalidate the standard numeric naming. It is just an alternative
e.g.
| HtmlFixture | |||
| homePage | |||
| Last Element Token | last | ||
| Element | last | body | pageBody |
Symbol (meta)
parameters (2)(1) name for a new symbol
(2) string value of the symbol
You can use this command to give symbolic names to strings you want to appear in other cells of your tests. This gives a name and a value to your symbol which may then be used later.
You can then use the symbol later by using the name of the symbol prefixed with the "symbol token". The default parameter token is symbol.
e.g.
| HtmlFixture | ||
| pageHead | ||
| Symbol | big | > 10 |
| Elements | symbol big | |
Note that the symbol token must appear at the beginning of the cell contents. The value of the parameter will be used instead. In other words, with the above definition, this command is just like:
|Elements| > 10|
Symbol Token
parameter: The token used to introduce a symbol in a cell. The default is the word: symbol. You may replace this with any non empty string. You may need to do this if the value of the default token is important to your testing.List (meta)
parameters(1) A name for the list
(2...n) values to be stored in the list. Any string values.
A List is a symbol with a given name but many values. The values in the symbol can be obtained by indexing from one. This command has a variable number of cells. The values are indexed in the same order you write them, starting with 1.
e.g.
| HtmlFixture | ||||
| homePage | ||||
| List | values | Charlemagne | Gandhi | Sun Tsu |
| Type Focus | title | 1 | ||
| Has Text | symbol values[2] | |||
Fail
The fail command is a modifier for many other commands. You use it by putting Fail in a cell alone, before any other command (some ignore it). The intent is to reverse the sense of the test.e.g.
| HtmlFixture | ||
| homePage | ||
| Fail | Elements | 3 |
Fail applies to the following commands: Attribute, Element, Elements, Has Text, Matches Text, Node, Nodes, Text, Type, and Types. The others will fail it if it is present, ignoring the rest of the row.
| HtmlFixture | |||
| homePage | |||
| Fail | Attribute | foo | bar |
| HtmlFixture | |||
| homePage | |||
| Fail | Element | 3 | body |
| HtmlFixture | ||
| homePage | ||
| Fail | Elements | 3 |
| HtmlFixture | ||
| homePage | ||
| Fail | Has Text | foo |
| HtmlFixture | ||
| homePage | ||
| Fail | Matches Text | ^EBY |
| HtmlFixture | |||
| homePage | |||
| Fail | Node | 4 | #text |
| HtmlFixture | ||
| homePage | ||
| Fail | Nodes | 3 |
| HtmlFixture | ||
| homePage | ||
| Fail | Text | foo |
| HtmlFixture | |||
| homePage | |||
| Fail | Type | body | 2 |
| HtmlFixture | |||
| homePage | |||
| Fail | Types | Input | 3 |
Note that saving of name-element pairs is suspended for all Fail commands (there is nothing to name). The imaging of XML works for some, but not all.
For example |Fail |Element |3| body | | | will show you element 3 in the last cell unless an exception occurs. Querying works as usual for Fail commands.
Some of the Fail combinations seem superfluous or even silly (even to the author). An attempt was made to make the rules as uniform as possible and to do a sensible thing in all cases. In the case of the other commands, applying Fail will itself fail. |Fail |Submit | ... will fail and the Submit... part will be ignored.
There are other ways to do some of the things Fail can do. For example
|Elements| != 3| is the same as |Fail |Elements | 3 |.
| fit.Summary |
Notes.
There are three different kinds of symbols/names/variables that you can use to build your tests for this fixture. First you may use fitnesse variables. See http://fitnesse.org/FitNesse.MarkupVariables. These can be used to set part of a cell as well as an entire cell. However, the syntax of variable access is fixed. Next are the names given to elements when you give various commands here, such as Element, or Save. Finally are the symbols defined by the Symbol and Attribute commands that can be used to fill an entire cell. Note that the Clear command clears only the names (of elements), not the variables or the symbols.
This version will sometimes generate messages on standard out (visible in the error log) of the form
org.apache.commons.httpclient.HttpMethodBase processRedirectResponse INFO: Redirect requested but followRedirects is disabled
This is due to the support for version 2 of org.apache.commons.httpclient code. It does not indicate an error. The diagnostic occurs when you give a URL that does not end in a /, causing a redirection. Browsers handle this seamlessly, but the apache code distinguishes the cases.
To see the complete fitnesse wiki markup rules see: http://fitnesse.org/FitNesse.WikiInstructions
[ User Guide] [.FrontPage] [.RecentChanges]