What is a Selenium Command?
A
command is what tells Selenium what to do. Selenium commands come in three 'flavors':
Actions,
Accessors and
Assertions.
Each command call is one line in the test table of the form:
Actions are commands that generally manipulate the
state of the application. They do things like "click this link" and
"select that option". If an Action fails, or has an error, the execution
of the current test is stopped.
Many Actions can be called with the "AndWait" suffix, e.g. "clickAndWait".
This suffix tells Selenium that the action will cause the browser to make a call to the server,
and that Selenium should wait for a new page to load.
Accessors examine the state of the application and
store the results in variables, e.g. "storeTitle". They are also used
to automatically generate Assertions.
Assertions are like Accessors, but they verify that the
state of the application conforms to what is expected. Examples include
"make sure the page title is X" and "verify that this checkbox is
checked".
All Selenium Assertions can be used in 3 modes:
"assert",
"verify",
and
"waitFor". For example, you can "assertText", "verifyText" and
"waitForText". When an "assert" fails, the test is aborted. When a
"verify" fails, the test will continue execution, logging the failure.
This allows a single "assert" to ensure that the application is on the
correct page, followed by a bunch of "verify" assertions to test form
field values, labels, etc.
"waitFor" commands wait for some condition to become true (which can be useful for testing Ajax applications).
They will succeed immediately if the condition is already true.
However, they will fail and halt the test if the condition does not become true within the current timeout setting.
Element Locators tell Selenium which HTML element a
command refers to. Many commands require an Element Locator as the
"target" attribute. Examples of Element Locators include "elementId" and
"document.forms[0].element".
Patterns are used for various reasons, e.g. to specify
the expected value of an input field, or identify a select option.
Selenium supports various types of pattern, including
regular-expressions.