/ selenium

Using Selenium IDE

What is selenium IDE:

Selenium-IDE (Integrated Development Environment) is a tool that you use to develop your Selenium test cases. It’s a Firefox plug-in. The 'record' button in selenium IDE enables user to record his actions and is a real time saver. Although, many-a-times, due to the external plugins used in our app, we need to manually write scripts or atleast modify the recorded scripts.

Why should developers know about selenium IDE?

In many of our applications, we have multiple forms and features that require testing/checking whenever we make slightest of change in our code. Selenium IDE provides an easy way to record steps in the form of selenium scripts, rather than manually checking/testing every time. This saves a lot of time and all we need is a Firefox add-on.

Basic usage:

Some examples of basic usage of selenium IDE:

1) Navigating to an element:

css:

html > body > form

Xpath:

/html/body/form

2) Identify an input:

Consider an example of an input with id 'u1'

css:

input[id=u1]

or

input #u1

or simply,

u1 (If only one element is present with this id)

Xpath:

//input[@id='u1']

3) Locate an element based on a partial id:

Many-a-times, we have elements that have Ids like 'list_item_1', 'list_item_2' or '1_list_item', etc.

In such cases, selenium ide uses the following syntax:

A) locating an element which starts from an id (example 'list_item_1')

css:

input[id^=list_item]

Xpath:

//input[starts-with(@id,'submit')]

B) locating an element which ends from an id (example: '1_list_item')

css:

input[id*=list_item]

Xpath:

//input[contains(@id, 'list_item')]

The above identification of elements and basics of selenium ide are well explained in the following videos:

https://www.youtube.com/watch?v=h3MJtwzCdoY

https://www.youtube.com/watch?v=X6jc7UurmD4

Important observation:

While scripting with selenium IDE, many-a-times one might notice that their scripts indicated false failiure(or red tests). It is essential to identify the commands that cause these false negatives and to atmost avoid their usage.

One of the most commonly used event in selenium ide is the 'clickAndWait' event of selenium IDE. The clickAndWait event is mainly used when we have made a request and then we are asking the ide to wait for some time for recieving response from the server and then proceed furthur to execute next steps in the script.
The drawback of using this event is that, when the 'clickAndWait' expires, the command turns red(instead of green). This is an indication that the wait time has lapsed. Due to this, the end results/ outputs of the test is also indicated as 'red' or false failiure of the script. This can be misleading as the validations might be passing but your test might still be displaying a false failiure.

Thus, to avoid this we can replace 'clickAndWait' command with a cobination of two commands, as follows: 'Click' and then 'waitForElementPresent'. Using this combination a false negative is avoided. Other commonly used command that indicates a false negative is the 'pause' command.

Flow Control & Selenium IDE:

Adding flow control to selenium ide allows one to add multiple checks to their script. Some plugins enable adding flow control to our selenium scripts. One of the plugin is sideflow.js. The steps to install and use sideflow.js are mentioned on the following link:

http://51elliot.blogspot.in/2008/02/selenium-ide-goto.html

References:

[Selenium documentation][1]

[An Example of basic usage of selenium ide][2]

[List of all commands of selenium][3]
[1]: http://docs.seleniumhq.org/docs/02_selenium_ide.jsp
[2]: http://www.codediesel.com/php/selenium-ide-tutorial-part-1/
[3]: http://seleniummaster.com/sitecontent/index.php/introduction-to-selenium-automation/selenium-ide/114-selenium-ide-complete-list-of-commands