7h. Selenium IDE – A glance on the Selenium commands

Welcome to yet another interesting post on Selenium IDE. Today, let us unwrap the mysteries of the commands that we see in the test script pane upon recording a test scenario. Sample is as follows,

Test Script

Big Word Alert! Selenese – It is nothing but a set of selenium commands. A sequence of these commands forms a test script. Each line is a Selenium command which has three parts viz., Command, Target and Value.

Command – What to do/What action needs to be performed

Target – Where (web element) the action has to take place

Value – Which data has to be passed to the target

Some commands do not always require a Target and Value. Example, “close” command is used to close a window. Whereas “click” command requires a target and “type” command expects both target and value.

Selenium commands come in three different flavors: Actions, Accessors and Assertions.

Actions:

These commands manipulate the state of the application by interacting with the web elements directly. If an Action fails or an error occurs, then the current test execution stops. The following commands in that test script will not be executed.

Let us see some examples to stick this to our brain,

CommandDescription
type ( locator,value )Sets the value of an input field, as though you typed it in.
click ( locator )Clicks on a link, button, checkbox or radio button
Close()Simulates the user clicking the “close” button in the titlebar of a popup window or tab
echo ( message )Prints the specified message into the third table cell in your Selenese tables. Useful for debugging.
focus ( locator )Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field.
open ( url )Opens an URL in the test frame. This accepts both relative and absolute URLs.
setTimeout ( timeout )Specifies the amount of time that Selenium will wait for actions to complete.

 

Most of these actions are called with a suffix, “AndWait”, e.g. “clickAndWait”. This suffix makes sure that Selenium waits for the new page or element to load.

Accessors:

These commands are used to examine the state of the application. These let us store the results in user defined variables which can be used for the purpose of assertions. They do not interact directly with the elements of the page.

Example, “storeAllLinks” will read the IDs of all links on the page and store them in a user defined variable. If the result has multiple values, then the variable will be of array type.

Assertions:

These are similar to accessors as they also do not interact directly with the web elements. Assertions are mainly used to verify if the application state confirms to what is expected.

Assertions come in three modes,

assert” – When an “assert” fails, test execution is stopped immediately. Rest of the test script is not executed.

verify” – when a “verify” fails, Selenium IDE logs the failure in red color and the execution continues.

waitFor” – waits for a certain condition to become true before proceeding to the next command. By default, the timeout value is set to 30 seconds. This can be changed to the desired value. Upon failure, the test execution continues with the next steps. Failure is logged in Selenium IDE logs pane.

CommandDescription
verifyTitle/assertTitleverifies an expected page title
verifyElementPresentverifies an expected UI element, as defined by its HTML tag, is present on the page
verifyTextverifies expected text and its corresponding HTML tag are present on the page
verifyTableverifies a table’s expected contents
waitForPageToLoadpauses execution until an expected new page loads. Called automatically when clickAndWait is used
waitForElementPresentpauses execution until an expected UI element, as defined by its HTML tag, is present on the page

 

More on “assert” and “verify” in upcoming blogs! Keep practicing different scenarios until then. A complete reference on these commands can be found in the official website, here.

See you again in another post. Have a great day!

Series Navigation<< 7g. Selenium IDE – Recording and running a test case7i. Selenium IDE – Setting timeouts, breakpoints, start points >>
By | 2017-07-10T19:14:41+00:00 September 12th, 2016|Selenium|0 Comments

About the Author:

Lakshmi Chandana is a Software professional + passion-fueled blogger + novel-reader + artist + tutor to make your day a little brighter than it was before! She is thrilled you are here! She is on a mission to make sure learning sticks but with the fun part kept intact. She uses certain tricks called BrainBells (inspired from barbells and dumbbells used for a workout) to achieve this and she says, “this is not the hardest job! As once minions said, it for sure is working in a bubble wrap factory. Imagine the self-control needed!” So, dive in to explore the fun-filled World of Selenium!!

Leave A Comment