Best Practices for Selenium Testing
  
Best Practices for Selenium Testing
This section provides additional guidance for creating Synthetic “Selenium Tests”, and consists of the following topics:
“Workflow for Creating a Selenium Test"
“Best Practices for Recording and Optimizing a Selenium Test"
Related Topics
“Installing Synthetic Test Engines"
“Configuring Synthetic Test Profiles"
“Running and Viewing Synthetic Tests"
Workflow for Creating a Selenium Test
Before you begin, download the latest Selenium IDE extension for Mozilla Firefox. Also you should familiarize yourself with selenium testing by referencing the following:
http://www.seleniumhq.org/
http://release.seleniumhq.org/selenium-core/1.0.1/reference.html
Typical Selenium Test Creation Workflow
1. Start the Selenium IDE in Firefox.
2. Record a web transaction.
3. Play back the web transaction in the Selenium IDE to determine if it is successful.
4. Edit the steps in the recorded transaction to create a robust test, and ensure that it can be played back at full speed.
5. Save the Test Case HTML file.
6. Create a Synthetic Selenium Test with the wizard using the saved HTML file.
7. Run the Selenium test.
Best Practices for Recording and Optimizing a Selenium Test
This section includes the following topics:
“Timeout on individual Selenium Test Steps"
“Using the Open and WaitFor Commands"
“What does the base URL map to?"
“WaitFor Commands"
“Using xpath commands"
“Firefox versions"
Timeout on individual Selenium Test Steps
Some URLs may take a while to open for any number of reasons. Selenium has a built-in timeout of 30 seconds per command, so if a command does not complete in 30 seconds, Selenium will fail that step. You can use the setTimeout command in Selenium to increase the amount of time.
The total timeout for the test that is specified in NetIM may also have to be increased correspondingly.
Using the Open and WaitFor Commands
The open command waits for the page to load before proceeding, and the AndWait suffix is implicit, but the page may not be fully loaded when the test moves on to the next command. Therefore, a test case may work on some occasions and not on others. A good practice is to wait for an element on the page to load before proceeding to the next command. For example, use the waitforElementPresent command on a link before proceeding to the command that clicks on the link. For details, see “WaitFor Commands".
What does the base URL map to?
The Base URL is the Test Target URI specified in the NetIM Synthetic Test. The test target URI for Selenium tests should include the protocol (for example, http://www.riverbed.com). When using relative URLs in the open statement, the test target URI is used as the Base URL for the Selenium test. When using an absolute URL in the open statement, the test target URI is not used.
WaitFor Commands
Use the waitForXXXX commands to ensure that a test will work consistently. Not doing this may result in occasional failures, or possibly result in the test never working within the NetIM Test Engine. An example of a well-designed test case is as follows:.
command
target
value
open
/secure/xyz.do?app=abc
 
waitForElementPresent
link=Some link I want to click
 
clickAndWait
link=Some link I want to click
 
waitForElementPresent
name=Some text field
 
type
name=Some text field
sample input
waitForElementPresent
link=Continue
 
clickAndWait
link=Continue
 
waitForElementPresent
name=accountNumber
 
type
name=accountNumber
12345678
waitForElementPresent
link=Personal Account
 
clickAndWait
link=Personal Account
 
waitForElementPresent
link=Personal Account
 
clickAndWait
link=Personal Account
 
In this example, the waitForElementPresent command appears before any other command that attempts to access that element.
Using xpath commands
Selenium allows the identification of locators using xpath. Some versions of Firefox and the Selenium IDE used to record the test case can cause these commands to fail with an invalid xpath error. Using a different version of Firefox usually solves this issue.
Firefox versions
Selenium is sensitive to Firefox and browser versions. After a test has been deployed to a Test engine and has been confirmed to run successfully, it is recommended that you turn off the automatic update feature in Firefox.