Selenium IDE – Part I

Selenium IDE is a free Firefox plugin that leverages javascript to record automated test scripts. In this first tutorial we will install Selenium IDE and create a basic test script. The next tutorial will cover more advanced topics.

I primarily use Selenium IDE in three areas:

  • Defect – I ask testers to record their steps and attach the script to their defects. This is a simple way to communicate exactly how they found an issue.  This technique significantly cuts down on communication overhead.
  • Acceptance Testing – While I prefer writing tests before I write the code, this is a simple way to record tests on existing web applications. In part II I will show you how to export these recordings into Java. By exporting these scripts you can easily add them to your existing automated test suite.
  • Demo Setup – I’ve found it handy to run small Selenium test cases to setup a demo. For example you may want to demonstrate the functionality on the tenth page that requires a log-in and multiple data entry steps. This approach can reduce demo setup time and enable you to focus on demonstrating new functionality.

Setup

  • Install the Selenium IDE Firefox plugin (http://seleniumhq.org/projects/ide/)
  • Navigate to https://sites.google.com/site/example4selenium/ in Firefox
  • Tools -> Selenium IDE
  • Initial Selenium

  • The Record Button button is set to record when you start Selenium IDE.
  • Open the Selenium IDE options.
  • Selenium IDE Options

  • Check ‘Record assertTitle automatically’. This option asserts the page title after every page transition. This verifies that the last action advanced to the correct page before proceeding with the next step.
  • Selenium IDE Options

Record Test

  • Search for the word ‘best’.
  • Click the ‘Search this site’ button.
  • Site Search

  • Click the ‘Another Post’ link.
  • Search Results

  • Selenium IDE plugin provides right-click assert options. Verify that this article contains the phrase “this is my best post ever”.
  • Right Click Assert

  • This plugin can also verify the presence of images. Right click the ‘Selenium’ logo.
  • All Available Commands

  • Under ‘Show All Available Commands’ there are ‘assert’ options and ‘verify’ options. What is the difference between assert and verify? Assert will stop the test case if it fails. On the other hand, verify will allow the test case to complete. It is recommended to use assert over verify.
  • Select the “assertElementPresent //img[contains(@src,’http://upload.wikimedia.org/wikipedia/en/5/5c/Seleniumlogo.png’)]” option.
  • Click the ‘Home’ link.
  • Fill out the form and click the ‘Submit’ button.
  • Form

  • Click the ‘Results’ link.
  • Right-click and verify the text ‘This is a test’ is present.
  • Verify Results

  • Click the Record Button button to stop recording.

Replay Script

  • Now replay this script and watch it go.
  • Play Test Case

  • Adjust the speed and replay the script.
  • Adjust Speed

Save Test Case

  • Save the test case.
  • Save Test Case

Resume Recording

  • Navigate to the correct page.
  • Set the focus under the last step and click the Record Button button.
  • Continue recording steps.

Test Suits

  • A suite is one or more test cases.
  • Add one or more test cases
  • Save the test suite
  • Save Test Suite

Next month, in Part II, we will cover

  • Storing Variables
  • Debugging Scripts
  • Using XPath
  • Exporting Scripts into Java

4 comments

  1. I want learn how to write a java script, how i can break the application functionality,and what kind and how many functions are used in writing the java scripts,i am willing to learn in writing java scripts for testing web applications.

    Waiting.

  2. If you would like to start learning JavaScript take a look at this w3schools tutorial http://www.w3schools.com/js/default.asp. This tutorial is very basic, but it provides examples that you can try yourself.

    As for “breaking the application functionality” work through both of our tutorials Selenium Part I and Selenium Part II. This provides the basics for writing and executing automated web tests. If you want to “break” the functionality then you will need to write scenarios that are not satisfied by the application. Then adjust the functionality of the application. This approach is called TDD. Good luck.

  3. Could you explain me the difference between the ‘Assert Element’ and ‘Verify Element’? Please explain with the ideal scenario’s to apply the above conditions.

  4. Assertions fail and stop the test from proceeding. On the other hand, verifications fail and allow the test to proceed. There are two primary reasons to use an assertion. First, the step that is being asserted must exist for the rest of the test to succeed. For example if a link does not exist and the next step is to click the link then the test will stop on the click step. In this case an assertion would be valuable. Second, you do not want the rest of the test to run once a the state of the system is invalid. For example if a test suite takes a long time to run you may want to fail and stop early so you can fix the error and not wait until the suite has completed the run. One motivation for using verify is to see all of the errors together. This empowers you to fix multiple issues before you try to rerun the test. I hope this helps.

Comments are closed.