Building Test Cases

Domains: Selenium

There are three primary methods for developing test cases. Frequently, a test developer will require all three techniques.

Recording

Many first-time users begin by recording a test case from their interactions with a website. When Selenium-IDE is first opened, the record button is OFF by default, unlike previous version of it.

During recording, Selenium-IDE will automatically insert commands into your test case based on your actions. Typically, this will include:

  • clicking a link -click or click at commands
  • entering values -type command
  • selecting options from a drop-down listbox -select command
  • clicking checkboxes or radio buttons -click command

Here are some gotchas to be aware of:

  • The type command may require clicking on some other area of the web page for it to record.

Adding Verifications and Asserts With the Context Menu

Your test cases will also need to check the properties of a web-page. This requires assert and verify commands. Here well simply describe how to add them to your test case.

With Selenium IDE recording, go to the browser displaying your test application and right click anywhere on the page. You will see a context menu showing verify and/or assert commands.

The first time you use Selenium, there may only be one Selenium command listed. As you use the IDE however, you will find additional commands will quickly be added to this menu. Selenium-IDE will attempt to predict what command, along with the parameters, you will need for a selected UI element on the current web-page.

Let's see how this works. Open a web-page of your choosing and select a block of text on the page. A paragraph or a heading will work fine. Now, right-click the selected text. The context menu should give you a verifyTextPresent command and the suggested parameter should be the text itself.

Also, notice the Show All Available Commands menu option. This shows many, many more commands, again, along with suggested parameters, for testing your currently selected UI element.

Try a few more UI elements. Try right-clicking an image, or a user control like a button or a checkbox. You may need to use Show All Available Commands to see options other than verifyTextPresent. Once you select these other options, the more commonly used ones will show up on the primary context menu. For example, selecting verifyElementPresent for an image should later cause that command to be available on the primary context menu the next time you select an image and right-click.

Again, these commands will be explained in detail in the chapter on Selenium commands. For now though, feel free to use the IDE to record and select commands into a test case and then run it. You can learn a lot about the Selenium commands simply by experimenting with the IDE.

Editing

Insert Command

Select the point in your test case where you want to insert the command. To do this, in the Test Case Panel, left-click on the line where you want to insert a new command. Right-click and select Insert Command; the IDE will add a blank line just ahead of the line you selected. Now use the command editing text fields to enter your new command and its parameters.

Insert Comment

Comments may be added to make your test case more readable.

Comments will hide the details of the Command with the readable text you sepecify.

Edit a Command or Comment

Simply select the line to be changed and edit it using the Command, Target, Value and Comment fields.

Opening and Saving a Test Case

To save a Selenium IDE project, click the save button at the top right hand side, Selenium IDE will download a .side file, which contains all test cases and suites.

When you open an existing test case or suite, Selenium-IDE displays the test cases and suites at the left hand side panel, and the commands at the table.

Similar pages

Page structure
Terms

Selenium

Selenium IDE