There are 4 basic categories of commands:
Many commands are performed against a specific element of the HTML page. Inorder to carry out such a command the method to locate the element must be specified using a find method
Name | Arguments | Find method | Description |
---|---|---|---|
AppendText | Text to append | Required | Appends text to a given text input field. |
AttachToIE | Required | Attaches to an exisintg instance of internet explorer that matches the passed in document title | |
Back | Navigates to the previous page in the browser history | ||
BringToFront | Brings the current browser window to the foreground. | ||
ClearCache | Clears the browser cache, best called before using other commands. | ||
ClearCookies | Url (optional) | Clears the browser cookies, either for a given url or all cookies. | |
ClearText | Required | Clears the value for the text input element specified by the find method | |
Click | Required | Triggers the click event for the element specified by the find method | |
Close | Closes the browser | ||
DoubleClick | Required | Triggers the double click event for the element specified by the find method | |
Flash | Required | Causes the selected browser element to flash | |
Focus | Required | Sets focus to a given element | |
Forward | Navigates to the next page in the browser history | ||
GetCookie | Url, cookie name | Gets the cookie for the specified Url and cookie name. Used in combination with the ValidateLastFound command. | |
Goto | Url | Navigates to the Url specified in the command arguments | |
PressTab | Presses the tab key moving focus to the next element in the tab order. | ||
Refresh | Causes the current browser window to refresh. | ||
Screenshot | File name | Creates an image of the current web page and saves it to disk. | |
SelectText | Required | Selects the text for the identified text input element. | |
SetCookie | Url,cookie data | Sets a cookie for the specified domain, The cookie data of the form: <name>=<value>[; <name>=<value>]... [; expires=<date:DAY, DD-MMM-YYYY HH:MM:SS GMT>][; domain=<domain_name>] [; path=<some_path>][; secure][; httponly]. | |
SetValue | Value,property name | Required | Sets the value for the element specified by the find method, using the value given in the command arguments |
SetValues | Values (comma seperated), property name | Required | Sets multiple values for the element specified by the find method, using the value given in the command arguments commonly used with a selected list that has the multiple attribute. |
TypeText | Text to type | Required | Types text for a given text field. |
Command Id: CmdAppendText Command: AppendText CommandArgs: Eddie FindMethod: ById FindArgs txtFirstName
This example will append text to the text field control identified by the id txtFirstName. If element with this id is found or the element is not a text field control, the test will fail.
Command Id: CmdAttachToIE1 Command: AttachToIE CommandArgs: {not applicable} FindMethod: ByTitle FindArgs Welcome to CodePlex
This example will attach to the first instance of Internet Explorer that has the page title "Welcome to CodePlex". If no instance of Internet Explorer is found, with that document title, the test will fail.
Command Id: CmdGoBack Command: Back CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example will navigate to the previous page in the browser's history.
Command Id: CmdBringToFront Command: BringToFront CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example will cause the current browser window to come to the foreground.
Command Id: CmdClearCache Command: ClearCache CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example will clear the browser cache.
Command Id: CmdClearCookies Command: ClearCookies CommandArgs: http://www.google.com FindMethod: {not applicable} FindArgs {not applicable}
This example will clear all cookies for the url http://www.google.com.
Command Id: CmdClearText Command: ClearText CommandArgs: {not applicable} FindMethod: ById FindArgs txtFirstName
This example look for a browser element with that has the id txtFirstName, it will clear the value for that text input field. The test will fail if an element can not be found for that id, or if the element found is not an text input element.
Command Id: CmdSubmitLoginForm Command: Click CommandArgs: {not applicable} FindMethod: ById FindArgs btnOkay
This example look for a browser element with that has the id btnOkay, it will then fire that element's click event. The test will fail if an element can not be found for that id.
Command Id: CmdCloseBrowser Command: Close CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example closes the browser the current test is attached to.
Command Id: CmdPopUp Command: DoubleClick CommandArgs: {not applicable} FindMethod: ByValue FindArgs Title
This example look for a browser element with that has the value Title, it will then fire that element's double click event. The test will fail if an element can not be found for that value.
Command Id: CmdFalshElement Command: Flash CommandArgs: {not applicable} FindMethod: ById FindArgs txtLastName
This example will cause the browser element with the id txtLastName to flash. The test will fail if no element with that id is found.
Command Id: CmdFocusElement Command: Focus CommandArgs: {not applicable} FindMethod: ById FindArgs txtLastName
This example will set focus to the browser element with the id txtLastName to flash. The test will fail if no element with that id is found.
Command Id: CmdGoForward Command: Forward CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example will navigate to the next page in the browser's history.
Command Id: CmdGetCookie Command: GetCookie CommandArgs: http://www.google.co.uk,wax FindMethod: {not applicable} FindArgs {not applicable}
This example will get the cookie named wax for the domain http://www.google.co.uk.
Command Id: CmdGotoStart Command: Goto CommandArgs: http://wwww.google.co.uk FindMethod: {not applicable} FindArgs {not applicable}
CommandArgs: The url to navigate to. If '~' is found in the url it will be replaced with the current directory.
This example will navigate to http://wwww.google.co.uk.
Note: If there is no attached browser, i.e. AttachToIE or Goto have not been called before in the test, a new browser window will be created prior to navigation
Command Id: CmdPressTab Command: PressTab CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example will press the tab key moving focus to the next element in the tab order.
Command Id: CmdRefresh Command: Refresh CommandArgs: {not applicable} FindMethod: {not applicable} FindArgs {not applicable}
This example will refresh the current browser window.
Command Id: CmdScreenshot Command: Screenshot CommandArgs: C:\images\testimage1.png FindMethod: {not applicable} FindArgs {not applicable}
This example will create a screen shot of the current web page and save it to disk.
Command Id: CmdSelectText Command: SelectText CommandArgs: {not applicable} FindMethod: ById FindArgs txtFirstName
This example will select the text for the text input element identified by the id txtFirstName. The test will fail if no element is found for the corresponding id, or if that element is not a text input field.
Command Id: CmdSetCookie Command: SetCookie CommandArgs: http://www.google.co.uk/,"wax=1234; expires=Wed, 01-Jan-2020 00:00:00 GMT" FindMethod: {not applicable} FindArgs {not applicable}
This example will set the cookie named wax to the value 1234 to expire on 1st Jan 2020 for the domain http://www.google.co.uk. Note the cookie data is enclosed in quotes because it contains a comma.
Command Id: CmdSetFirstName Command: SetValue CommandArgs: Edward,Text FindMethod: ById FindArgs txtFirstName
insert excel image
This example sets the value of the the browser element with the id txtLastName to Edward. The test will fail if no element with that id is found.
Command Id: CmdSetMultiList Command: SetValue CommandArgs: Visa,MasterCard,SelectedItem FindMethod: ById FindArgs optCreditCards
This example finds the select list with the id txtLastName and sets the selected items to Visa and MasterCard. The test will fail if no element with that id is found.
Command Id: CmdTypeText Command: TypeText CommandArgs: Eddie FindMethod: ById FindArgs txtFirstName
This example finds the text box with the id txtTypeText and types in the text Eddie. The test will fail if no element with that id is found.
Name | Arguments | Find method | Description |
---|---|---|---|
Validate | value, property name | Required | Asserts the value of an element's property is the same as the expected value |
Validate using attributes | value, attribute:{name} | Required | Asserts the value of an element's attribute is the same as the expected value |
Validate last found value | value | Required | Asserts the value of the last "Get" command (i.e. GetCookie, GetJavaDialogMessage) is the same as the expected value |
Validate document contains text | value, text | Required | Asserts the document contains the specified value. |
ValidateItems | values (comma seperated), property name | Required | Asserts values for elements that can have multiple values. Commonly used with a selected list that has the multiple attribute. |
Command Id: CmdValidateLinkText Command: Validate CommandArgs: Save document,Text FindMethod: ById FindArgs linkSaveDocument
This example will check that the link identified by the id linkSaveDocument has it's text property set to Save document If the link can not be found or the link's text property is not set to this value then the test will fail.
Command Id: CmdValidateAttrubute Command: Validate CommandArgs: mainForm,attribute:class FindMethod: ById FindArgs form1
This example will check that the attribute called class is equal to mainForm
Command Id: CmdValidateDocument Command: Validate CommandArgs: WatiN Home,Text FindMethod: UsingDocument FindArgs
This example will check that the document contains the text UsingDocument. The test will fail if the document doesn't contain this text.
It's also possible to enter values using regular expressions see:http://msdn.microsoft.com/en-us/library/kweb790z(VS.71).aspx for correct syntax.
Command Id: CmdLastFound Command: ValidateLastFound CommandArgs: wax=1234 FindMethod: FindArgs
This example asserts that the value of the last get command, which retrieves a cookie, is equal to "wax=1234".
Command Id: CmdValidateSelectList Command: ValidateItems CommandArgs: 1,2,3,SelectedItem FindMethod: ById FindArgs listOptions
This example will check that the selected items of a list, identified by the id listOptions are 1, 2 and 3; if otherwise the test will fail.
Name | Arguments | Find method | Description |
---|---|---|---|
AttachDialogHandler | {dialog type},{dialog id} | Attaches a specified type of dialog and assigns it a given id | |
GetJavaDialogMessage | {dialog type},{dialog id} | Using a previously attached simple SimpleJavaDialog get's its alert message |
Value | Description |
---|---|
SimpleJavaDialog | Used to test a javascript alert dialog, used in the and |
Command Id: CmdAttachDlg1 Command: AttachDialogHandler CommandArgs: SimpleJavaDialog,dlgSimple FindMethod: FindArgs
This will attach a SimpleJavaDialog handler and assign it the id dlgSimple. The id allows subsequent commands to interact and reference this dialog.
Command Id: CmdAttachDlg2 Command: GetJavaDialogMessage CommandArgs: SimpleJavaDialog,dlgSimple FindMethod: FindArgs
This example shows how to attach a dialog, click a link that will cause the dialog to appear, and then retrieve it's message content and finally assert that it's equal to an expected value.
Name | Arguments | Description |
---|---|---|
ById | {Id} | Finds an element using the value of it's id. |
ByValue | {value} | Finds an element by it's value |
ByLastElement | Use the last element found from the previous command executed. | |
ByUrl | Find an element based on the value of it's url | |
ByNameAndValue | {name, value} | Find an element based on it's name and value. |
UsingDocument | Used for validating properties at the document level see: example validate UsingDocument |
Command Id: CmdFindByTest Command: Click CommandArgs: FindMethod: ById FindArgs link1
This example will locate an element by it's id. If no matching id is found then the test will fail.
Command Id: CmdFindByLastElement Command: Click CommandArgs: FindMethod: ByLastElement FindArgs
This example will use the last element found and fire its click event.
Command Id: CmdFindByUrl Command: Click CommandArgs: FindMethod: ByUrl FindArgs http://www.google.co.uk
This example will use the element that has an href of "http://www.google.co.uk" and fire its click event. If no such element is found the test will fail.
Command Id: CmdFindByValue Command: Click CommandArgs: FindMethod: ByValue FindArgs 3
This example will locate an element by it's value. If no matching value is found then the test will fail.
This example would match the following html fragment:
<input type="Radio" name="radio1" value="3">
Command Id: CmdFindByNameValue Command: Click CommandArgs: FindMethod: ByNameValue FindArgs radio1, 3
This example will locate an element by it's name and value. If no matching element is found then the test will fail.
This example would match the following html fragment:
<input type="Radio" name="radio1" value="3">
Name | Description |
---|---|
AttachToIETimeOut | Time to wait whilst trying to attach to an instance of IE. |
AutoCloseDialogs | Automatically close any dialogs opened during a test |
Command Id: CmdFindByNameValue Command: Click CommandArgs: FindMethod: ByNameValue FindArgs radio1, 3
This example will locate an element by it's name and value. If no matching element is found then the test will fail.