2 - How To Use Selenium IDE With Scripts
2 - How To Use Selenium IDE With Scripts
Step 1
Step 2
In Firefox, navigate to http://newtours.demoaut.com/. Firefox should take you to the page similar to the
one shown below.
Step 3
Right-click on any blank space within the page, like on the Mercury Tours logo on the upper
left corner. This will bring up the Selenium IDE context menu. Note: Do not click on any
hyperlinked objects or images
Select the "Show Available Commands" option.
Then, select "assertTitle exact: Welcome: Mercury Tours." This is a command that makes sure
that the page title is correct.
Step 4
In the "User Name" text box of Mercury Tours, type an invalid username, "invalidUNN".
In the "Password" text box, type an invalid password, "invalidPWD".
Step 5
Click on the "Sign-In" button. Firefox should take you to this page.
Step 6
Toggle the record button off to stop recording. Your script should now look like the one shown below.
Step 7
Now that we are done with our test script, we shall save it in a test case. In the File menu, select "Save Test
Case". Alternatively, you can simply press Ctrl+S.
Step 8
Choose your desired location, and then name the test case as "Invalid_login".
Click the "Save" button.
Step 9.
Go back to Selenium IDE and click the Playback button to execute the whole script.
Selenium IDE should be able to replicate everything flawlessly.
3 Types of Commands
Actions These are commands that directly interact with page elements.
Example: the "click" command is an action because you directly interact with the element
you are clicking at.
The "type" command is also an action because you are putting values into a text box, and
the text box shows them to you in return. There is a two-way interaction between you and
the text box.
Accessors They are commands that allow you to store values to a variable.
Example: the "storeTitle" command is an accessor because it only "reads" the page title
and saves it in a variable. It does not interact with any element on the page.
3 Types of Assertions
Step 1
Step 2
Step 4
In Firebug, expand the <head> tag to display the <title> tag.
Click on the value of the <title> tag (which is "Welcome: Mercury Tours") and paste it onto the Target fi
in the Editor.
Step 5
To create the third command, click on the third blank line in the Editor and key-in "type" on the Comma
text box.
In Firebug, click on the "Inspect" button.
Click on the User Name text box. Notice that Firebug automatically shows you the HTML code for that element.
Step 6
Notice that the User Name text box does not have an ID, but it has a NAME attribute. We shall, therefore, use
NAME as the locator. Copy the NAME value and paste it onto the Target field in Selenium IDE.
Still in the Target text box, prefix "userName" with "name=", indicating that Selenium IDE should target
element whose NAME attribute is "userName."
Type "invalidUN " in the Value text box of Selenium IDE. Your test script should now look like the image belo
We are done with the third command. Note: Instead of invalidUN, you may enter any other text string. B
Selenium IDE is case sensitive, and you type values/attributes exactly like in the application.
Step 7
To create the fourth command, key- in "type" on the Command text box.
Again, use Firebug's "Inspect" button to get the locator for the "Password" text box.
Paste the NAM E attribute ("password") onto the Target field and prefix it with "name="
Type "invalidPW" in the Value field in Selenium IDE. Your test script should now look like the ima
below.
Step 8
For the fifth command, type "clickAndWait" on the Command text box in Selenium IDE.
Use Firebug's "Inspect" button to get the locator for the "Sign In" button.
Paste the value of the NAME attribute ("login") onto the Target text box and prefix it with "name=".
Your test script should now look like the image below.
Step 9
Save the test case in the same way as we did in the previous section.
The Find button in Selenium IDE is used to verify if what we had put in the
Target text box is indeed the correct UI element.
Let us use the Invalid_login test case that we created in the previous sections. Click
on any command with a Target entry, say, the third command.
Click on the Find button. Notice that the User Name text box within the Mercury
Tours page becomes highlighted for a second.
This indicates that Selenium IDE was able to detect and access the expected
element correctly. If the Find button highlighted a different element or no element at
all, then there must be something wrong with your script.
Execute Command
This allows you to execute any single command without running the whole
test case. Just click on the line you wish to execute and then either click on "Actions
> Execute this command" from the menu bar or simply press "X" on your keyboard.
Step 1. Make sure that your browser is on the Mercury Tours homepage. Click on the command you wish
to execute. In this example, click on the "type | userName | invalidUN" line.
Start point
A start point is an indicator that tells Selenium IDE which lines the execution
will start. Its shortcut key is "S".
In the example above, playback will start on the third line (type | password
| invalidPW). You can only have one start point in a single test script.
The start point is similar to Execute Command in such that they are dependent on
the currently displayed page. The start point will fail if you are on the wrong page.
Breakpoints
Breakpoints are indicators that tell Selenium IDE where to automatically pause the
test. The shortcut key is "B".
The yellow highlight means that the current step is pending. This proves that
Selenium IDE has paused execution on that step. You can have multiple
breakpoints in one test case.
Step
It allows you to execute succeeding commands one at a time after pausing the test
case. Let us use the scenario in the previous section "Breakpoints."
Selenium IDE works well only with HTML - other formats are still in
experimental mode. It is NOT advisable to create or edit tests using other formats
in Source View because there is still a lot of work needed to make it stable. Below
are the known bugs as of version 1.9.1.
You will not be able to perform playback nor switch back to Table View
unless you revert to HTML.
The only way to add commands safely on the source code is by
recording them.
When you modify the source code manually, all of it will be lost when
you switch to another format.
Though you can save your test case while in Source View, Selenium
IDE will not be able to open it.
The recommended way to convert Selenese tests is to use the "Export Test
Case As..." option under the File menu, and not through the Source View.