Selenium IDE Introduction
Selenium IDE (Integrated Development Environment) is a tool that we can use to develop automated test scripts. It has record-and-playback functionality, but we can also write the test scripts ourselves by manually entering the commands. It comes with a browser context menu with the most frequently used Selenium commands. It saves test execution time and is a good way to get familiar with test automation.
Further references
All the Selenium IDE commands are explained on the following location: http://release.seleniumhq.org/selenium-core/1.0.1/reference.html
Using Selenium IDE for the first time
Selenium IDE comes as a Firefox plug-in and has an easy-to-use user interface. Although the interface is very intuitive the most frequently used parts are explained in this section.
Prerequisites
As we are going to use Selenium IDE for the first time, the first thing we have to do is to make sure that Firefox and Selenium IDE are installed properly.
- Go to http://getfirefox.com and install Firefox.
- Go to http://seleniumhq.org/download/ in the Firefox browser and install Selenium IDE.
- Restart Firefox if requested.
In practice
We can now open Selenium IDE by using the following actions:
- Open Firefox
- Open Selenium IDE, via the
Tools
menu.
We just opened Selenium IDE and we can start recording test scripts by default..
There is more…
Selenium IDE is divided into sections which are numbered in the previous screenshot. Each section is explained below:
- MenubarThe menubar has options to
add
,open
andsave
test scripts and test suites. It also has some general edit options and it is even possible to specify a preferred programming language. - Base URLAllows test scripts to be run across different domains.
- ToolbarThe buttons in the toolbar are used to control the test scripts. Each button is explained below (starting from the left):
- Speed Control: Controls how fast your test script runs.
- Run All: Run all test scripts in Selenium IDE.
- Run: Run a single test script in Selenium IDE.
- Pause/Resume: Pause a running test script.
- Step: Step through the test script once it has been paused.
- Apply Rollup Rules: This allows us to group a sequence of actions into a single action.
- Record: The record button. It will be enabled when Selenium IDE is recording.
- test script paneThe test script commands are displayed in the test script pane. There is one tab which shows us the script in the three-column table format. The other tab shows us the script in a preferred language.The Command, Target and value textfields are corresponding to the three-column table structure. It is possible to edit the values by clicking on a specific row. Those three fields are explained below:
- Command: This select box has a list of all the Selenium commands. It is possible to type into it to use the auto complete functionality or use it as a dropdown. Some reference information is shown in the reference pane at the bottom once a specific action is selected.
- Action: The first parameter specified for a command in the Reference tab of the bottom pane always goes in the Target field.
- Value: If a second parameter is specified by the Reference tab, it always goes in the Value field.
- Test suite paneShows the test scripts in the current test-suite along with the results.
- Log/Reference paneThe bottom pane is used for four different functions divided in separate tabs, like:
Log
,Reference
,UI-Element
, andRollup
information. Each function is explained below:- Log: Error messages and information messages are shown while the test is running.
- Reference: Displays the documentation of the command actually selected.
- UI-Element: Displays the UI-element mappings actually in use.
- Rollup: Shows rollup rules.
Record a test script
In this tutorial we are going to record a test script with Selenium IDE.
Prerequisites
Ensure that the record button is enabled. Selenium IDE automatically opens in record mode, otherwise you need to click on the (red) record button in the right top corner.
In practice
- Open the website under test in the Firefox browser. In this case we will use: http://selenium.polteq.com/testshop/.
- Open Selenium IDE, via the
Tools
menu. - Start recording by pressing the
record
button in the right top corner, if needed. - Search for ‘iPod’ and click on the search button.
- Validate that the text ‘iPod shuffle’ is present in the search results list. We can do that by selecting the text and opening the context menu (right-click) and select
assertText
.
The test script will end up like this:
COMMAND | ||
---|---|---|
open | ||
type | ||
clickAndWait | ||
assertText |
Selenese test cases are HTML based, so do not forget to add the HTML extension once you save the test case.We can change the Locator Builder settings in Options -> Options… -> Locator Builders tab. It’s a good practice to put CSS on top.
Modify a test script
In this tutorial we will modify a test script by adding some commands manually.
Prerequisites
We can use the test script created in the previous tutorial, but now we want to change the language without recording the test again.
In practice
- Open the previous recorded test script.
- Select the row where we want to put an extra command.
- Ensure that record mode is enabled.
- Click on a specific language.
- Disable record mode.
The test script will end up like this:
COMMAND | ||
---|---|---|
open | ||
click | ||
type | ||
clickAndWait | ||
assertText |
We just added an extra command to our previous recorded test script.
Store information from the page
With Selenium IDE we can store data and use it later. There are a couple of actions to store data, like:
store
, storeValue
, storeText
.In practice
We like to store the text from a specific link and print it to the log panel. Obviously you can also use the text (which is stored in a variable) in the next test step.
- Open the previously recorded test script.
- Select the last row.
- Insert two new rows by opening the context menu (right-click) and select
Insert New Command
- Add a
storeText
command to store the text of a given element. - Add a
echo
command to display the content of the variable in the log panel.
The test script will end up like this:
COMMAND | ||
---|---|---|
open | ||
type | ||
clickAndWait | ||
storeText | ||
echo | ||
assertText |
The output of the script above is:
[info] echo: iPod shuffle
Selenium uses a JavaScript map called
storedVars
to store the data.Dealing with AJAX functionality
Some websites are using AJAX to modify the graphical user interface (GUI) without being reloaded. In this tutorial we are going to record website functionality which is using AJAX. We can use
waitFor
commands, like: waitForAlertNotPresent
, waitForAlertPresent
, waitForElementPresent
, waitForElementNotPresent
, waitForTextPresent
, etc.In practice
- Open the website under test in the Firefox browser. In this case we will use: http://selenium.polteq.com/testshop/.
- Open Selenium IDE, via the
Tools
menu. - Start recording by pressing the
record
button in the right top corner, if needed. - Add a product to the cart by performing the following actions: navigate to the ‘laptop’ category, view an item and click on the ‘add to cart’ button.
- Verify that the product is added to the cart, by right clicking on the items name in the cart and select
waitForText
. - Delete the item from the cart, by clicking on the remove icon next to the item name.
- Verify that the text ‘no product’ is present in the cart, we can do that by selecting the text and opening the context menu (right-click) and select
waitForElementPresent
. - Stop recording by clicking on the record button and try to execute the recorded test script by clicking on the play button.
The test script will end up like this:
COMMAND | ||
---|---|---|
open | ||
clickAndWait | ||
clickAndWait | ||
click | ||
waitForText | ||
click | ||
waitForElementPresent |
Selenese test cases are HTML based, so do not forget to add the HTML extension once you save the test case.
Create test suites
A test suite is a collection of test scripts. In this tutorial we are going to take a closer look on how to create a test suite.
In practice
- Create a test script as described in the previous tutorials.
- Select
File
->New Test Case
to create a new test script. (or open the context menu from the left panel and selectNew Test Case
) - Repeat step 1 and 2 as many times you want.
- Select
File
->Save Test Suite
to save all test scripts.
Selenese test suites are HTML based, so do not forget to add the HTML extension once you save the test case.
Exexute test scripts in different browsers
In this tutorial we are going to execute test scripts in different browsers.
Prerequisites
It is necessary to download the
Selenium standalone server
, IEDriverServer
and chromedriver
. (http://code.google.com/p/selenium/downloads/list)In practice
- We need to start Selenium standalone server by entering the following command in the commandline:
- We need to enable
WebDriver Playback
in Selenium IDE.Options
->Options...
->WebDriver
tab and checkEnable WebDriver Playback
- Specify in which browser we like to run our test scripts
Options
->Options...
->WebDriver
tab and specify the browser in the textfield. (chrome, firefox, internet explorer and so on)
Now you can run your test script with WebDriver in the specified browser.
No comments:
Post a Comment