Contents


Customizing Rational Functional Tester scripts for data-driven testing

Comments

Data-driven testing is one of the most important aspects of functional automation. It's the most important technique to implement an actual usage scenario by providing unique data sets to the automation, making it more realistic and closer to the end user usage pattern. It's also useful in scenarios where millions of records are required to be supplied to the application under test for complete coverage. IBM® Rational® Functional Tester provides a framework which is useful for creating automated data-driven test scripts. However, automation engineers are required to customize their scripts to suit their application and specific requirements.

What is a datapool?

A datapool is nothing more than a test dataset. It's a collection of related data records which supplies data values to the variables in a test script during test script playback.

Creating a datapool

Automation engineers can use the following step-by-step procedure to import a CSV file to RFT.

  1. Create a .CSV (comma separated values file) with the desired test data set. See Figure 1.
Figure 1. CSV file
example of a CSV file
example of a CSV file
  1. Open Functional Tester with the correct data store. Right click on Project and select Add Test Datapool.
Figure 2. Adding a test datapool
adding a test datapool
adding a test datapool
  1. Select the project and enter a name for the datapool. Click Next.
Figure 3. Naming the datapool
naming the datapool
naming the datapool
  1. Browse to the CSV file you wish to import, which contains the desired test data. Click Finish.
Figure 4. Finishing the import
Finishing the import
Finishing the import
  1. Open the datapool to verify it.
Figure 5. Verifying the datapool
Verifying the datapool
Verifying the datapool

Using the imported CSV file as a datapool

  1. Right-click on the Project and select Add Script Using Recorder.
Figure 6. Adding a script
Adding a script
Adding a script
  1. Select the project and enter a script name. Cick on Next.
Figure 7. Naming the script
Naming the script
Naming the script
  1. Update the script assets Window pop-up with necessary details.
Figure 8. Selecting script assets
Selecting script assets
Selecting script assets
  1. To select the test datapool, click on Browse and select the newly imported CSV datapool. Click OK.
Figure 9. Selecting the datapool
Selecting the datapool
Selecting the datapool
  1. Click Finish.
  2. Open the application.
Figure 10. The application
The application on Paused
  1. Select the application and click OK. In this case, we're using the ClassicJavaB sample application.
Figure 11. Selecting the application
Selecting the application
Selecting the application
  1. Start recoding a script for the data input operations you wish to automate. We clicked on the Place Order button, selected the New Customer radio button and then clicked OK. On the next screen the application opens up a Place an order form. We entered values in Card number, Expiration Date, Name, Street, City, State, zip and Phone before clicking the Place order button. Finally we clicked OK for order confirmation.
  2. The above script recording will generate the following recorded script:
Listing 1. The recorded script
import resources.Script1Helper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;

public class Script1 extends Script1Helper
{
	public void testMain(Object[] args) 
	{
		// Start Application
		startApp("ClassicsJavaB");
		
		// Click on Place Order
		placeOrder().click();
		
		// Click on New Customer radio button
		newCustomer().click();
		ok().click();
		
		// Enter the values
		cardNumberIncludeTheSpacesText().click(atPoint(43,10));
		placeAnOrder().inputKeys("1111 1111 1111 1111");
		expirationDateText().click(atPoint(33,9));
		placeAnOrder().inputChars("01/06");
		nameText().click(atPoint(95,6));
		placeAnOrder().inputChars("rama");
		streetText().click(atPoint(65,13));
		placeAnOrder().inputChars("saswad raod");
		cityStateZipText().click(atPoint(44,9));
		placeAnOrder().inputChars("pune");
		phoneText().click(atPoint(31,14));
		placeAnOrder().inputChars("91 22 122345");
		placeOrder().click();
			
		// 
		ok().click();
		
		// Frame: ClassicsCD
		classicsJava(ANY,MAY_EXIT).close();
	}
}
  1. This recorded script is useful for re-entering the static records which got hard coded in the script. For data-driven testing, automation engineers are required to provide unique records when the script gets executed. The above recorded script needs to be modified in order to provide the necessary data set from the datapool at runtime. The test script shown below is a customized script for that purpose. The modified part of the script is marked in bold.
Listing 2. Customized script
import org.eclipse.hyades.execution.runtime.datapool.IDatapoolIterator;import resources.Script1Helper;import com.rational.test.ft.*;import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.script.*;import com.rational.test.ft.value.*;import com.rational.test.ft.vp.*;public class Script1 extends Script1Helper{public void testMain(Object[] args) {
	// DatapoolScriptSupport provides methods for accessing rows in an associated datapool.
	DatapoolScriptSupport dpss = new DatapoolScriptSupport();

	//Declare 'dp' as an object for IDatapool 
              (org.eclipse.hyades.execution.runtime.datapool.IDatapool)
org.eclipse.hyades.execution.runtime.datapool.IDatapool dp;
	
	//Create a file object with complete TestDatapool file path
java.io.File dpfile = new java.io.File("D:\\Documents and Settings\\
pradosht\\IBM\\rationalsdp6.0\\workspace\\Project3\\TestDatapool1.rftdp");
		
	//Load the Testdatapool
	dp = dpss.dpFactory().load(dpfile,true);
		
	//Open the Test Datapool
	IDatapoolIterator dpitr = dpss.dpFactory().open(dp,"");
	
	//Initialize Test Datapool	
	dpitr.dpInitialize(dp);
		          
//Starting application
	startApp("ClassicsJavaB");while(!dpitr.dpDone())
	{
		// Click on Place order
		placeOrder().click();
		
		// Click on New Customer
		newCustomer().click();
		ok().click();
		
		//Get the current record & store it in record object
		IDatapoolRecord dprec = dpitr.dpCurrent();
			
		// Frame: Place an Order – Click on Card Number
		cardNumberIncludeTheSpacesText().click();

		//By accessing the corresponding cell in the current record from excel sheet
		placeAnOrder().inputKeys(dprec.getCell(0).getStringValue());

		// Frame: Place an Order – Click on Date 
		expirationDateText().click();

		//By accessing the corresponding cell in the current record from excel sheet
		placeAnOrder().inputChars(dprec.getCell(1).getStringValue());

		// Frame: Place an Order – Click on Name
		nameText().click();

//By accessing the corresponding cell in the current record from excel sheet
		placeAnOrder().inputChars(dprec.getCell(2).getStringValue());

		// Frame: Place an Order – Click on Street 
		streetText().click();

//By accessing the corresponding cell in the current record from excel sheet
		placeAnOrder().inputChars(dprec.getCell(3).getStringValue());

		// Frame: Place an Order – Click on CityStateZip
		cityStateZipText().click();

//By accessing the corresponding cell in the current record from excel sheet
		placeAnOrder().inputChars(dprec.getCell(4).getStringValue());

		// Frame: Place an Order – Click on Phone
		phoneText().click();

//By accessing the corresponding cell in the current record from excel sheet
		placeAnOrder().inputChars(dprec.getCell(5).getStringValue());				
		// Frame: Place an Order
		placeOrder2().click();
		
		//Order Confirmation
		ok2().click();

		//Iterating to the Next Record
		dpitr.dpNext();
		
	   }
		
		// Close Application
		classicsJava(ANY,MAY_EXIT).close();
	}
}

In this article you learned how to use datapools for implementing data-driven tests and the necessary customization required in Rational Functional Tester 6.1 scripts. We hope you found it helpful.


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=169282
ArticleTitle=Customizing Rational Functional Tester scripts for data-driven testing
publish-date=10242006