Archived PushToTest site

Operational Test Data with Data Production Libraries (DPLs)

Operational Test Data with Data Production Libraries (DPLs)

A PushToTest TestMaker Data Product Library (DPL) delivers operational data to tests at test runtime. For instance, a recorded Selenium test of a Web-based log-in page retrieves the user name and password values from a comma separated value (CSV) data file as TestMaker operates the test. Tests use DPL provided data not only as input values but also to validate the application's function.

The TestMaker DPL system provides a simple and easy way to data-enable tests. A DPL does not require programming or scripting. And it is a flexible framework that permits you to add your own DPLs to meet your organization's specific needs.

DPL Introduction

TestMaker implements a Data Production Library (DPL) as an extensible framework to provide operational test data to test script runners at test runtime. The DPL framework is general in that data may be input from a variety of sources, including a relational database, comma-separated-value file, and data generating objects. A DPL also provides a safe way to store data between test steps. TestMaker comes with pre-built DPLs and makes it easy for software developers to add their own custom DPLs.

DPLs work in conjunction with script runners at test runtime. TestScenarios define the DPL and script runner interaction. The TestMaker Tutorials give instructions on using the pre-built DPLs.

TestMaker users configure Test Use Cases in the TestMaker Editor to use operational test data from a DPL. To see this in action follow these steps:

  • Start TestMaker
  • Choose File -> New Functional Test. The Editor opens. The new TestScenario appears in the left. TestMaker sets the default name of the new TestScenario to Untitled.xml. The settings for this TestScenario appear in the tabs:  General, Use Cases, TestNodes, Monitoring, Options.
  • Click the Use Cases tab.
  • Click Add Test.
  • Choose Selenium in the Test Type pop-up menu.
  • Click Browse. Select a Selenium test. For example, TestMaker_home/example_agents/AjaxRIASelenium/CalendarTest_DPL.selenium
  • Click Add DPL.
  • Choose Read From A CSV Data File from the DPL Type pop-up menu.
  • Click Browse. Select a CSV data file. For example, TestMaker_home/example_agents/AjaxRIASelenium/Data.csv
  • Choose Get Next Row of Data from the DPL Action pop-up menu.

The Editor should appear as follows:


alt

This configuration tells the TestMaker Selenium script runner to look into the Selenium test and replaces values in the test with values from the data.csv file. The DPL provides data from the data.csv file as TestMaker runs the Selenium script, at test run time.

The DPL uses the first row in the CSV file to identify field mapping names. Insert these mapping names into the Selenium file where you want TestMaker to inject the test data from the CSV file. After the mapping name row comes the rows of the data file contain the actual data. The DPL Action determines the row of data TestMaker provides to the test. In a load test, setting the DPL Action to Get Next Row of Data tells TestMaker to advance to the next row of data. When the DPL reaches the bottom of the table, the DPL starts at the top.

The Selenium, soapUI, Command Line and TestGen4Web script runners provide support for data mapping from DPLs. Script runners for Java, Jython, JRuby, VB, .NET, Groovy and the other support scripting languages receive DPL data in a dictionary structure.

DPLs have the ability to share data from one test to the next. For example, TheLocker DPL takes the results from a test step authored in soapUI as input to a second test step authored in TestGen4Web. See the Mailer Check Tutorial for an example of DPL data sharing between test steps.

The above example showed how to use data from a CSV file. DPLs work in the same way with data from a Relational Database (RDBMS,) and other data generating objects. See the DPL Recipes section for details.


Providing Data To Distributed Tests

TestMaker is a distributed test system. Multiple virtual users run in a TestNode and tests run across one or more TestNodes. Tests often need unique data for each virtual user. For example, a test of a banking system needs a separate and unique customer number for each virtual user running in the test. TestMaker offers 3 solutions to meet your testing needs.

Common Test Data, No Coordination

TestMaker's CSV DPL sends a copy of a single CSV file to each TestNode running a test. Each Virtual User uses data in the CSV file. Each user has its own DPL and each DPL has its own pointer to the row of data in the CSV file. Each virtual user runs concurrently and there is no coordination between the virtual users.

CSV files distributed to each TestNode

To use this configuration, use the TestMaker Editor to configure a Test Use Case that uses a CSV DPL (HashDPL.) Set the DPL Action setting to Get Next Row of Data. When you run the test TestMaker will send a copy of the defined CSV file to each TestNode. TestMaker creates a DPL for each virtual user. Each DPL has a row pointer. The pointer is initially set to the first row of data. The DPL reads the first row of data and injects the data fields into the test script. The DPL moves the pointer to the next row of data. At the last row of data the DPL moves the pointer to the first row of data.

Unique Provided Data

Many times the test architecture requires each virtual user to use unique data. For example, when testing a banking system each virtual user needs to log-in to the banking application using its own user id and password. TestMaker provides UniqueDPL to provide each virtual user's DPL with its own data. The data comes from a single CSV file. Each virtual user uses its local DPL to communicate over a TCP/IP request to a single UniqueDPL service. The UniqueDPL reads from the single CSV file.

Unique data distributed to each virtual user

The communication overhead for UniqueDPL is minimal. PushToTest staged tests up to 100,000 virtual users and observed less than 1% network bandwidth overhead and less than 20 millisecond wait times when using UniqueDPL.

Transactional Data Provided To Each Virtual User

TestMaker's RDBMS DPL enables tests to receive operational test data from a relational database. For example, configure a MySQL instance to serve transactional data to the virtual users. One PushToTest customer stored invoice data for a test of an Enterprise Resource Planning (ERP) system. A stored procedure (StoredProc) in MySQL provides invoice data to the virtual users, including part numbers, part costs, quantities, and shipping details. The StoreProc enables each virtual user to receive its own unique data from the common data store.

Transactional data distributed to each virtual user

The above example showed how to use data from a CSV file. DPLs work in the same way with data from a Relational Database (RDBMS,) and other data generating objects. See the DPL Recipes section for details.


Recipes


Comma Separated Value (CSV) Operational Data For Tests 

Comma separated value (CSV) files contain data formatted into rows, where each row is on a single line and contains one or more fields separated by commas. The CSV Data Production Library (DPL) reads rows of data from a CSV file and injects the data into a test script as string arrays. Each time TestMaker operates the test the DPL Action controls which row of CSV data to use next. When the DPL reaches the bottom of the CSV file it loops back to the top. See the While command to end the test upon reaching the end of the CSV file data.

Use in Selenium

See Task 3 of the Selenium Ajax Tutorial.

Use in soapUI

See Task 3 of the soapUI Tutorial.

Use in Java, Jython, and other scripting languages

The DPL passesd a Hashmap/Dictionary to the unit test script. For example, a Java-based unit test handles the incoming data like this:

    public HTMLTest(){
        selenium = new SeleniumHtmlunit();
        selenium.setLogLevel("INFO");
        IDs = new HashMap();
        IDs.put("","");
        IDs.put("3000","3000");
         ...
        }

    public void test(Object DPLValues) throws Exception{
        if (DPLValues != null){
            applyValues(DPLValues);
        }

        // Set a base URL for open() if all your URLs are relative
        selenium.setBaseUrl("http://localhost:8080/");
        selenium.setSpeed(IDs.get("3000"));
        ...
        }

    void applyValues(Object values) {
        // Assigns the values included in the DPL to the selenium code
        if (values instanceof HashMap) {
            HashMap DPLvalues = (HashMap) values;
            for (String key : IDs.keySet()) {
                if (DPLvalues.containsKey(key)) {
                    IDs.put(key, (String) DPLvalues.get(key));
                }
            }
         }

Use the Transformer (found in the Tools drop-down menu) to transform a Selenium or TestGen4Web script into a Java or Jython class. The results class is data enabled to receive DPL provided data.


Relational Data (RDBMS) Operational Data For Tests 

Relational Database Management Systems (RDBMS) store data in a relational model of tables, rows, and columns. The Structured Query Language (SQL) provides a syntax for defining views of the relational model. The RDBMS DPL injects relational data into the test at test runtime.

The RDBMS DPL has five configuration parameters:

  1. Connector: The JDBC type to connect to the database. TestMaker does not provide a JDBC driver since databases provide JDBC connectors by implementing the java.sql.Driver interface. In the example given, the driver class used is the com.mysql.jdbc.Driver from the MySQL database.
  2. URL: The URL of the database.
  3. Logging: The account username for database access.
  4. Password: The account password for database access.
  5. Query: The query for the database. The query is done one time with the result stored for further use.

The TestMaker Editor graphically configures a DPL in the TestScenario. Here is the configuration syntax:


   
       
       
       
       
       
    



RDBMS DPL automatically injects operational test data into test scripts by using the table field names as mapping names.


UniqueDPL To Provide Unique Data In A Distributed Test

UniqueDPL implements a common data provider service to serve requests for unique data to the DPLs running in the TestNodes. It is up to the TestMaker operator to start the service. Once started the service will read data from a provided comma separated value (CSV) file to the DPLs. The service is threadsafe and has very little memory or network overhead.

Find the UniqueDPL installer in TestMaker_home/installme/UniqueDPL.


The TestMaker Editor graphically configures a DPL to access data at test runtime from the UniqueDPL service in the TestScenario. Here is the configuration syntax:

                  langtype="java" name="UniqueDPL"/>

     
           
           
           
           
     

     
          
          

- Filename is the name of the csv file
- Host the name of the server that will be used, be sure to use fully qualified name like
llara.AVANTICA.AVANTICATEC.NET instead of common localhost!
- Port the name of the server that will be use
-StartService if the serive should be started inside a testnode

If you start the service automatically, you will need to add this boiler plate code to stop it
at the end:

                                testclass="com.pushtotest.tool.dpl.provided.UniqueDPLService" langtype="java">
             
             


The UniqueDPL service loops back to the beginning of the CSV file when it reaches the final row.

EncryptDPL To Provide Secure Data

Provide MD5 DES password encrypted data files to tests using EncryptDPL. This Data Production Library (DPL)  reads encrypted data from comma separated value (CSV) files. The DPL decrypts data using a user provided password. For example, the plan-text data looks like this:

user_id, user_password
frank, mylovelorette
frank, myfriendcarol

The encrypted data looks like this:

user_id, user_password
fW8+F2tbiXfBMZHj7bXzkg==, OMM96f3VtTx7vdN4QPdd+Q==
NOmZTZP9H4NeBZeGEfwtZA==, QB+pReZ+2yuXEK7ku4flrg==

Note that the encrypted data file does not encrypt the mapping names, only the subsequent rows of data are encrypted.

EncryptDPL reads the encrypted data, decrypts the data using the provided password, and provides the data to the test.

There are four steps to using EcyrptDPL:

  1. Encrypt the CSV data. Choose the the Encryption Utility command in TestMaker -> Tools drop-down menu.
  2. Create a test of your application. Create the test in Selenium IDE, soapUI, or as a unit test written in Java, Jython, Ruby, PHP, Perl, or other supported language.
  3. Configure a TestScenario to provide the decrypted operational test data to your test. Use the TestMaker Editor to create the TestScenario.
  4. Run the test.

Access the EncryptDPL from the Editor's Use Case tab. Add a DPL to a test. Then choose EncryptDPL from the DPL Type menu.


TestMaker Editor configuring a DPL


When you run a TestScenario the EncryptDPL will read encrypted data from the provided CSV file, it decrypts the data, and passes the data to the test. The TestScenario provides the password to decrypt the data file.  TestMaker supports an optional ${password} parameter to request the password at test runtime. Using this parameter, TestMaker displays a password request dialog when you run the test.



Enter the password and click Accept.


Encryption and Decryption Utility

TestMaker includes a utility for encrypting and decrypting CSV files. Access the Encryption Utility in the TestMaker -> Tools drop-down menu.


Utility for encrypting and decrypting CSV data files


The Encryption utility uses password encryption. It creates a PWS digest using MD5 and then encrypts using SimpleDES.


Contact PushToTest Global Services for an advanced form of Encrypt that supports advanced encryption technology.


Advanced Topics for EncryptDPL

An example of the TestScenario syntax for EncryptDPL follows:


  

     

       

       

     

   

   

     

     

   

   

     

       

         

           

             

               

                 

                   

                 

               

             

           

           

Script-level Encryption/Decryption

TestMaker provides Java libraries to encrypt and decrypt data files. Use these libraries from a Java or Jython unit test script. Iinstead of using the EncryptDPL to decrypt the CSV files, you can use a normal HashDPL, and pass the encrypted text to the test script, and there you can use the TOOL encryption package to decrypt it! There is no indication in the scenario of the encryption.


com.pushtotest.tool.encryption.Encryptor


Encryptor(password).encryptCSV(

                new File(txtSrc.getText()),

                new File(txtDest.getText()),

                "NORMAL");


Encryptor(password).decryptCSV(

                new File(txtSrc.getText()),

                new File(txtDest.getText()),

                "NORMAL");


Example Script To Show Decrypted Data

The following is an example Jython script to display the contents of decrypted data received from the EncryptDPL.


import sys

import re

from java.util import HashMap

from java.util import Map

from java.lang import System

import time


class Report:


    def __init__(self):

      pass;


    def print(self,DPLvalues= None):

   

        print "Report.print() values: "

   

        hashMap =  isinstance(DPLvalues, Map)

        if hashMap:

            for value in DPLvalues.keySet():

                print( value + " = " + DPLvalues.get(value) )

        print

        print


def getReport():

    test = Report();

    return test;


Sharing and Reusing Operational Data Between Test Steps

Tests not only receive operational test data from a DPL, tests may also store application data in a DPL. TheLocker DPL is a thread-safe, virtual user safe, data storage and retrieval DPL. See an example in the MailerCheck tutorial.


Original Operational Data For Tests Using Lingo

DPLs can create their own operational test data. For example, the Lingo DPL creates pseudo random gibberish text that is handy for testing. To help understand how to create DPLs, here is the source code for the Lingo DPL:

package com.pushtotest.tool.dpl.provided;

import com.pushtotest.tool.dpl.DataProduction;
import com.pushtotest.tool.util.Lingo;
import java.util.Vector;
import java.util.Random;
import java.util.Date;

/**
 * DPL that provides Dummy text of the type "Lorem ipsum.."
 * @author wmartinez
 */
public class LingoDPL implements DataProduction{

    private Random myRandom = new Random(new Date().getTime());
    private Vector vPayloads = new Vector();
    private Lingo lingoGen = new Lingo();
    private int iPosition = 0;
    
    /** Creates a new instance of LingoDPL */
    public LingoDPL() {
    }

    public void setup() {
        // Default of Lingo default size
        vPayloads.add(lingoGen.getMessage());
    }

    public void setup(int messSize) {
        // Creates only one message of messSize
        vPayloads.add(lingoGen.getMessage(messSize));
    }

    public void setup(String[] arguments) {
        // arguments contains a list of sizes in string form
        for (String sSize: arguments) {
            int iSize = Integer.parseInt(sSize);
            vPayloads.add(lingoGen.getMessage(iSize));
        }
    }

    public Object getData() {
        return vPayloads.get(iPosition);
    }

    public Object getRandomData() {
        return vPayloads.get(myRandom.nextInt(vPayloads.size()));
    }

    public Object getNextData() {
        Object sToReturn = vPayloads.get(iPosition++);
        if (iPosition == vPayloads.size()){
            iPosition = 0;
        }
        return sToReturn;
    }

    public Object getDataByIndex(int index) {
        if (index >= vPayloads.size())
            index = vPayloads.size()-1;
        return vPayloads.get(index);
    }

    public void tearDown() {
        vPayloads.clear();
    }
    
}

Creating Your Own DPL

Creating your own DPL requires Java programming skills and a familiarity with the DPL abstract class definition. Implementing a DPL requires a Java class to implement the standard DPL methods including getNextData and getDataByIndex.

Instructions to receive the TestMaker source code are found here.

The DPL interface definition is found in community/tool/src/com/pushtotest/tool/dpl/DataProduction.java

DPL implementations are found in community/tool/src/com/pushtotest/tool/dpl/provided

Source code for the Editor is found at community/Editor/src/Resources

PushToTest Global Services adds and changes DPLs for PushToTest customers.




 

 

Additional documentation, product downloads and updates are at www.PushToTest.com. While the PushToTest testMaker software is distributed under an open-source license, the documenation remains (c) 2010 PushToTest. All rights reserved. PushToTest is a trademark of the PushToTest company.