The command set is often called selenese. Selenium commands come in three “flavors”, They are:
Actions, Accessory and Assertions.
1.Actions: user actions on application / Command the browser to do something.
Actions are commands that generally manipulate the state of the application.
- Click link- click / Clickandwait
- Selecting items
2. Accessors: Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”.
3. Assertions: For validating the application we use Assertions
- For verifying the web pages
- For verifying the text
- For verifying alerts
Assertions can be used in 3 modes:
Example: “assertText”,”verifyText” and “waitForText”.
- When an “assert” fails, the test is aborted.
- When a “verify” fails, the test will continue execution
- “waitFor” commands wait for some condition to become true
Commonly Used Selenium Commands:
These are probably the most commonly used commands for building test.
open – opens a page using a URL.
Opens an URL in the test frame. This accepts both relative and absolute URLs. The “open” command waits for the page to load before proceeding, ie. the “AndWait” suffix is implicit. Note: The URL must be on the same domain as the runner HTML due to security restrictions in the browser (Same Origin Policy). If you need to open an URL on another domain, use the Selenium Server to start a new browser session on that domain.
click/clickAndWait – performs a click operation, and optionally waits for a new page to load.
“click” command is used, when you want to click on any element like Link/ Text box/radio button/ check box etc of your software web application.
Note: If the click action causes a new page to load (like a link usually does), use command ‘waitForPageToLoad’
‘ClickAndWait’ : ClickAndWait command clicks on a link and waits for to load page. If you select click command, it will not wait until next page loads. So your next command will get failed.
Note: The “clickAndWait” command uses the default timeout value present at the Options menu for the IDE, while in “click” + “waitForPageToLoad” we have to specify it by hand, therefore it can be bigger or smaller than the default. or you can use “wait” command.
verifyTitle/assertTitle – gets the title of the current page. verifies an expected page title.
Difference between Verify and assert is, When an “assert” fails, the test will be aborted. If a “verify” fails, the test will continue executing and logging the failure.
verifyTextPresent– verifies expected text is somewhere on the page.
verifyElementPresent -verifies an expected UI element, as defined by its HTML tag, is present on the page.
verifyText – verifies expected text and it’s corresponding HTML tag are present on the page.
verifyTable – verifies a table’s expected contents.
waitForPageToLoad -pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
waitForElementPresent -pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
store: To store the value
variableName – the name of a variable in which the result is to be stored. In the below example, WELCOME is stored in w, when you call echo, The result will be printed.
This command is a synonym for storeExpression.
echo: Toprint the message
This command prints the specified message into the third table cell in your Selenese tables. Useful for debugging, you can see the result in “Log”(shown below)