Categories: ProgrammingTutorials

Quick Start into Selenium Tests

3 min read

(For more resources related to this topic, see here.)

Step 1 – Recording and adding commands in a test

In this section we will show you how to record a test on a demo e-commerce application. We will test the product search feature of the application using the following steps:

  1. Launch the Firefox browser.

  2. Open the website for testing in the Firefox browser. For this example we will use http://demo.magentocommerce.com/.

  3. Open Selenium IDE from the Tools menu.

  4. Selenium IDE by default sets the recording mode on. If it’s not pressed, you can start recording by pressing the (record) button in the top-right corner.

  5. Now switch back to the Firefox browser window and type Nokia in the search textbox and click on the Search button as shown:

  6. Check if the link Nokia 2610 Phone is present in the search results. We can do that by selecting the link and opening the context menu (right-click) and selecting Show All Available Commands | assertElementPresent link=Nokia 2610 Phone.

  7. Next, we will click on the Nokia 2610 Phone link to open the product page and check if the Nokia 2610 Phone text is displayed on the product page. To do this, select the Nokia 2610 Phone text and open the context menu (right-click) and select Show All Available Commands | assertTextPresent link=Nokia 2610 Phone:

  8. Go back to Selenium IDE. All the previous steps are recorded by Selenium IDE in the Command-Target-Value format as shown in the following screenshot. Stop the recording session by clicking on the Recording button:

Step 2 – Saving the recorded test

Before we play back the recorded test, let’s save it in Selenium IDE:

  1. Select File | Save Test Case from the Selenium IDE main menu:

  2. In the Save As dialog box, enter the test case name as SearchTest.html and click on the Save button. The test will be saved with the name SearchTest.

Step 3 – Saving the test suite

In Selenium IDE, we can group multiple tests in a test suite. Let’s create a test suite and Selenium IDE will automatically add SearchTest to this suite:

  1. Select File | Save Test Suite from the Selenium IDE main menu.

  2. In the Save As dialog box, enter the test case name as SearchFeatureTests.html and click on the Save button.

  3. You can create and record more than one test case in a test suite.

Step 4 – Running the recorded test

Selenium IDE provides multiple ways to execute the tests:

  • Option 1 – running a single test case

    1. Select the test which you want to execute from the test suite pane and click on the (play current test case) button .

    2. Selenium IDE will start the playback of the test and you can see the steps that we recorded earlier are being played automatically in the browser window. At end of execution, Selenium IDE will display results as per the following screenshot:

  • Option 2 – running all tests from a test suite

    If you have multiple tests in a test suite, you can use the (play the entire test suite) button to play all the test cases.

    After the test is executed in Selenium IDE, you can see the results in Log tab. All the steps which are successfully completed will be heighted in green and checks in dark green. If there are any failures in the test, those will be highlighted in red. This is how Selenium IDE helps you testing your web application.

Summary

We learned how to record a test, save a test case, enhance a test by adding commands, and run a test with Selenium IDE. This article also got you started on with programming with Selenium WebDriver.

Resources for Article :


Further resources on this subject:


Packt

Share
Published by
Packt

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago