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
Learning Selenium Testing Tools - Third Edition
Learning Selenium Testing Tools - Third Edition

Learning Selenium Testing Tools - Third Edition: Leverage the power of Selenium to build your own real-time test cases from scratch , Third Edition

eBook
R$49.99 R$218.99
Paperback
R$272.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Learning Selenium Testing Tools - Third Edition

Chapter 1. Getting Started with Selenium IDE

Test automation has grown in popularity over the years because developers do not have the time or money to invest in large test teams to make sure that applications work as they are expected. Developers also want to make sure that the code they have created works as they expect it to.

Jason Huggins saw this issue too and wanted to make sure that any system he was working on would work on multiple operating systems and browsers. So he created Selenium.

Selenium IDE is a fully-featured IDE (Integrated Development Environment) that installs as a plugin in Mozilla Firefox and enables developers to test their web applications through Selenium. With the Selenium IDE, you can record user interactions with the web browser and play them back to test for errors. It's a powerful, robust IDE that radically simplifies and automates the QA testing process.

Selenium is one of the most well-known testing frameworks in the world that is in use. It is an open source project that allows testers and developers alike to develop functional tests to drive the browser. It can be used to record workflows so that it reduces the time in regression testing. Selenium can work on any browser that supports JavaScript, since Selenium has been built using JavaScript.

In this chapter, you will learn the basics of the Selenium IDE, how to use it, and how to locate a web element on a web page. We shall cover the following topics:

  • What is Selenium IDE
  • Recording our first test
  • Updating tests to work with AJAX sites
  • Using variables in our tests
  • Debugging tests
  • Saving tests to be used later
  • Creating and saving test suites

Note

So, let's get on with it...

Before we start working through this chapter, we need to make sure that Mozilla Firefox is installed on your machine. If you do not have Mozilla Firefox installed, you will need to download it from http://www.getfirefox.com/.

Understanding Selenium IDE

Selenium IDE is a Firefox add-on developed originally by Shinya Kasatani as a way to use the original Selenium Core code without having to copy Selenium Core onto the server. Selenium Core is the key JavaScript module that allows Selenium to drive the browser. It has been developed using JavaScript so that it can interact with DOM (Document Object Model) using native JavaScript calls.

Selenium IDE was developed to allow testers and developers to record their actions as they follow the workflow that they need to test.

Installing Selenium IDE

Now that we understand what Selenium IDE is, it is a good time to install it. At the end of these steps, you will have successfully installed Selenium IDE onto your computer:

  1. Go to http://seleniumhq.org/download/.
  2. Click on the download link for Selenium IDE. You may see a message appear saying Firefox prevented this site (seleniumhq.org) from asking you to install software on your computer. If you do, click the Allow button.
  3. A Firefox prompt will appear, as shown in the following screenshot:
    Installing Selenium IDE
  4. You will then be asked if you would like to install Selenium IDE and the exporter add-ons. These have been made pluggable to the IDE by the work that Adam Goucher did. You will see a screenshot similar to the following one:
    Installing Selenium IDE
  5. Click on Install button. This will now install Selenium IDE and formatters as Firefox add-ons.
  6. Once the installation process is complete, it will ask you to restart Firefox. Click the Restart Now button. Firefox will close and then reopen. If you have anything open in another browser, it might be worth saving your work as Firefox will try to go back to its original state. However, this cannot be guaranteed.
    Installing Selenium IDE
  7. Once the installation is complete, the add-ons window will show the Selenium IDE and its current version:
    Installing Selenium IDE

You have successfully installed Selenium IDE and we can start thinking about writing our first test.

Getting acquainted with the Selenium IDE tool

Now that Selenium IDE has been installed, let's take some time to familiarize ourselves with it. This will give us the foundation that we can use in later chapters. Open up Selenium IDE by going through the tools menu in Mozilla Firefox. Navigate to Tools | Selenium IDE. A window will appear. If the menu bar is not available, which is now the default in Firefox, you can launch Selenium IDE via Firefox | Web Developer | Selenium IDE.

Getting acquainted with the Selenium IDE tool

Starting from the top, I will explain what each of the items are:

  • Base URL: This is the URL that the test will start at. All open commands will be relative to Base URL unless a full path is inserted in the open command.
  • Speed Slider: This is the slider under the Fast and Slow labels in the screenshot.
  • Getting acquainted with the Selenium IDE tool: This play entire test suite icon runs all the tests in the IDE.
  • Getting acquainted with the Selenium IDE tool: This play current test case icon runs a single test in the IDE.
  • Getting acquainted with the Selenium IDE tool: This pause/resume icon pauses a test that is currently running.
  • Getting acquainted with the Selenium IDE tool: This step icon steps through the test once it has paused.
  • Getting acquainted with the Selenium IDE tool: This is the record button. This will be engaged when the test is recording.
  • The Command drop-down list has a list of all the commands that are needed to create a test. You can type into it to use the autocomplete functionality or use it as a dropdown.
  • The Target textbox allows you to input the location of the element that you want to work against.
  • The Find button, once the target box is populated, can be clicked to highlight the element on the page.
  • The Value textbox is where you place the value that needs to change. For example, if you want your test to type in an input box on the web page, you will put what you want it to type in the value box.
  • The Table tab will keep track of all your commands, targets, and values. It has been structured this way because the original version of Selenium was styled on FIT tests. FIT (Framework for Integrated Testing) was created by Ward Cunningham. The tests were originally designed to be run from HTML files and the IDE keeps this idea for its tests.
  • If you click the Source tab, you will be able to see the HTML that will store the test. Each of the rows will look like this:
      <tr>
        <td>open</td>
        <td>/chapter1</td>
        <td></td>
      </tr>
  • The area below the Value textbox will show the Selenium log while the tests are running. If an item fails, then it will have an [error] entry. This area will also show help on Selenium commands when you are working in the Command drop-down list. This can be extremely useful when typing commands into Selenium IDE instead of using the record feature.
  • The Log tab will show a log of what is happening during the test. The Reference tab gives you documentation on the command that you have highlighted, and is also useful if you forgot some command; users can just start writing command in the Command field, then select some like searched and read the reference.

Rules in creating tests with Selenium IDE

Now that we have installed Selenium IDE and understand what it is, we can think about working through our first tests. There are a few things that you need to consider when creating your first test. These rules apply to any form of test automation but need to be adhered to, especially when creating tests against a user interface:

  • Tests should always have a known starting point. In the context of Selenium, this can mean opening a certain page to start a workflow.
  • Tests should not have to rely on any other tests to run. If a test is going to add something, do not have a separate test to delete it. This is to ensure that if something goes wrong in one test, it will not mean you have a lot of unnecessary failures to check.
  • Tests should only test one thing at a time.
  • Tests should clean up after themselves.

These rules, like most rules, can be broken. However, breaking them can mean that you may run into issues later on, and when you have hundreds, or even thousands of tests, these small issues can mean that large parts of a test suite are failing.

With these rules in mind, let's create our first Selenium IDE test.

Recording your first test with Selenium IDE

We will record our first test using Selenium IDE. To start recording the tests, we will need to start Mozilla Firefox. Once it has been loaded, you will need to start Selenium IDE. You will find it under the Tools drop-down menu in Mozilla Firefox or in the Web Developer drop-down menu. Once loaded, it will look like the next screenshot. Note that the record button is engaged when you first load the IDE.

To start recording your tests, let's do the following:

  1. When in the record mode, navigate to http://book.theautomatedtester.co.uk/chapter1.
  2. On the web application, do the following:
    1. Click on the record button (red-colored radio button).
    2. Select another value from the drop-down box, for example, Selenium RC.
    3. Click on the Home Page link.
    Recording your first test with Selenium IDE
  3. Your test has now been recorded and should look like the preceding screenshot.
  4. Click the play button that looks like this icon: Recording your first test with Selenium IDE
  5. Once your test has completed, it will look like the following screenshot:
    Recording your first test with Selenium IDE

We have successfully recorded our first test and played it back. As we can see, Selenium IDE tried to apply the first rule of test automation by specifying the open command. It set the starting point of the test, in this case, /chapter1, and then it began stepping through the workflow that we want to record.

Once the actions have all been completed, you will see that all of the actions have a green background. This shows that they have completed successfully. On the left, you will see that it has completed one successful test, or run, within Selenium IDE. If you were to write a test that failed, the Failure label will have a 1 next to it.

Validating a test with assert and verify

In the last few steps, we were able to record a workflow that we would expect the user to perform. It will test that the relevant bit of functionality is there, such as buttons and links to work against. Unfortunately, we are not checking whether the other items on the page are there or if they are visible when they should be hidden. We will now work against the same page as before, but we shall make sure that different items are on the page.

There are two mechanisms for validating elements available on the application under test. The first is assert: this allows the test to check whether the element is on the page. If it is not available, then the test will stop on the step that failed. The second is verify: this allows the test to check if the element is on the page, but if it isn't, then the test will carry on execution. To add the assert or verify commands to the tests, we need to use the context menu that Selenium IDE adds to Firefox. All that one needs to do is right-click on the element if on Windows or Linux. If you have a Mac, then you will need to do the two-finger click to show the context menu.

When the context menu appears, it will look roughly like the following screenshot with the normal Firefox functions above it:

Validating a test with assert and verify

We will record the test and learn how to use/verify some commands as follows:

  1. Open the IDE so that we can start recording.
  2. Navigate to http://book.theautomatedtester.co.uk/chapter1.
  3. Select Selenium Grid from the drop-down box.
  4. Change the selection to Selenium Grid.
  5. Verify that the Assert that this text is on the page text is mentioned on the right-hand side of the drop-down box, by right-clicking on the text and selecting verifyText id=diveontheleft Assert that this text is on the page. You can see the command in the previous screenshot.
  6. Verify that the button is on the page. You will need to add a new command for verifyElementPresent with the verifybutton target in Selenium IDE.
  7. Now that you have completed the previous steps, your Selenium IDE should look like the following screenshot:
    Validating a test with assert and verify

If you now run the test, you will see it has verified that what you are expecting to see on the page has appeared. Notice that the verify commands have a darker green color. This is to show that they are more important to the test than moving through the steps. The test has now checked that the text we required is on the page and that the button is there too.

What will happen if the verify command did not find what it was expecting? The IDE would have thrown an error stating what was expected was not there, but then carried on with the rest of the test. We can see an example of this in the following screenshot:

Validating a test with assert and verify

The test would not have carried on if it was using assert as the mechanism for validating that the elements and text were loaded with the page.

We have just seen that we can add asserts or verification to the page. Selenium IDE does not do this when recording, so it will always be a manual step. The assert command will stop the running tests, unlike the verify command in which the tests will continue running even after failure. In both the cases, Selenium IDE will log an error. Each of these have their own merits.

Some of the verify and assert methods are as follows:

Selenium Command

Command Description

verifyElementPresent

This verifies an expected element is present on the page.

assertElementPresent

This asserts an expected element is present on the page.

verifyElementNotPresent

This verifies an expected element is not present on the page.

assertElementNotPresent

This asserts an expected element is not present on the page.

verifyText

This verifies expected text and its corresponding HTML tags are present on the page.

assertText

This asserts expected text and its corresponding HTML tags are present on the page.

verifyAttribute

This verifies the value of an attribute of any HTML tag on the page.

assertAttribute

This asserts the value of an attribute of any HTML tag on the page.

verifyChecked

This verifies whether the condition of the checkbox is checked or not on the page.

assertChecked

This asserts whether the condition of the checkbox is checked or not on the page.

verifyAlert

This verifies the alert present on the page.

assertAlert

This asserts the alert present on the page.

verifyTitle

This verifies an expected page title.

assertTitle

This asserts an expected page title.

Creating comments in your tests

Before we carry on further with Selenium, this is a good time to mention how to create comments in your tests. As all good software developers know, having readable code and having comments can make maintenance in the future much easier. Unlike in software development, it is extremely hard, almost impossible, to write self-documenting code. To combat this, it is good practice to make sure that your tests have comments that future software testers can use.

Adding Selenium IDE comments

To add comments to your tests, perform the following steps:

  1. In the test that was created earlier, right-click on a step. For example, the verify step.
  2. The Selenium IDE context menu will be visible as shown in the following screenshot:
    Adding Selenium IDE comments
  3. Click on Insert New Comment. A space will appear between the Selenium commands.
  4. Click on the Command textbox and enter in a comment so that you can use it for future maintenance. It will look like the following screenshot:
    Adding Selenium IDE comments

We just had a look at how to create comments. Comments will always appear as purple text in the IDE. This, like in most IDEs, is to help you spot comments quicker when looking through your test cases. Now that we know how to keep our tests maintainable with comments, let's carry on working with Selenium IDE to record/tweak/replay our scripts.

Multiplying windows

Web applications, unfortunately, do not live in one window of your browser. An example of this can be a site that shows reports. Most reports will have their own window so that people can easily move between them.

Unfortunately, in testing terms, this can be quite difficult to do, but in this section, we will have a look at creating a test that can move between windows.

Working with multiple windows

Working with multiple browser windows can be one of the most difficult things to do within a Selenium test. This is down to the fact that the browser needs to allow Selenium to programmatically know how many child browser processes have been spawned.

In the following examples, we will see the tests click on an element on the page that will cause a new window to appear. If you have a pop-up blocker running, it's a good idea to disable it for this site while you work through these examples. Open up Selenium IDE and go to the Chapter 1 page on the site and refer to the following steps:

  1. Click on one of the elements on the page that has the text Click this link to launch another window. This will cause a small window to appear.
  2. Verify the text in the popup by right-clicking and selecting VerifyText id=popup text within the popup window.
  3. Once the window has loaded, click on the Close the Window text inside it.
  4. Add a verify command for an element on the page. Your test should now look like the following screenshot:
    Working with multiple windows

Sometimes, Selenium IDE will add a clickAndWait command instead of a click command. This is because it notices that the page has to unload. If this happens, just change the clickAndWait command to a click so that it does not cause a timeout in the test.

In the test script, we can see that it has clicked on the item to load the new window and then has inserted a waitForPopUp command. This is so that your test knows that it has to wait for a web server to handle the request and the browser to render the page. Any commands that require a page to load from a web server will have a waitFor command. The next command is the selectWindow command. This command tells Selenium IDE that it will need to switch context to the window, called popupwindow, and will execute all the commands that follow in that window unless told otherwise by a later command.

Once the test has finished with the pop-up window, it will need to return to the parent window from where it started. To do this, we need to specify null as the window. This will force the selectWindow command to move the context of the test back to its parent window.

Complex working with multiple windows

In this example, we will open two pop-up windows and move between them and the parent window as it completes its steps:

  1. Start Selenium IDE and go to Chapter 1 on the website.
  2. Click on the Click this link to launch another window link. This will launch a pop-up window.
  3. Assert the text on the page. We do this by right-clicking and selecting assertText.
  4. Go back to the parent window and click on the link to launch the second pop-up window.
  5. Verify the text on the page.
  6. Move to the first pop-up window and close it using the close link. As before, be aware of clickAndWait instead of click.
  7. Move to the second pop-up window and close it using the close link.
  8. Move back to the parent window and verify an element on that page.
  9. Run your test and watch how it moves between the windows. When complete, it should look like the following screenshot:
    Complex working with multiple windows

We just had a look at creating a test that can move between multiple windows. We saw how we can move between the child windows and its parent window as though we were a user.

Selenium tests against AJAX applications

Web applications today are being designed in such a way that they appear the same as desktop applications. Web developers are accomplishing this by using AJAX within their web applications. AJAX (Asynchronous JavaScript And XML) relies on JavaScript creating asynchronous calls and then returning XML with the data that the user or application requires to carry on. AJAX does not rely on XML anymore, as more and more people move over to JSON (JavaScript Object Notation), which is more lightweight in the way it transfers the data. It does not rely on the extra overhead of opening and closing tags that is needed to create valid XML.

Working on pages with AJAX

In our example, we will click on a link and then assert that some text is visible on the screen:

  1. Start up Selenium IDE and make sure that the record button is pressed.
  2. Navigate to http://book.theautomatedtester.co.uk/chapter1.
  3. Click on the text that says Click this link to load a page with AJAX.
  4. Verify the text that appears on your screen. Your test should look like the following screenshot:
    Working on pages with AJAX
  5. Run the test that you have created. When it has finished running, it should look like the following screenshot:
    Working on pages with AJAX

Have a look at the page that you are working against. Can you see the text that the test is expecting? You should see it, so why has this test failed? The test has failed because when the test reached that point, the element containing the text was not loaded into the DOM. This is because it was being requested and rendered from the web server into the browser.

To remedy this issue, we will need to add a new command to our test so that our tests pass in the future:

  1. Right-click on the step that failed so that the Selenium IDE context menu appears.
  2. Click on Insert New Command.
  3. In the Command select box, type waitForElementPresent or select it from the drop-down menu.
  4. In the Target box, add the target that is used in the verifyText command.
  5. Run the test again and it should pass this time:
    Working on pages with AJAX

Selenium does not implicitly wait for the item that it needs to interact with, so it is seen as good practice to wait for the item you need to work with and then interact with it. The waitFor commands will timeout after 30 seconds by default, but if you need it to wait longer, you can specify the tests by using the setTimeout command. This will set the timeout value that the tests will use in future commands.

If need be, you can change the default wait if you go to Options | Options and then on the General tab, and under Default timeout value of recorded command in milliseconds (30s = 30,000ms) change it to what you want. Remember, 1,000 milliseconds = 1 second.

Working with AJAX applications

As more and more applications try to act like desktop applications, we need to be able to handle synchronization steps between our test and our application. In this section, we will see how to handle AJAX and what to synchronize:

  1. Navigate to http://book.theautomatedtester.co.uk/chapter1.
  2. Click on the load text to the page button.
  3. Wait for the text I have been added with a timeout. Your test will look like the following screenshot:
    Working with AJAX applications

In the previous examples, we waited for an element to appear on the page; there are a number of different commands that we can use to wait. Also, remember that we can take advantage of waiting for something not to be on the page, for example, waitForElementNotPresent. This can be just as effective as waiting for it to be there.

The following commands make up the waitFor set of commands, but this is not an exhaustive list:

Selenium Command

Command Description

waitForAlertNotPresent

This waits for an alert to disappear from the page.

waitForAlertPresent

This waits for an alert to appear on the page.

waitForElementPresent

This waits for an expected element to appear on the page.

waitForElementNotPresent

This waits for an expected element to disappear from the page.

waitForTextPresent

This waits for expected text and its corresponding HTML tags to appear on the page.

waitForTextNotPresent

This waits for expected text and its corresponding HTML tags to disappear from the page.

waitForPageToLoad

This waits for all elements to appear on the expected page.

waitForFrameToLoad

This waits for an expected frame and its corresponding HTML tags to appear on the page.

A number of these commands are run implicitly when other commands are being run. An example of this is the clickAndWait command. This will fire off a click command and then fire off a waitForPageToLoad command. Another example is the open command, which only completes when the page has fully loaded.

If you are feeling confident, then it's a good time to try different waitFor command techniques.

Storing information from the page in the test

Sometimes, there is a need to store elements that are on the page to be used later in a test. It could be that your test needs to pick a date that is on the page and use it later so that you do not need to hardcode values into your test.

Once the element has been stored, you will be able to use it again by requesting it from a JavaScript dictionary that Selenium keeps track of. To use the variable, it will take one of the following two formats: it can look like ${variableName} or storedVars['variableName']. I prefer the storedVars format as it follows the same format as within Selenium internals. To see how this works, let's work through the following example:

  1. Open up Selenium IDE and switch off the record button.
  2. Navigate to http://book.theautomatedtester.co.uk/chapter1.
  3. Right-click on the text Assert that this text is on the page and go to the storeText command in the context menu and click on it.
  4. A dialog will appear as shown in the following screenshot. Enter the name of a variable that you want to use. I have used textOnThePage as the name of my variable.
    Storing information from the page in the test
  5. Click on the row below the storeText command in Selenium IDE.
  6. Type type into the Command textbox.
  7. Type storeinput into the Target box.
  8. Type ${textOnThePage} into the Value box.
  9. Run the test. It should look like the following screenshot:
    Storing information from the page in the test

Once your test has completed running, you will see that it has placed Assert that this text is on the page into the textbox.

Debugging tests

We have successfully created a number of tests and have seen how we can work against AJAX applications, but unfortunately, creating tests that run perfectly the first time can be difficult. Sometimes, as a test automator, you will need to debug your tests to see what is wrong.

To work through this part of the chapter, you will need to have a test open in Selenium IDE.

These two steps are quite useful when your tests are not running and you want to execute a specific command. They are:

  1. Highlight a command.
  2. Press the X key. This will make the command execute in Selenium IDE.

When a test is running, you can press the pause button to pause the test after the step that is currently being run. Once the test has been paused, the step button is no longer disabled and you can press it to step through the test as if you were stepping through an application.

If you are having issues with elements on the page, you can type in their location and then click on the Find button. This will surround the element that you are looking for with a green border that flashes for a few seconds. It should look like the following screenshot:

Debugging tests

The echo command is also a good way to write something from your test to the log. This is equivalent to the Console.log code in JavaScript, for example, echo | ${textOnThePage}, as shown in the following screenshot:

Debugging tests

Also, remember that if you are trying to debug a test script that you have created with Selenium IDE, you can set breakpoints in your test. You simply right-click on the line and select breakpoint from the list. It will be similar to the following screenshot:

Debugging tests

You can also use the keyboard shortcut of B to allow you to do it quicker.

Creating test suites

We managed to create a number of tests using Selenium IDE and have managed to run them successfully. The next thing to have a look at is how to create a test suite, so that we can open the test suite and then have it run a number of tests that we have created. If you have Selenium IDE open from the last steps, click on the File menu:

  1. Click New Test Case.
  2. You will see that Selenium IDE has opened a new area on the left of the IDE as shown in the following screenshot:
    Creating test suites

You can do this as many times as you want, and when the Play entire test suite button is clicked, it will run all the tests in the test suite. It will log all the passes and failures at the bottom of the Test Case box.

To save this, click on the File menu and then click Save Test Suite and save the test suite file to a place where you can get to it again. One thing to note is that saving a test suite does not save the test case. Make sure that you save the test case every time you make a change and not just the test suite.

To change the name of the test case to something a lot more meaningful, you can do this by right-clicking on the test and clicking on the Properties item in the context menu:

Creating test suites

You can now add meaningful names to your tests and they will appear in Selenium IDE instead of falling back to their filenames.

We have managed to create our first test suite. This can be used to group tests together to be used later. If your tests have been saved, you can update the test suite properties to give the tests a name that is easier to read.

Parameterization

Parameterization is a key feature in automation testing. It is possible to give test data (parameter) as input in Selenium IDE as it is with any other automation tool. Selenium IDE requires configuration before proceeding for parameterization, which is explained in the following section.

After configuring Selenium IDE for parameterization, in the following example, we will search a text on Google and verify the text appears on the page. The storeEval command will read the search data from the google_search.js file and save it in the searchDataValue variable. With this variable, data types on the Google search page, verify Download Selenium IDE text using the assertTextPresent command. In this way, you can achieve data parameterization or data-driven testing by passing external data to a variable in Selenium IDE.

Selenium IDE Configuration

You need to create JavaScript file as the data source file. These are the steps to create JavaScript file and configure Selenium IDE:

  1. In a Notepad, create input data as follows:
    searchData = 'Selenium IDE'
  2. Save it as a file, say for example, google_search.js.
  3. Open Selenium IDE and choose the Option | Options… menu.
  4. Under Selenium IDE Extensions, browse the saved google_search.js file. After attaching the data file, your Selenium IDE option window will look like the following screenshot. Then, click OK and restart the Selenium IDE:
    Selenium IDE Configuration
  5. Now, record the script to perform Google search and verify the page element and update the commands as shown in the following screenshot. Then, execute the test. You can also use the WaitForElementPresent command till the page element is loaded and verify instead of the pause command.
    Selenium IDE Configuration

In this example, we are searching a text on the Google page and verifying the text appearing on the page. The storeEval command will read the search data from the google_search.js file and store it in a searchDataValue variable and verify the Download Selenium IDE text using an assertTextPresent command. In this way, you can achieve data parameterization or data-driven testing in Selenium IDE.

Generating source code from Selenium IDE

The Selenium IDE formatters plugin enables you to export the recorded steps. Selenium IDE can export the recorded steps or user actions to different formats. The Selenium team provides bindings for several programming languages. You can write a script in one of these programming languages and use the provided libraries to remotely control a browser. Selenium IDE formatters convert the recorded actions into source code for a specific programming language.

You need to set enable experimental features on Selenium IDE options to view the formatters. Check out the following screenshot for formatters:

Generating source code from Selenium IDE

Record user actions on Selenium IDE, and to view specific programming language formatters, select the Selenium IDE | Options | Format as shown in the following screenshot. A confirmation dialog appears, click on OK:

Generating source code from Selenium IDE

Ensure that the code is displayed under the Selenium IDE Source tab as seen in the screenshot that follows. You can also see the Java/Junit4/WebDriver programming language formatter. Selenium IDE used the type command to identify text typing into the textbox. In the source code, the sendkeys command is used in order to type text into the textbox using the Selenium Java/Junit4/WebDriver programming language. You can generate a formatter of any of the specific programming languages. After viewing the source code, you can switch back from a specific formatter to HTML. If a formatter is not HTML, then recording options will not work and the Table tab will not be active:

Generating source code from Selenium IDE

In the preceding recorded action, we searched a text on Google and verified the text appears on the page. Selenium IDE exports these actions to view a specific programming language. This is one of the useful features of Selenium IDE; it provides an option to set the clipboard format. You can copy commands from the Table tab and paste in the format of that specific programming language.

Saving tests

Saving tests is done in the same manner as saving a test suite. Click on the File menu and then click Save Test Case. This will give you a Save dialog box; save this to a place where you can get to it later. When you save your tests and your test suite, Selenium IDE will try to keep the relationships between the folders in step when saving the tests and the test suites.

What you cannot record

We have seen our tests work really well by recording them and then playing them back. Unfortunately, there are a number of things that Selenium cannot do. Since Selenium was developed in JavaScript, it tries to synthesize what the user does with JavaScript events. This means that it is bound by the same rules that JavaScript has in any browsers by operating within the sandbox.

  • Silverlight and Flex/Flash applications, at the time of writing, cannot be recorded with Selenium IDE. Both these technologies operate in their own sandbox and do not operate with the DOM to do their work. HTML5, at the time of writing, is not fully supported with Selenium IDE. A good example of this is elements that have the contentEditable=true attribute. If you want to see this, you can use the type command to type something into the html5div element. The test will tell you that it has completed the command, but the UI will not have changed, as shown in the following screenshot:
    What you cannot record
  • Selenium IDE does not work with Canvas elements on the page either, so you will not be able to make your tests move items around on a page.
  • Selenium cannot do file uploads. This is due to the JavaScript sandbox not allowing JavaScript to interact with <input type=file> elements on a page. While you might be able to send the text to the box, it will not always do what you expect, so I would recommend not doing it.

We will be able to automate a number of these elements with Selenium WebDriver in later chapters of this book.

Summary

We learned a lot in this chapter about Selenium IDE, learning how to create your first test using the record and replay functions and we now understand some of the basic concepts such as moving between multiple windows that can appear in a test, and saving our tests for future use.

Specifically, we covered the following topics:

  • How to install Selenium IDE: We started by downloading Selenium IDE from http://seleniumhq.org.
  • What Selenium IDE is made up of: The breakup of Selenium IDE allowed us to see what makes up Selenium IDE. It allowed us to understand the different parts that make up a command that will be executed in a test as well as its basic format. We had a look at how to load Selenium IDE and how to get started with recording tests. We saw that a Selenium IDE command is made up of three sections: the command, the target, and the value that might be used.
  • Recording and replaying tests: We used Selenium IDE to record a workflow that a user will need in their tests. We also had a look at verifying and asserting that elements are on the page and that the text we are expecting is also on the page.
  • How to add comments to tests: In this section of the chapter, we saw how to add comments to the tests so that they are more maintainable.
  • Working with multiple windows: In this section, we saw how applications today can have pop-up windows that tests need to be able to move between.
  • Working with AJAX applications: AJAX applications do not have the items needed for the tests when the tests get to commands. To get around this, we had a look at adding waitFor commands to the tests. This is due to the fact that Selenium does not implicitly wait for elements to appear on the page.
  • Storing information in variables: There is always something that is on the page that needs to be used later, but unfortunately, you will not know what the value is before the test runs. This section showed us how we can record items into a variable and use it later in a test. This can be something that has happened on a page and needs to be checked that it is still there on later pages.
  • Debugging tests: Creating tests does not always go according to the plan, so in this section, we saw some of the different ways to debug your tests.
  • Parameterization: Parameterizing the data in Selenium IDE.
  • Saving test suites: Finally, we saw how we can save tests for future use and how we can save them into different groups by saving them into test suites.

We also discussed what cannot be tested using Selenium IDE. We saw that Silverlight and Flex/Flash applications cannot be tested, and that when working with a number of HTML5 elements, the tests say that they have completed the tasks even though the UI has not changed. In later chapters, we will discuss different mechanisms that we can use within our tests that might be useful against HTML5 elements on the page.

Now that we've learnt about Selenium IDE, we're ready to look at all the different techniques we can use to find elements on the page.

Self-test questions

  1. What is the main language that drives Selenium IDE?
    1. Ruby.
    2. Python.
    3. JavaScript.
  2. Selenium IDE works on Internet Explorer.
    1. True.
    2. False.
  3. Selenium verifies items on the page when it is recording steps.
    1. True.
    2. False.
  4. What is the difference between verify and assert?
  5. If you wanted to validate that a button had appeared on a page, which two commands would be the best to use?
    1. verifyTextPresent / assertTextPresent.
    2. verifyElementPresent / assertElementPresent.
    3. verifyAlertPresent / assertAlertPresent.
    4. verifyAlert / assertAlert.
  6. If an element got added after the page loaded, what command would you use to make sure the test passed in the future?
    1. waitForElementPresent.
    2. pause.
    3. assertElementPresent.
  7. How do we run all the tests in a test suite?
Left arrow icon Right arrow icon

Description

If you are a software developer with a basic knowledge of testing and are interested in automated testing using Selenium, this is the book for you. No prior knowledge of Selenium is required.

Who is this book for?

If you are a software developer with a basic knowledge of testing and are interested in automated testing using Selenium, this is the book for you. No prior knowledge of Selenium is required.

What you will learn

  • Understand designing and implementing the automation framework
  • Understand and implement AJAX in your web pages
  • Set up Selenium WebDriver in both IntelliJ and Eclipse
  • Build test suites in Selenium using PageObjects
  • Get to know about WebElement handling with Selenium WebDriver
  • Install Selenium WebDriver for mobile devices
  • Understand and learn testing in Selenium Grid
Estimated delivery fee Deliver to Brazil

Standard delivery 10 - 13 business days

R$63.95

Premium delivery 3 - 6 business days

R$203.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 24, 2015
Length: 318 pages
Edition : 3rd
Language : English
ISBN-13 : 9781784396497
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Brazil

Standard delivery 10 - 13 business days

R$63.95

Premium delivery 3 - 6 business days

R$203.95
(Includes tracking information)

Product Details

Publication date : Feb 24, 2015
Length: 318 pages
Edition : 3rd
Language : English
ISBN-13 : 9781784396497
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 657.97
Learning Selenium Testing Tools - Third Edition
R$272.99
Selenium Design Patterns and Best Practices
R$200.99
Selenium Essentials
R$183.99
Total R$ 657.97 Stars icon
Banner background image

Table of Contents

16 Chapters
1. Getting Started with Selenium IDE Chevron down icon Chevron up icon
2. Locators Chevron down icon Chevron up icon
3. Overview of the Selenium WebDriver Chevron down icon Chevron up icon
4. Finding Elements Chevron down icon Chevron up icon
5. Design Patterns Chevron down icon Chevron up icon
6. Working with WebDriver Chevron down icon Chevron up icon
7. Automation Framework Development and Building Utilities Chevron down icon Chevron up icon
8. Mobile Devices Chevron down icon Chevron up icon
9. Getting Started with the Selenium Grid Chevron down icon Chevron up icon
10. Advanced User Interactions Chevron down icon Chevron up icon
11. Working with HTML5 Chevron down icon Chevron up icon
12. Advanced Topics Chevron down icon Chevron up icon
13. Migrating from Remote Control to WebDriver Chevron down icon Chevron up icon
A. Automation Prerequisites for Selenium Automation Chevron down icon Chevron up icon
B. Answers for Self-test Questions Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(11 Ratings)
5 star 63.6%
4 star 9.1%
3 star 27.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Feb 19, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Clearly written with good examples. Was able to get going quickly.
Amazon Verified review Amazon
Bhushan Jun 03, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Perfect book for fresher’s and new learnerWell summarized each and every feature
Amazon Verified review Amazon
Naveen Bharadwaj May 22, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I just started my career in automation team and selenium was a complete rocket science for me. The book authored by Raghavendra Prasad MG has been a great guide to me the whole time. Things are explained from scratch and any person who knows or understands English can learn selenium if he/she practices what's given in the book. Of-course, the person reading the book must have that interest or the need to learn selenium. To finalize, this is an extremely well written book with screenshots at every stage explaining how to go about with things. The book is a very good deal for the price it is being sold at, because what one can make after learning selenium is no-where close to the cost at what the book is sold.
Amazon Verified review Amazon
Mike Ludemann Jul 18, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Alle wichtigen Information und mehr sind vorhanden.
Amazon Verified review Amazon
buya Jun 28, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Ich habe gleich zwei Bücher gekauft für die Automatiserung mit dem Selenium Framework.Dieses Buch bietet einen guten Leitfaden.Im Vergleich zu dem anderen Buch welches ich mir auch über Amazon erworben habe, ist dieses Buch besser in der Praxis einsetzbar. Ich habe dieses Buch als Grundlage für das Selbstudium gekauft und bin recht zufrieden damit.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela