Create an advanced upload file test case in Rational Performance Tester

Advanced binary data manipulation

Simulating upload transactions is essential for good test coverage of a web application. Learn how to create Rational Performance Tester tests to upload a random file selected from a datapool of files to a target application. Advanced examples show how to create multiplatform test cases and how to generate random parameters at run time (a random file name or extension, for example). This article is meant for intermediate- to advanced-level Rational Performance Tester users.

Valerio Pengue (, Software Performance Engineer, IBM

Valerio Pengue has six years of experience as a software performance engineer. He has spent the last 3.5 years working on social software reliability testing in the IBM Software Lab in Dublin, Ireland.

28 August 2012

Also available in Chinese Russian

About this article

Many web applications offer an upload functionality to let users post or store files as binary content. Although IBM® Rational® Performance Tester includes features to manipulate binary content in test recordings, sometimes you might need a deeper level of customization. The examples in this article show how to use the basic file substitution feature in Rational Performance Tester and how to create more complex tests using multiple files and multiple platforms.

Recording the upload transaction

Upload transactions can be recorded in the usual way. The following example shows the steps for a web-based application using HTTP, but the same concepts apply to other network protocol.

  1. Start the Rational Performance Tester HTTP recorder to create a Test From New Recording, as Figure 1 shows.
Figure 1. Create New Test settings
Select Rational Performance Tester HTTP Recording from the recording wizard

The web browser specified in the recorder (Windows > Preferences > RPT HTTP Recording) will launch, and you can use it to execute the Upload transaction.

Make sure to insert a comment or a transaction with the Rational Performance Tester toolbar just before executing the upload action so you can easily identify it in the test afterward.

Figure 2. The Recorder Test Annotation toolbar
screen capture of the toolbar

The test will be generated automatically after stopping the recorder and closing the browser.

The binary content should be automatically detected by Rational Performance Tester as associated with a variable called MimeFileContent, as in Figure 3.

Figure 3. Test generation
MimeFileContent is one of Test Data parameters

Basic file substitution

In most test scenarios, you will execute the same transaction multiple times with different concurrent users. This also applies to upload transactions. To determine a more realistic test scenario, you might want the users to upload different files rather than just the one used in the recording.

With Rational Performance Tester, you can achieve this just by using the included features in few steps:

  1. Create a directory (for example, C:\Datapool), and add all of the files that you want to use in your tests.
  2. Create a CSV file with the content of the directory, specifying the full path for each file. You can run the following command line:
    C:\>dir /b /s c:\Datapool > datapool.csv
  3. Create a new datapool with 1 column as shown in Figure 4:
Figure 4. Datapool example
New Datapool settings (select 1 column)
  1. Uncheck both of these Options check boxes, as shown in Figure 5:
    • First row contains variable names and optional suggested types
    • First column contains equivalence class names and optional row numbers
Figure 5. Datapool example 2, New Datapool wizard
Specify the csv file in the New Datapool wizard

The datapool should look like Figure 6.

Figure 6. Datapool example 3
Datapool populated with the csv file
  1. Double-click the column name and specify the following values:
    • Name:Path
    • Type:unManageFile
Figure 7. Datapool example 4, setting the Path variable as unManagedFile
EditVariable pop-up dialog window
  1. Select the variable associated with the binary content from the test data, and click Substitute (see Figure 8).
Figure 8. Data substitution 1
MimeFileContent variable and Substitute selected
  1. Click Select Data Source.
Figure 9. Select Data Source
Screen segment, Select Data Source selected
  1. From the Select Data Source dialog window, select Datapool.
Figure 10. Data substitution 2
Datapool is one of the available source objects
  1. From the "Select datapool column" dialog window (Figure 11), select the data pool and the column that you want to include in the test.
Figure 11. Data substitution 3, select datapool and column
dialog window to select datapool column
  1. Select the access mode that you want to use in your test (Shared (per machine for Open mode and Random for Access mode in this example). See Rational Performance Tester help or the information center, cited in Resources, to learn about the different options.

The settings in Figure 12 will randomly select a different file at the start of each iteration. When the last row of the datapool is reached, it will just restart from the first row.

Figure 12. Datapool settings for access mode
Access mode dialog window
  1. Select the datapool column that you want to associate with the test variable (Path)
Figure 13. Data substitution 4
Data Source dialog window

If you have performed all the previous steps correctly, you will see the substitutions shown in Figure 14 in the Test Data view.

Figure 14. Data substitution 5
Path variable substituted for MimeFileContent type

You will now be able to execute your test with multiple users. Each of them will pick a random file from the datapool at each iteration and substitute the binary content in the upload HTTP request.

This customization will work in most cases although sometimes you might need to replace also other variables in order to make the script work. For example, the filename could be specified in a different variable or you need to specify also the file extension. Some of these scenarios will be covered in the next section.

Advanced test cases

This section shows two examples of advanced test cases that enhance the basic scenario described in the previous section.

Running the test on different platforms

One of the requirements of the file substitution is to specify the full path of the file in the datapool. This means that the file must be in a specific location of the test agent. For example, if you have created the script for a Microsoft Windows agent, you can run it from any Windows machine just by copying the datapool folder at the same location on the test machine. However, this will not work on a Linux platform. If you have both Windows and Linux agents in your test environment, the only workaround is to duplicate the test once you have applied all of the data correlations and edit the copy as a Linux version.

  1. To create the Linux version, just go through the steps outlined in the previous paragraph to create a Linux datapool, and then substitute the binary content variable with the column of the Linux datapool.
Figure 15. Data substitution, Linux
Path variable substituted for TestFiles_Linux datapool
  1. Add a custom code at the start of the test to get the OS of the machine that will run the test.
Figure 16. Add a custom code
test.GetOs custom code added at top of test case
  1. Modify the execution method of the custom code as Listing 1 shows.
Listing 1. Modify the execution method of the test.GetOs custom code
public String exec(ITestExecutionServices tes, String[] args) {
    String os = System.getProperty("");
    if (!os.startsWith("Windows")){
           return "Linux";
           return "Windows";

Insert all of the transactions and pages after the custom code under an If condition, and specify the following test control and condition parameters (shown in Figure 17):

  • First operand: custom code: test.GetOS
  • Operator: Equals
  • Second operand: Linux
Figure 17. If- condition parameters
Test Contents, Test Element Details panes

Modify the Windows script in the same way, but specify "Windows" as the second operand of the If-Condition.

You can now create a test schedule and add both versions of the upload test in sequence. At run time, one of them will be executed and the other one will be skipped, according to the OS platform of the agent that runs the script.

Figure 18. Upload Schedule template
infinite loop schedule, both versions in sequence

Correlating other parameters

The basic file substitution feature works in most cases, although sometimes you might need to correlate other parameters in the upload request to make it work properly. These might include:

  • Using different file names
  • Using a specific file extension
  • Using a specific MIME type

In the following example, you will not only set parameters for the file content but also generate a random file name that includes the right extensions according to the type of the file picked from the datapool. If you look at Figure 8 you will notice a parameter in the HTTP request called file, which represents the file name. It is set to the name of the file uploaded during the recording (Desert.jpg). In the basic file datapool (Figure 6), you have different file types (.bmp, .doc, .zip, and so forth). If you don't correlate this value, when Rational Performance Tester substitutes the file content at run time, the file will be uploaded with the file name set during the recording. To avoid this situation, you need to substitute this parameter with a custom code that generates a random file name and appends the extension of the file that is going to be pushed in the HTTP request.

There are many ways to generate a random name. The simplest one is to append a timestamp (which is a Rational Performance Tester variable) at the end of the file name. To create more realistic file names, the following example will use four datapools of words (Words) and will pick a random number of words from them to create the random file name. Additionally, it will append the extension based on the file picked from the datapool.

  1. You can create the Words datapools from a CSV file of words by following a procedure similar to the one used for the Files datapool. Make sure that you do not have special characters in any word.

The result should be like the Words datapool shown in Figure 19.

Figure 19. Words datapool
Words datapool contains the words from csv file
  1. Clone the datapool four times, giving a different name to each instance (for example, Filenames_part1). You can just save the datapool with a different name four times (Files > Save As).
  2. Insert a custom code at the start of the test. Listing 2 shows the exec method of the custom code.
Listing 2. Exec method of the custom code
  public String exec(ITestExecutionServices tes, String[] args) {
       Random randomGenerator = new Random(); 
       int random = randomGenerator.nextInt(100) + 1;
       String filename=args[0];
       if (random>25)filename=filename+" "+args[1];
       if (random>50)filename=filename+" "+args[2];
       if (random>75)filename=filename+" "+args[3];
       String extension=args[4].substring(args[4].lastIndexOf(".")+1,args[4].length());
return filename; }
  1. Add the datapool variables as arguments of the custom code. You need to add them in the following order:
    • Filenames_part1.string
    • Filenames_part2.string
    • Filenames_part3.string
    • Filenames_part4.string
    • TestFiles.Path
  2. To add the variables, just click the Add button in the Arguments pane. You can use the same steps and settings that you used to import the TestFile datapool.

At the end, your Arguments pane for the custom code will look like in Figure 20.

Figure 20. Generate Filename custom code
Datapool columns added as arguments of the custom code
  1. Then substitute the file variable with the custom code that you just created, using the same steps to substitute the file content.

Your request should now look like Figure 21.

Figure 21. Substitute the file name with custom code
test.GenerateFilename custom code substituted

Multiple file name substitutions

In case the file name occurs multiple times in the request, just repeat the step above for all the instances. Alternatively, you can use the Find function in Rational Performance Tester. Just follow these steps:

  1. Double-click the file variable in the Test Data view (see Figure 21) to get to the instance in the HTTP request.
  2. Right-click the highlighted text (Figure 22), and select Find more and substitute from the drop-down menu (Figure 23).
Figure 22. Substitute more instances of file name 1
Desert.jpg highlighted in the HTTP request
Figure 23. Substitute more instances of file name 2
Right click menu for test data
  1. In the "Substitute multiple items" view, go through the list of all of the occurrences of the file name in the requests, and check all of the instances that you want to substitute.
Figure 24. Substitute more instances of file name 3
substitute all instances in Substitute Multiple Items window
  1. Click Substitute checked until all of the instances have been substituted.



Get products and technologies



developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Rational software on developerWorks

ArticleTitle=Create an advanced upload file test case in Rational Performance Tester