In this article we are going to discuss about how to record your First Selenium IDE script. Before going any further it is highly recommended to understand the features of IDE window.

Note : During this article and going forward we will be using Base URL : www.testingjournals.com for all our examples in representing Selenium features. We will be focusing on implementation of Basic IDE features only and keeping all complex fancy stuff for upcoming tutorials.

To make it more understandable, let’s divide whole process in three different phases :


Phase 1: Recording / Formation of Selenium IDE Script

Phase 2: Stability & Execution

Phase 3: Exporting Test Case / Test Suite

Before we start recording, let’s have a look at the scenario we are going to automate : First we will hit Base URL “www.testingjournals.com” –> Search with keyword “Selenium” from the Side bar –> Click on the Blog titled as : Selenium IDE : Your First Automation Script –> Verify the text present “Recording / Formation of Selenium IDE Script”.

1) Recording / Formation of Selenium IDE Script

Pre-condition : Mozilla Firefox is up and running with Selenium IDE installed as a plugin.

– Open Selenium IDE.
– In Base URL bar, provide : www.testingjournals.com
– Make sure that Record Button is on.

ide_firstscript_baseURL

– Now in the browser window hit the same Base URL and wait till the landing page gets loaded.
– To make sure that we have accessed the perfect page there is a command we an use called “verifyTitle”. You can manually provide in the Command section and set the expected value in the Target section. Or there is another way, right click anywhere on the web page and you will see an option verify Title along with the Target. Select that option, you will see that command loaded on Selenium IDE Editor screen.

verify_title

verify_title_command

– Going further you will see a Search box in the Right side bar. Provide keyword “Selenium” into that search bar and click Search button.
– Two more commands will be loaded on IDE Editor : Type and Click. If you will focus on Target field for these two commands, you’ll see Selenium IDE has recorded CSS Locators by default. You can change these locators by clicking on down arrow and select any available target. Click Here to read more about Locators.

selenium_search_command

– You will be landed on a page having all the articles displayed for search parameter : “Selenium”. Now we want to click on article link : “Selenium IDE : Your First Automation Script”. Last step would be assert text present “Recording / Formation of Selenium IDE Script”.

selenium_ide_firstscript_complete

So we are done with recording our first very basic Selenium IDE script. We have used multiple commands like verifyTitle, type, clickAndWait and assertTextPresent. Now, lets try executing the script.

2) Stability & Execution

Keep the Log panel open and just hit the Play button from Selenium IDE window. It will start executing all the commands on Mozilla Firefox browser. Once the execution is completed, your Selenium IDE window will look like this.

selenium_ide_execution

You will also face such situations where your script will fail due to undesirable scenarios like : late server response, frequently changing locator values and the most evil, change in the requirements. In all such cases, stability of your automation script is substantial. It needs timely maintenance to preserve the stability.

3) Export Test Case / Test Suite

All you need to do is save your test case. Pretty simple, press Ctrl+S OR select File -> Save Test Case. Provide the name of your test case, provide the desired location and click on Save button. Test case will be saved in HTML format to the location provided by you.

– In future you can access the same script, click on File -> Open.. and open the same HTML file you exported last time. All your commands and steps will be loaded once you import the script.

Use of Find Button :

In simple words, “Find Button” locates and highlights the selected element(from IDE Editor) on the web page. Before clicking Find button you will have to select the desired command from the IDE editor window. Entire element background gets highlighted for merely 1 second, enough to give you assurance about the element being present on the screen. Click on below image to expand.

find_button

– If selected element is not available on the screen, it will show [error] locator not found in the Log section.

Set / Clear Start Point :

It is possible to start the execution of you Selenium IDE script from any step or command. You just need to Set the Start point to that command. Now, you can add the start point in the three ways : Select the command and 1) Click Action from Menu Bar -> Set / Clear Start Point 2) Press “s” from the keyboard and 3) Right click on the test step and select “Set / Clear Start Point”. Once the start point is set, you can see a Play Icon displayed in stating of the test command.

– When running the test case, execution will trigger from the Test command on which you have Set the start point. So, you need to make sure that same web page is opened in Firefox browser from where you execution is supposed to start after setting the Start Point.

set_startpoint

– You can remove or clear the Start point the same way it has been set. You can not set more than one Start point in a single test script.

Toggle Breakpoint :

Selenium IDE also lets you to set the Break Point anywhere in the Test Script. Break Point can be added if you want to pause the execution at any point and not let all the commands execute from the script. Purpose is simple, you want to execute smaller bunch of commands from the entire script rather than running all the commands.

Toggle Break Point can be added in the three ways : Select the command and 1) Click Action from Menu Bar -> Toggle Breakpoint 2) Press “b” from the keyboard and 3) Right click on the test step and select “Toggle Breakpoint”. Once the Breakpoint is set, you can see a Pause Icon displayed in stating of the test command.

toggle_breakpoint

– When running the test case, execution will be paused at the Test command on which you have Set the Breakpoint. You can remove or clear the Breakpoint the same way it has been set. You can set more than one Breakpoint in a single test script. By providing multiple Breakpoints you can review your execution step-by-step and find the root cause of failures.

Selenium IDE Commands In Detail :

As discussed earlier, any Selenium IDE step is having 3 parameters : Commands, Target & Value.

selenium_command

Commands : Here you provide the name of an Action to be performed on the Target.

Target : Location of the web element on which the command is to be executed.

Value : Any parameter or string to be passed along with the command to perform the test step.

Basically there are three types of Selenium Commands :

1) Actions
2) Accessors
3) Assertions

Actions :

These type of commands are used to perform some actions on a web element. They directly interact with the web page by clicking on it or typing the parameter passed in Value field. In above example we have used Action command : “Type”. When we will execute this command, it will directly talk with the element having “id=search” and will provide the value “selenium” into the text box.

Same way, there are action commands like “click”, “clickAndWait”, “doubleClick” etc.

Accessors :

To store the values in a variable, Accessors commands are used. These type of commands do not interact with web page or any element. Values stored in accessors can be used anywhere in the test script for assertion or verification
purpose.

For Example, “storeAllButtons” command is an accessor, because it stores IDs of all buttons present on the web page and allows user to use later on.

Assertions :

Assertions also do not interact with the web elements. They verify if the provided conditions are fulfilled or not. There are three forms of Assertions,

– Assert : These commands verify the given condition is getting passed or not. Upon failure it aborts the execution.

– Verify : These commands also verify the given condition is getting passed or not. Upon failure it does not abort the execution, the execution continues and the particular command gets failed.

– WaitFor : These commands wait for the given condition to be passed before going further into the execution. For example “waitForElementPresent”, this command will wait for the element to be present(will return True if present) and than pursue with the following commands.

Default timeout value is 30 seconds. User can also provide the desired timout. If the condition is passed within the given period, Test Step is passed otherwise failure is logged and execution continues to the next command.

Click here to discuss about most frequently used Selenium IDE commands.

So, we are done with our very basic Selenium IDE script. It’s time to throw more light on Locators.


Share This Article :