Thursday, 31 January 2013

Building Test Cases | Selenium Tutorial pdf

Building Test Cases

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 ON by default.
Note: This can be set to OFF as a default with an available user extension.
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 clickAndWait 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.
• Following a link usually records a click command. You will often need to change this to clickAnd- Wait to ensure your test case pauses until the new page is completely loaded. Otherwise, your test case will continue running commands before the page has loaded all its UI elements. This will cause unexpected test case failures.
=> 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. We won’t describe the specifics of these commands here; that is in the chapter on “Selenese”
Selenium Commands. Here we’ll 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 though the IDE.

=> Editing
Insert Command
Table View

Select the point in your test case where you want to insert the command. Right-click and select Insert Command. Now use the command editing text fields to enter your new command and its parameters.
Source View
Select the point in your test case where you want to insert the command, and enter the HTML tags needed to create a 3-column row containing the Command, first parameter (if one is required by the Command), and second parameter (again, if one is required). Be sure to save your test before switching back to Table view.
Insert Comment
Comments may be added to make your test case more readable. These comments are ignored when the test case is run.
In order to add vertical white space (one or more blank lines) in your tests, you must create empty comments. An empty command will cause an error during execution.
Table View
Select the point in your test case where you want to insert the comment. Right-click and select Insert Comment. Now use the Command field to enter the comment. Your comment will appear in purple font.
Source View
Select the point in your test case where you want to insert the comment. Add an HTML-style comment, i.e., <!– your comment here –>.
Edit a Command or Comment
Table View
Simply select the line to be changed and edit it using the Command, Target, and Value fields.
Source View
Since Source view provides the equivalent of a WYSIWYG editor, simply modify which line you wish–
command, parameter, or comment.

=> Opening and Saving a Test Case
The File=>Open, Save and Save As menu commands behave similarly to opening and saving files in most other programs. When you open an existing test case, Selenium-IDE displays its Selenium commands in the test case pane.
Test suite files can also be opened and saved via the File menu. However, such operations have their own menu entries near the bottom; the Open, Save, and Save As items are only for files.
Note: At the time of this writing, there’s a bug, where at times, when the IDE is first opened and then you select File=>Open, nothing happens. If you see this, close down the IDE and restart it (you don’t need to close the browser itself). This will fix the problem.

No comments: