
Understanding the Correlation Options:
Correlation allows you to save dynamic values during test execution. Thesesettings let you configure the extent of automatic correlation performed byVuGen while recording. All of correlation options are disabled by default.The Correlation options only apply to the VBScript and JScript languages.Correlate small numbers - Correlate short data types such as bytes,characters, and short integers. (disabled by default)Correlate large numbers - Correlate long data types such as integers, longintegers, 64-bit characters, float, and double. (disabled by default)Correlate simple strings - Correlate simple, non-array strings and phrases.(enabled by default)Correlate arrays - Track and correlate arrays of all data types, such as string,structures, numbers, etc. (disabled by default)Correlate structures - Track and correlate complex structures. (disabled bydefault)For further instructions, see “Setting Script Recording Options” on page 60.Setting Script Recording OptionsYou set the Recording Options before your script related initial recording.The number of available options depends on the script generation language.
To set the script recording options:
1 Open the Recording Options. Choose Tools > Recording Options from themain menu or click Options... in the Start Recording dialog box. TheRecording Options dialog box opens.Chapter 4 • Setting Script Generation Preferences612 Select the General:Script node.3 In the Select Script Language box, select a mode of code generation — CLanguage or Visual Basic for Applications. Use C to record applications thatuse complex constructs and C++ code. Use Visual Basic to record scriptbasedapplications.4 In the Scripting Options section, enable the desired options by selecting thecheck box adjacent to it. The options are explained in the previous sections.5 Click OK to save your settings and close the dialog box.
Correlation allows you to save dynamic values during test execution. Thesesettings let you configure the extent of automatic correlation performed byVuGen while recording. All of correlation options are disabled by default.The Correlation options only apply to the VBScript and JScript languages.Correlate small numbers - Correlate short data types such as bytes,characters, and short integers. (disabled by default)Correlate large numbers - Correlate long data types such as integers, longintegers, 64-bit characters, float, and double. (disabled by default)Correlate simple strings - Correlate simple, non-array strings and phrases.(enabled by default)Correlate arrays - Track and correlate arrays of all data types, such as string,structures, numbers, etc. (disabled by default)Correlate structures - Track and correlate complex structures. (disabled bydefault)For further instructions, see “Setting Script Recording Options” on page 60.Setting Script Recording OptionsYou set the Recording Options before your script related initial recording.The number of available options depends on the script generation language.
To set the script recording options:
1 Open the Recording Options. Choose Tools > Recording Options from themain menu or click Options... in the Start Recording dialog box. TheRecording Options dialog box opens.Chapter 4 • Setting Script Generation Preferences612 Select the General:Script node.3 In the Select Script Language box, select a mode of code generation — CLanguage or Visual Basic for Applications. Use C to record applications thatuse complex constructs and C++ code. Use Visual Basic to record scriptbasedapplications.4 In the Scripting Options section, enable the desired options by selecting thecheck box adjacent to it. The options are explained in the previous sections.5 Click OK to save your settings and close the dialog box.
Correlating Statements
You can optimize Vuser scripts by correlating statements. VuGen’sCorrelated Query feature allows you to link statements by using the resultsof one statement as input for another.This chapter describes:
➤ About Correlating Statements
➤ Using Correlation Functions for C Vusers
➤ Using Correlation Functions for Java Vusers
➤ Comparing Vuser Scripts using WDiff
➤ Modifying Saved Parameters
The following information applies to all types of Vuser scripts except forGUI.About Correlating Statements
The primary reasons for correlating statements are:
➤ to simplify or optimize your codeFor example, if you perform a series of dependent queries one after another,your code may become very long. To reduce the size of the code, you cannest the queries, but then you lose precision and the code becomes complexand difficult to understand. Correlating the statements enables you to linkqueries without nesting.VuGen User’s Guide • Working with VuGen132
➤ to generate dynamic dataMany applications and Web sites identify a session by the current date andtime. If you try to replay a script, it will fail because the current time isdifferent than the recorded time. Correlating the data enables you to savethe dynamic data and use it throughout the scenario run.
➤ to accommodate unique data recordsCertain applications (for example databases) require the use of uniquevalues. A value that was unique during recording is no longer unique forscript execution. For example, suppose you record the process of opening anew bank account. Each new account is assigned a unique number which isunknown to the user. This account number is inserted into a table with aunique key constraint during recording. If you try to run the script asrecorded, it tries to create an account with the recorded number, rather thana new unique number. An error will result because the account numberalready exists.If you encounter an error when running your script, examine the script atthe point where the error occurred. In many cases, a correlated query willsolve the problem by enabling you to use the results of one statement asinput to another.
The main steps in correlating a script are:
1 Determine which value to correlate.For most protocols, you can view the problematic statements in theExecution log. You double-click an error message and jump directly to itslocation.Alternatively, you can use the WDiff utility distributed with VuGen todetermine the inconsistencies within your script. For more information, See“Comparing Vuser Scripts using WDiff” on page 136.
2 Save the results.You save the value of a query to a variable using the appropriate function.The correlating functions are protocol-specific. Correlation function namesusually contain the string save_param, such as web_reg_save_param andlrs_save_param. Refer to the specific protocol chapters for an explanationChapter 8 • Correlating Statements133on how to perform correlation. In several protocols, such as database andWeb, VuGen automatically inserts the functions into your script.
3 Reference the saved values.Replace the constants in the query or statement with the saved variables.Several protocols have built-in automatic or partially automated correlation:
Using Correlation Functions for C VusersTo correlate statements for protocols that do not have specific functions,you can use the C Vuser correlation functions. These functions can be usedfor all C-type Vusers, to save a string to a parameter and retrieve it whenrequired. For similar functions for Java, Corba-Java, or RMI-Java Vusers, see“Using Correlation Functions for Java Vusers” on page 135.For additional information about the syntax of these functions, refer to theOnline
Function Reference.
lr_eval_string Replaces all occurrences of a parameter withits current value.
lr_save_string Saves a null-terminated string to a parameter.
lr_save_var Saves a variable length string to a parameter.VuGen User’s Guide • Working with VuGen134Using lr_eval_stringIn the following example,
lr_eval_string replaces the parameter row_cntwith its current value. This value is sent to the output window using lr_output_message.
Using lr_save_stringTo save a NULL terminated string to a parameter,
use lr_save_string. To savea variable length string,
use lr_save_var and specify the length of the stringto save.In the following example, lr_save_string assigns 777 to a parameter emp_id.This parameter is then used in another query or for further processing.
lrd_stmt(Csr1, "select count(*) from employee", -1, 1 /*Deferred*/, …);
lrd_bind_col(Csr1, 1, &COUNT_D1, 0, 0);
lrd_exec(Csr1, 0, 0, 0, 0, 0);lrd_save_col(Csr1, 1, 1, 0, "row_cnt");
lrd_fetch(Csr1, 1, 1, 0, PrintRow2, 0);lr_output_message("value: %s",
lr_eval_string("The row count is:"));
lrd_stmt(Csr1, "select id from employees where name='John'",…);
lrd_bind_col(Csr1,1,&ID_D1,...);
lrd_exec(Csr1, ...);
lrd_fetch(Csr1, 1, ...);/* GRID showing returned value "777" */
lr_save_string("777", "emp_id");
Correlating Statements135Using Correlation Functions for Java Vusers
To correlate statements for Java, CORBA-Java, and RMI-Java Vusers, you canuse the Java Vuser correlation functions. These functions may be used for allJava type Vusers, to save a string to a parameter and retrieve it whenrequired.When recording a CORBA-Java or RMI-Java script, VuGen performscorrelation internally. For more information see Chapter 15, “CorrelatingJava Scripts.”Using the Java String FunctionsWhen programming Java Vuser scripts, you can use the Java Vuser stringfunctions to correlate your scripts.In the following example, lr.eval_int substitutes the variable ID_num withits value, defined at an earlier point in the script.In the following example, lr.save_string assigns John Doe to the parameterStudent. This parameter is then used in an output message.lr.eval_string Replaces a parameter with its current value.lr.eval_data Replaces a parameter with a byte value.lr.eval_int Replaces a parameter with an integer value.lr.eval_string Replaces a parameter with a string.lr.save_data Saves a byte as a parameter.lr.save_int Saves an integer as a parameter.lr.save_string Saves a null-terminated string to a parameter.lr.message(" Track Stock: " + lr.eval_int(ID_num));]lr.save_string("John Doe", "Student");// ...lr.message("Get report card for " + lr.eval_string(""));classroom.getReportCardVuGen User’s Guide • Working with VuGen136Comparing Vuser Scripts using WDiffA useful tool in determining which values to correlate is WDiff. This utilitylets you compare recorded scripts and results to determine which valuesneed to be correlated.If you are working with other protocols, you can view the Execution log todetermine where the script failed and then use the WDiff utility to assist youin locating the values that need to be correlated.To use WDiff effectively, you record the identical operation twice, andcompare the scripts (or data files for Tuxedo, WinSock, and Jolt). WDiffdisplays differences in yellow. Note that not all differences indicate a valueto correlate. For example, certain receive buffers that indicate the time ofexecution do not require correlation.
To search for correlations using WDiff:
1 Record a script and save it.
2 Create a new script and record the identical operations. Save the script.
3 Select the section you want to compare (Actions, data.ws, and so forth).
4 Select Tools > Compare with Vuser. The Open Test box opens.
5 Specify a Vuser script for comparison (other than the one in the currentVuGen window) and click OK. WDiff opens and the differences between theVuser scripts are highlighted in yellow.
6 To display the differences only, double-click in the WDiff window.
7 Determine which values need to be correlated.Note that in the above example, WDiff is comparing the data.ws from twoWinsock Vuser scripts. In this instance, the value to be correlated is the PIDfor the clock processes, which differs between the two recordings.To continue with correlation, refer to the appropriate section:
8Modifying Saved ParametersAfter you save a value to a parameter, you may need to modify it beforeusing it in your script. If you need to perform arithmetical operations on aparameter, you must change it from a string to an integer using the atoi oratol C functions. After you modify the value as an integer, you must convertit back to a string to use the new variable in your script.In the following WinSock example, the data at offset 67 was saved to theparameter, param1. Using atol, VuGen converted the string to a long integer.After increasing the value of param1 by one, VuGen converted it back to astring using sprintf and saved it as a new string, new_param1. The value ofthe parameter is displayed using lr_output_message. This new value may beused at a later point in the script.lrs_receive("socket2", "buf47", LrsLastArg);
lrs_save_param("socket2",NULL, "param1", 67, 5);
lr_output_message ("param1: %s", lr_eval_string(""));sprintf(new_param1, "value=%ld", atol(lr_eval_string("")) + 1);
lr_output_message("ID Number:"%s" lr_eval_string("new_param1"));