Web Application that we are going to test will be the Mercury Tours website. This website provides an online flight reservation system, and so it contains all the elements we need. The URL of this website is http://newtours.demoaut.com/, which will also be our Base URL.
Steps to create a test script by Recording
Now we are going to create our first test script using the most common method of Selenium IDE that is by recording. After that, we will execute our script using the playback feature of Selenium IDE.
- First of all, we will launch the Firefox browser and then go to Selenium IDE.
Then we will type the Base URL: http://newtours.demoaut.com/ and toggle the Record button on (if it is not toggled on by default).
Navigate to http://newtours.demoaut.com/ in Firefox.
- Right-click anywhere on the page, and it will bring the Selenium IDE context menu. Make sure not to click on any hyperlinked objects or images.
- Type any invalid username like ABC in the User Name text box.
- Type any invalid password like 123 in the Password text box.
Finally, click on the “Sign-In” button and then you will be navigated to the page which will look like this:
To stop recording again, Toggle the record button as off.
We will now save the test script in a test case. For this, click on the Save button on the right corner in the menu bar.
- Choose the location for saving the test case and then given any name to the Test Case (e.g., “First Test Case.”)
- Now click on the “Save” button.
The file will get saved with .side extension.
Now to execute the complete script, go back to Selenium IDE and click on the Playback, i.e., Run current test case button. Selenium IDE should be able to clone perfectly everything.
- The maximum two parameters can be used in the Selenese command: Target and Value.
- The requirement of parameters depends on the Command.
There are three types of commands
- Commands that are used to interact with page elements are Actions.
- Example: Click command can be considered as an action because it directly interacts with the element you want to click.
- Another Example is the Type command where we put values into a text box, and the text box displays them in return, creating a two-way interaction between you and the text box.
- Commands used to store values to a variable.
- Example: StoreTitle is considered as an accessor because its only use is to read the page title and stores it in a variable. It does not create any interaction with any element on the web page.
- These commands are used to verify if a specific condition is met or not.
There are three types of Assertions
1] Assert: Failure of assert command stops the test immediately.
2] Verify: In case of verifying command failure, Selenium IDE will first log this failure, and then it will continue with the test execution.
3] WaitFor: waitFor command will first wait for a particular condition to become true before proceeding to the next command.
- Step passes when the condition becomes true within the waiting period.
- Step fails in case the condition is not met and becomes false. It will then log the failure and continues with the execution of the next command.
Some common Commands Used in Selenium IDE
Steps to create a Script Manually
We will now create the test script manually by typing the commands with the help of Inspect Element.
Step 1: Launch Firefox and Selenium IDE and type the base URL (http://newtours.demoaut.com/), ensuring that the record button is OFF.
Step 2: Click on the blank line in the Editor and type Open in the command box. Then press Enter.
- Navigate to the base URL and right-click anywhere and then select option Inspect element.
- Select the second line in the editor and enter the second command by typing “type “using the autocomplete feature.
- Click and paste the value of the <input> tag (that is “userName”) in the Target field.
- For creating the third command, click on the third blank line in the Editor and type the command in the text box.
- Click on the “Inspect” button.
- After clicking on the User Name text box, you will notice that it will automatically start displaying the HTML code for that element.
- We will see that the User Name text box has a NAME attribute instead of ID attribute and so we will use its NAME as the locator. We will copy and paste the NAME value in the Target field.
- Prefix “userName” with “name=” which indicates that Selenium IDE will look for an element whose NAME attribute is “userName.”
Type any invalid value in the text box “Value” of Selenium IDE.
Follow steps 4, 5, and 6 for the password field as well.
Now get the locator for “Login” in the same way and prefix it with “name=.”
As done in the previous section to save the test, follow the same process.
It tells the Selenium IDE from where to start the execution of a test case, and its shortcut key is “S.” Please note that there can be only one start point in a single test script.
Breakpoint tells the Selenium IDE where to stop the test or pause the execution. The shortcut key for the breakpoint is “B.” There can be multiple breakpoints in a single test script.