Commands
The Selenium API defines dozens of commands that can be categorized into the following:- Actions
- Accessors
- Assertions
Actions
- Actions are commands that change the state of the application like clicking links or buttons, select an option in a
<select>or type a character sequence in a given textbox. -
Actions are available in different flavors. For instance,
click(locator)will trigger a click on an elementlocatorbut you can also find:clickAndWait(locator)command which will trigger a click and stop the test until the browser has finished loading a new page.clickAt(locator, offset)command that also triggers a click but takes another argument: a X and Y tuple that offset the actual clicking location by X and Y pixels.- A combination of the above :
clickAtAndWait(locator,offset)that combines the specification of an offset for the click location and waits for a new page to load.
test with actions ? typeid=searchDonuts near my home? typemodifies the state of the application (it modifies a test field) and so is considered as an action
Accessors
- Accessors inspect the state of the application and store values in variables.
- For instance,
storeCookies(variableName)stores all the cookies in use in the current page in the variablevariableName. -
To use stored variables, the syntax is
${variablename}(orstoredVars['variableName']if in a JavaScript context):Test with variables storemy_search_stringsearchString? typeid=search${searchString}? and if in a JavaScript code section:if (storedVars['variableName'] == '') { ... }
Assertions
-
Assertions are also able to inspect the current page but:
- They are made to return a boolean value
- This boolean represents the conformity of the element to a desired pattern
- Usually, the pattern represents the state of an element.
-
Assertions come into 3 flavors:
- assert : if assertion fails, test is aborted and marked as failed :
assertTitle(pattern)will fail if the title of the page doesnot correspond to thepatternargument. - verify : if a verification fails, the test doesnot stop but a trace will be printed in the log.
- waitFor : these commands pause the test until a condition is satisfied or a timeout is reached.
- assert : if assertion fails, test is aborted and marked as failed :
I like your blog very much...
ReplyDeleteSelenium Course in Chennai