Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Selenium Design Patterns and Best Practices

You're reading from   Selenium Design Patterns and Best Practices Build a powerful, stable, and automated test suite using Selenium WebDriver

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher
ISBN-13 9781783982707
Length 270 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Dima Kovalenko Dima Kovalenko
Author Profile Icon Dima Kovalenko
Dima Kovalenko
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Writing the First Test FREE CHAPTER 2. The Spaghetti Pattern 3. Refactoring Tests 4. Data-driven Testing 5. Stabilizing the Tests 6. Testing the Behavior 7. The Page Objects Pattern 8. Growing the Test Suite A. Getting Started with Selenium Index

Getting started with the Selenium IDE

Now, let's get our hands dirty! We will be playing with Selenium Interactive Development Environment (Selenium IDE or simply IDE) in this section. IDE is one of the greatest starting points for the Selenium project. It allows someone who has never programmed in his or her life to record a useful test in a matter of minutes and start adding new tests to the test suite in no time.

Installing the Selenium IDE

Selenium IDE is a browser plugin that only works in Firefox browser. It is easy to install and integrates well with the functionality of the browser. Use these easy-to-follow steps to install the IDE in the browser:

  1. In your Firefox browser, navigate to the Selenium website at http://seleniumhq.org:
    Installing the Selenium IDE
  2. Click on the Download Selenium link on the home page shown:
    Installing the Selenium IDE
  3. In the Selenium IDE section on the Download page, click on the link for the latest released version, as shown here:
    Installing the Selenium IDE
  4. Allow Selenium to be installed on your computer by clicking on Allow on the following permission dialog:
    Installing the Selenium IDE
  5. The following dialog will show you all of the Selenium IDE components that will be installed on your browser. Click on Install Now when it becomes clickable after several seconds. The installation dialog is shown in the following screenshot:
    Installing the Selenium IDE
  6. Restart Firefox.

    Now that the plugins have been installed, you should see a little icon in the browser:

    Installing the Selenium IDE
  7. Clicking on that button will reveal the Selenium IDE window, as shown in the following screenshot:
    Installing the Selenium IDE

We are now ready to go!

Recording our first test

Just like many commercial testing tools, the Selenium IDE supports the Record-Playback style of writing tests. The IDE monitors your browser and notes down any actions that you perform. By compiling a list of actions, a test slowly emerges. Let's start recording our first test by following these steps:

  1. Open the Selenium IDE in the Firefox browser and make sure the recording mode is on, as shown in following screenshot:
    Recording our first test

    Note

    Note that the recording indicator is a little difficult to read since it does not change color when on or off. The main difference is a slightly light gray square around the button when it's on. This is one of several major drawbacks of Selenium IDE.

  2. In a new tab, navigate to http://awful-valentine.com, as shown in the following screenshot:
    Recording our first test
  3. Click on the search text field and type in cheese in the search bar and click on the submit button. The following screenshot shows the search box and the submit button:
    Recording our first test

    As we are performing these actions, the IDE is recording all of them in the background. We can inspect all of the recorded actions in the IDE window, as shown in the following screenshot:

    Recording our first test

Let's walk through the table inside the IDE window to get a better understanding of each item.

The table has three columns in it:

  • The first column is Command. This is where the action of the command is defined, such as a click or type.
  • The second column is Target, where the command will be performed.
  • Finally, the third column is Value. This section is only used when the target element, such as a text field, needs some text inserted into it.

We have our simple script now; let's save it so we can reuse it later.

Saving the test

Our next step is to save the test run to a file:

  1. Click on the File option:
    Saving the test
  2. Choose Save Test Case.
  3. Name the file search_test.html and save it.

Notice that we saved the test as an HTML file. This is because Selenese, the language that the IDE uses to record and playback tests, is just an HTML table. You can even open the search_test.html file in your web browser and see how it looks! In the following screenshot, we have Selenium IDE and the saved test opens side by side for easy comparison:

Saving the test

Right away, you can see that the IDE (on the left) and the saved Selenese output displayed in a web browser (on the right) look extremely similar.

You have been reading a chapter from
Selenium Design Patterns and Best Practices
Published in: Sep 2014
Publisher:
ISBN-13: 9781783982707
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image