Select A Random Web List Value PDF Print E-mail

Technique Description

Static data entry is constrained by the fact that it doesn’t allow the automated script to automatically adjust with the dynamic applications. An advantage of inputting random data is an increased robustness of the scripts that more gracefully handle application changes. Another advantage is in the fact that over multiple automated test executions, test coverage is increased since different data may be entered in each run. This technique selects a random value from a list box (the current examples focus on web list boxes).

The process for selecting a random value from a list box is as follows:

  1. Obtain a collection/array of all options in the list box.
  2. Get a count of the total number of items in the collection/array.
  3. Use random number generator to select a random element from the collection/array.

 

Downloadable Functions

This section provides samples of the above technique in various scripting languages. Note that many automated test tools (commercial and open source) use industry standard scripting languages, therefore the code can be used in a standalone manner as well as in various tools (i.e. VBScript code can be used in QTP, and Ruby code can be used in WATIR).

The prerequisite for running the downloadable code example is as follows:

  • It must be executed on a system with Internet access.

 

The below links provide the code in .txt files. Download then change the extension appropriately.

 

Helpful External Links