Skip Headers
Oracle® Functional Testing OpenScript User's Guide
Version 9.20

Part Number E15488-05
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

4 Using Databanks

OpenScript allows users to parameterize script data inputs to perform data driven testing using Databanking. Users can select any data inputs for their script and then substitute a variable to drive the input from an external file during playback. Multiple Databank files can be attached to a single script and users can specify how OpenScript assigns data during script playback.

4.1 Understanding Data Driven Testing (Parameterization)

Data Driven Testing, or parameterization, allows you to quickly and efficiently create automated data-driven tests.

The OpenScript Modules record parameters defined by each page of the Web application to a script. Databanks are used to hold unlimited amounts of input data that can be automatically fed as parameters into your Web application when the script is run. You can use the OpenScript Databanking features to define variable values in script parameters and substitute values from Databank files for the variable values.

During playback, the parameters in the Web page are filled with values from the Databank file. Databank files can be easily created or modified using any simple text editor, spreadsheet, word processor, or database application. Users can create sophisticated unattended regression tests to thoroughly exercise a Web application by using varied input data from Databank files.

Data Input Parameterization enables users to parameterize recorded script inputs to perform data driven testing in either the script GUI view or code view. These inputs could be form field inputs for Web applications but could also be other types of script inputs that users may parameterize. Types of inputs users may parameterize include:

Data Input Sources enables users to drive input values from an external CSV file or other external data source such as a database (i.e. using a database query to pull inputs from a database table).

Data Parameterization GUI View enables users to configure the inputs they want to parameterize and the data source they want to drive the inputs from through a substitute variable GUI interface. For example, the "ticker" query string parameter for "Page [4] Ticker List" in the following Tree View is set to the variable value "{{fmstocks_data.ticker,ter}}".

Within the variable "{{fmstocks_data.ticker,ter}}", "fmstocks_data" is the name of the Databank file, ".ticker" identifies the field name within the Databank file, and "ter" is the recorded value.

Data Parameterization Code View Commands enable users to specify the inputs they want to parameterize and the data source they want to drive the inputs from through data parameterization in the code view.

For example, the "ticker" query string parameter for "Page [4] Ticker List" in the above Tree View appear as http.querystring(http.param("ticker", "{{fmstocks_data.ticker,ter}}") in the http.get method code in the Code View, as follows (line breaks and spacing added for clarity):

beginStep("[4] Ticker List", 3422);

{

   http.get(6, "http://testserver2/fmstocks/{{LINK_1_3,TickerList.asp}}", 

        http.querystring(http.param("ticker", "{{fmstocks_data.ticker,ter}}"), 

             http.param("company", "")),  null, true, "ASCII", "ASCII");

}

endStep()

4.2 Using Script Databanks

Databanks are used to hold unlimited amounts of input data that can be automatically fed into your Web application. During playback, the parameters in the Web page are filled with values from the Databank file. The Databank and script parameter shortcut menu options allow you to map parameters in a script to fields in a Databank file as variable names.

Scripts must be configured to use Databanks. Use the Script Properties option on the Script menu to specify the Databank file(s) to use with a script in the Assets properties. Scripts can be configured to use more than one Databank file.

When you record a script that has a navigation that uses parameters, the parameter nodes appear under the Query String node:

In the Code View, the parameters appear in the http.param parameters of the http.querystring parameter:

When you configure the Databank(s) to use with the script, the Get next Databank record from databank name node and Java code are added to the script.

Select the script parameter node to map to a Databank and use the Substitute Variable option on the right-click shortcut menu to select the Databank field name to map to the parameter. The Databank file and field name appear in the parameter node of the script tree.

The variable appears in the Code view in the http.param parameters of the http.querystring parameter:

Use the Playback iterations to playback using the records in the Databank. You can also use custom code to loop through Databank records and assign values to variables.

4.3 Configuring Databanks

You must configure the Databank to use with a script before you can get records from the Databank to use in a script.

To configure Databanks to use with a script:

  1. Open or create a Script project.

  2. Select Script Properties from the Script menu.

  3. Select the Script Assets type. See Section 3.3.6, "Adding Script Assets" for additional information about adding script assets.

  4. Select Databanks.

  5. Click Add.

  6. Select Databank.

  7. Select CSV file or Database. Once a databank is defined as CSV or Database (SQL), the databank type cannot be changed to the other type.

  8. For CSV files:

    1. Select the Repository from the My Repositories tree.

    2. Select the Databank file from the repository.

    3. Set the Type to Databanks (*.csv, *.txt).

      Type: Specifies the type of databank file to add to the script (*.csv, *.txt).

    4. Select the Charset to use.

      Charset - specifies the character set encoding used for the databank file. The suggested charset encoding of the databank .csv file is the native charset of user machine. For US machines the suggested encoding is cp1252. For East European machines, the suggested charset is cp1251. If a databank file was saved with UTF-8 encoding with Unicode byte order mark (BOM), OpenScript detects it, and sets encoding to UTF-8. If the charset used for the databank file is different from the charset of the user machine or UTF-8 with BOM, then you must the correct charset. Otherwise, the databank will not be read correctly and may cause a script failure. You can select the correct charset from the Charset list or enter the correct Charset in the field.

      During playback, the Agent will define the charset for reading the databank file in following order:

      • If file has UTF-8 encoding with BOM, then it will be used.

      • The Charset specified during asset configuration will be used.

      • If no charset specified (case of 9.1 scripts), then UTF-8 encoding will be used.

    5. Enter an alias name to use for the Databank or leave the default alias name. The default alias name is the name of the .CSV Databank file.

      Alias: Specifies an alias name to use for the Databank. The Databank file name is the default. The Databank alias name is the name that appears when you add a Databank record retrieval node to a script tree.

    6. Set the Relative to option. The Relative to current script and Relative to a repository options specify how the current script will locate the specified script asset. The Relative to a repository option locates the script asset by a repository path such as, [Repository: Default] Default!/WebTutor, if the asset is selected from a repository. The Relative to current script option locates the script asset by a relative path such as ../WebTutor. Selecting the The Relative to current script option is not recommended as script-relative paths are more brittle than repository-relative paths if scripts are moved or shared.

      The following are guidelines when using script assets in a team or distributed environment:

      • Do not use Absolute Paths when referring to assets or saving assets. Oracle Load Testing does not support absolute paths.

      • OpenScript, Oracle Test Manager, Oracle Load Testing, and all command-line agents should all use the same shared repository names and paths.

      • Do not refer to an asset in another repository by a relative path.

    7. Click OK.

    8. Click OK to add the Databank file.

  9. For Databases, a Databanks Database Assets dialog box appears. This dialog box lets you specify the database and query to uses as a databank. Contact your Database Administrator for the appropriate settings for your database. The the following options are available:

    1. Specify the Database Driver.

      Oracle Thin - This driver option applies to Oracle databases.

      • Hostname - Specify the host name of the machine running the database. This is not required for a JDBC:ODBC or Custom driver setting.

      • Port - Specify the port for the driver you selected. For example, the default port for an Oracle Thin JDBC driver is 1521. Modify the port number if necessary. This is not required for a JDBC:ODBC or Custom driver setting.

      • SID - Specify the database or server ID.

      • Service name - Enter the Service name used for the Oracle database.

      ODBC - This driver option is available as an option for SQL and Oracle databases and any other database for which you have anJDBC:ODBC Bridge driver.

      • Data Source - Specifies the data source for the ODBC driver.

    2. Specify the URL, username, password, query string, and databank alias.

      • URL - Specifies the URL to user to connect to the database.

      • Username - Enter the username for connecting to the database, if required for authentication.

      • Password - Enter the password for connecting to the database, if required for authentication.

      • Query - Specify a single SQL query that returns all the rows needed as databank values. The SQL query cannot contain PL/SQL or SQL*Plus code. Only pure SQL is supported. You must ensure that the query returns the column names (i.e. databank fields) that the script expects.

        If you have a large database-backed databank, but will only use a small portion of the records in the test, then use the "Where" clause in the SQL query to minimize the amount of records retrieved from the database. For example, if you have database with 200000 records and only need to have 100 iterations retrieving records 201 through 301 sequentially starting from record 201. use a query such as Select * From LargeTable Where id > 200 AND id < 302. The start record will be 1 and no is range set. This reduces the databank preparation time and minimizes the amount of records retrieved from the database.

        Use the "Order By" clause in the query to make sure the results returned from the database are ordered as intended. For example, if you have a database table with Columns id, firstName, and lastName that is populated it with the following data:

        1, John, Smith
        2, Jane, Doe
        [...]
        400, Maria, Sanchez
        [...]
        200000, Sachin, Rajaram
        

        If you use the query Select * From users, the results of query could be unordered, meaning the first record in databank could be 400, Maria, Sanchez instead of 1, John, Smith. Using the query Select * From users Order By id would order the first databank record as 1, John, Smith as expected.

      • Alias: Specifies an alias name to use for the Databank. The Databank alias name is the name that appears when you add a Databank record retrieval node to a script tree.

    3. Click Test to verify the connection to the database.

    4. Click OK.

    5. Click OK to add the Databank file. For Databases used as databanks, a copy of all data is retrieved and indexed before the start of the test. The data is not read live during the test. See Section 4.5, "Playing Back Scripts With Iterations" for additional information about playing back scripts with databanks.

Databank CSV files are comma-separated value files. The field names are on the first line of the file separated by commas (no spaces). The field data is on subsequent lines separated by commas (different line for each record, no spaces around commas). The following shows an example:

FirstName,LastName,Mail,Phone

John,Smith,JohnS@company.com,x993

Mary,Ellen,MaryE@company.com,x742

If a data value contains a comma, place quotation marks around the value, as follows:

John,Smith,"Anytown, MA","(603) 993-0000"

New lines may be embedded inside of quotation marks, as follows:

"field1","field2 contains two lines: Line one.

Line two.","field3"

Blank lines are stripped out and ignored.

The character encoding of the CSV file is determined by an (optional) byte-order-mark at the beginning of the file. Programs such as Notepad set this byte-order mark when users save a text document with a specific encoding character set like UTF-8. If no byte-order mark is specified, the CSV reader uses the current platform's default character set to read the file (for example, cp1252 on most Windows English installations).

4.4 Getting Databank Records

To get Databank records to use with a script:

  1. Open or create a script project.

  2. Configure the Databank to use with a script in the Script Assets Properties.

  3. Select the script node where you want to use the Databank record.

  4. Select the Script menu and then select Other from the Add sub menu.

  5. Expand the General node and select Get Next Databank Record.

  6. Select the databank or click New to add a new databank.

  7. Select the Record.

  8. Click OK.

  9. Select the Databank alias to specify the Databank file to get the record from.

  10. Click OK. A GetNextDatabankRecord: databank alias node will be added to the script.

    In the Java Code view, a getDatabank("databank alias").method (); will be added to the script code depending upon the type of record selected:

    getDatabank("customer").getNextDatabankRecord();
    getDatabank("customer").getFirstRecord();
    getDatabank("customer").getLastRecord();
    getDatabank("customer").getRecord(5);
    
  11. Right click the parameter node in the script tree that you want to substitute with a Databank variable and select Substitute Variable.

  12. If necessary, expand the Databanks node and select the Databank field you want to use as the input parameter data.

  13. Click Finish.

  14. The script node name/value pair changes to show the Databank alias name, field name, and recorded value as a variable value. For example:

    login = {{db.customer,login,ta906}}
    

    In the Java Code view, the parameter code changes to show the Databank alias name, field name, and recorded value as a variable value. For example:

    http.postdata(http.param("login", "{{db.customer,login,ta906}}")
    
  15. Click the Playback toolbar button to playback the script once to verify the it plays back correctly.

4.4.1 Getting Databank Records Using the API

You can use the additional API methods available with getDatabank("databank alias")in the Java Code view to retrieve specific records from the databank. This section provides examples of the available methods.

4.4.1.1 Databank API Usage Notes

These API methods are not compatible with databank's iteration settings Randomly or Shuffle Records. The Databank Exception "incompatible with db setting" will be thrown if these methods are used with the Randomly or Shuffle Records iteration settings.

The records obtained through these API calls are not counted against the usage count of all records. It is possible for an infinite script loop to occur if the When Out of Records iteration setting is set to Stop the User, but the script only uses these API calls to read records.

4.4.1.2 Getting a Record Count

The following example uses the getDatabankRecordCount() method to get the record count from the "customer" databank and prints the value to the Results view:

int recordCount = getDatabank("customer").getDatabankRecordCount();
String count = Integer.toString(recordCount);
info("Record Count = " + count );

4.4.1.3 Getting a Specific Record

The following example uses the getRecord(n) method to get a specific record from the "customer" databank and prints the value to the Results view:

getDatabank("customer").getRecord(5);

The following code example use a For statement to loop through all records in the databank:

int recordCoun1 = getDatabank("customer").getDatabankRecordCount();
for (int i=1; i<=recordCount; i++) {
   info("Record count = " + 
      Integer.toString(i) +
      " of " + 
      Integer.toString(recordCount));
   getDatabank("fmstocks_data").getRecord(i);
}

4.4.1.4 Getting the First Record

The following example uses the getFirstRecord() method to get the first record in the "customer" databank:

getDatabank("customer").getFirstRecord();

4.4.1.5 Getting the Last Record

The following example uses the getLastRecord() method to get the last record in the "customer" databank:

getDatabank("customer").getLastRecord();

4.5 Playing Back Scripts With Iterations

OpenScript allows repetitive playback of navigations in a script. The iterations can be performed with or without databanks.

  1. Start OpenScript.

  2. Open the script to play back.

  3. Configure the script to use a databank as described in Section 4.3, "Configuring Databanks".

  4. Select Iterate from the Script menu or click the toolbar button. The resulting dialog box has the following options:

    Use Databanks: When selected, databanks will be used for script playback. Databanks configured for the script show the following settings:

    • Name: Lists the alias name(s) for the databank file(s).

    • Range: Lists the range of databank records to use for script playback. This list corresponds to the Range option selected for each databank file.

    • Start: Lists the starting databank record to use for script playback. This list corresponds to the Starting Record specified for each databank file.

    • Select Record: Lists the how databank records are selected for script playback. This list corresponds to the Select Next Record setting selected for each databank file.

    • When Out of Records: Lists the action to take when the databank file is out of records during script playback. This list corresponds to the When Out of Records setting selected for each databank file.

    • Data: Lists the data in the Starting Record of each databank file.

    Databank Source: This section shows the following information about the selected databank:

    • Alias: Shows the alias name of the selected databank file and the number or rows in the file.

    • Type: Shows the type of the selected databank file. Databanks can be CSV text files or databases.

    • Source: Shows the path and filename of CSV text files or the database query used for database databanks. While there is not a maximum file size, the recommended maximum sizes is 200 MB. The only limitation is how long it takes to generate the index. The databank must be indexable within 30 seconds, by default. This setting is configurable in the "Databank Setup Timeout" setting in the General Preferences.

    Databank Settings: This section specifies the settings to use for the selected databank:

    • Advance to Next Record: Specifies when the virtual user should advance to the next databank record during script playback. The master script being played is always the script that triggers when an iteration occurs. The following options are available:

      • When Script Requests a Record: The databank record advances every time a script explicitly requests a record during script playback. A record request corresponds to the script Java code calling the getDatabank(alias).getNextRecord() method. This is the default behavior.

      • When Script Request Specified Column: The databank record advances when a script refers to a databank column (i.e. databank field) in the script. A record request corresponds to the script Java code evaluating a parameterized value such as {{db.fmstocks_data.ticker}}. You can specify that any column advances to the next record or specify a particular databank column advances to the next record. For example, if you have an employee databank with a firstName field and the firstName column is specified as the Column value, the databank record advances only when the {{db.employees.firstName}} value in the script Java code is evaluated on script playback. Select the databank field name as the Column value or select <Any> to allow any filed to advance the databank record.

      • Each Iteration of Script: The databank record advances before a script containing the databank starts another playback iteration.

    • Select Next Record: Specifies how a new record is selected from the databank when the databank record advances. The following options are available:

      • Sequentially: The databank records increment one by one in sequential order from the start of the specified range. When multiple virtual users are running, records are distributed in sequential order across all virtual users.

      • Randomly: The databank records are selected at random from the databank. The same record may be used multiple times before all records are exhausted. Random record selection is only provided for databanks that can be indexed. When configuring databank settings, if the databank file is too large to index, the Randomly or Shuffle record options may not be available. The When Out of Records setting does not apply when Random is selected.

      • By Shuffling: The databank records are selected at random from the databank ensuring that once a record is selected, it is never selected again. The setting works similar to selecting a random card from a deck until no cards are left. Shuffle mode only supports databanks containing fewer than 200,000 records. For databanks containing more than 200,000 records, you can shuffle the values in the actual data file or you should use the Randomly mode.

      • Use Seed: Specifies a randomization seed value to use when using the Randomly or Shuffle modes. Use the same seed across multiple tests to create the same sequence of random numbers for all tests. If 0 or not specified, a seed is generated automatically based on the current time.

    • When Out of Records: Specifies the action the virtual user takes if all databank records in the specified range have been used and a new record is requested. The following options are available:

      • Loop Over Range: Loops back to the first record in the range after all records in the range are used and continues distributing records. Use the Maximum Iterations settings to prevent the virtual user from running forever.

      • Keep the Same Record: Continues to use the last record requested after all records in the range are used. No additional records are requested from the databank. Any calls in the Java code to getNextDatabankRecord() are ignored after all records are used. Custom Java code may be used in the script to have Virtual users request an individual record using getRecord(n), getLastRecord(), or getFirstRecord().

      • Stop the User: The virtual user immediately stops running the next time a record is requested from the databank after all records in the range are used. The virtual user will stop regardless of how many iterations are specified by the Maximum Iterations settings.

    • Range: Specifies the range of records to use. The following options are available:

      • All Records: When selected, the virtual user uses all records in the databank. The first record is 1.

      • Specific Records: When selected, the virtual user uses a subset of records in the databank. Specify the first and last records to use for the range. The range includes both the starting and ending record in the specified range.

    • Starting Record: Specifies which databank record to use first. The first record in a databank is 1. The starting record must be within the specified range of records. For example if you select Specific Records and set the range to 5:10, the starting record must be at least 5, but not more than 10.

    Maximum Iterations: This section specifies the maximum number of iterations of a main script's run() section to complete:

    • Run no more than [ ] iterations: Specifies the maximum number of iterations. If a databank exhausts all records and When Out of Records specifies Stop the User, the virtual user will always still stop running, even if the specified number of iterations has not completed.

  5. Select Use Databanks.

  6. Select which databank file to specify the settings for if more than one database is configured for the script.

  7. Specify the settings for the databank file.

  8. Select the Run no more than [ ] iterations option and set the iteration count to the desired number of playback iterations.

  9. Click OK.

    You can view the progress of the script playback in the Console View. You can review the results of script playback in the Results View.

4.5.1 Notes and Limitations

Certain setting combinations are not allowed, or may cause exceptions when the script is run. The following are situations to be aware of when using iteration options.

  1. The When Out of Records option is not available when Select Next Record is set to Randomly. When random is selected, an infinite supply of random records exists.

  2. Virtual users may still request an individual record using getRecord(n) after all records are used up, and When Out of Records is set to Keep the Same Record.

  3. The getRecord(n), getFirstRecord(), and getLastRecord() Java code methods do not advance the record cursor used by getNextDatabankRecord(). Therefore:

    getNextDatabankRecord();// returns 1
    getRecord(7);// returns 7
    getNextDatabankRecord();//returns 2, not 7
    
  4. The getRecord(n), getFirstRecord(), and getLastRecord() Java code methods throw an exception when they are invoked if Select Next Record is set to Shuffle Records or Randomly.

  5. The getRecord(n), getFirstRecord(), and getLastRecord() Java code methods throw an exception if they are invoked and the databank is not indexed.

  6. Use Seed is only available when Select Next Record is set to Shuffle Records or Randomly.

  7. A specific databank range and starting index may not be set if the databank cannot be indexed.

  8. The Select Next Record: Shuffle Records and Randomly options are only allowed when the databank can be indexed.

  9. The Select Next Record: Shuffle Records is only allowed when the databank can be indexed and when there are fewer than 200,000 records.