Scripting Basics
- Modify each Vu script that accesses VTS so that the connection to VTS is made only once
in the init and end section.
- Add to the top of every vuser_init, action, and vuser_end section of scripts that use Client VTS API functions
- In the vuser_init section of the script, load the VTS dll, connect to VTS, and specify the column names:
PVCI pvci = 0;
int rc = 0;
char *VtsServer = "127.0.0.1"; // loopback on the same machine
lr_load_dll("vtclient.dll");
// Time out if VtsServer isn't found:
pvci = lrvtc_connect( VtsServer,8888,0);
rc = vtc_get_last_error(pvci);
if( rc != 0 ) {
lr_message("*** rc = %d for VTC connection to %s.", rc, VtsServer);
return -1;
}
- In the vuser_end section of the script:
PVCI pvci = 0;
pvci = lrvtc_disconnect();
Some LoadRunner examples in the VTS 2.doc
VTS User Guide are incorrect!
The sample script uses "raw" C function calls prefixed with "vtc_" rather than equivalent Loadrunner Vu function calls prefixed with "lrvtc_".
- In Action sections of scripts that use VTS, make lrvtc_ function calls.
VTC automatically creates column names, so lrvtc_create_column functions are not necessary.
int rc = 0;
// Insert into the next row the value of a single cell:
rc = lrvtc_send_message("Col1", "2");
// Insert into the next row data to several columns:
rc = lrvtc_send_row1("Col1;Col2;Col3", "1;John;Me", ";", VTSEND_SAME_ROW );
rc = lrvtc_send_row1("Col1;Col2;Col3", "3;Mary;Too", ";", VTSEND_SAME_ROW );
// Add value into the next column if the value does not already exist:
rc = lrvtc_send_if_unique("Col2", "4");
// increments value in Col1 row 2 by 3 (row num starts at 0):
rc = lrvtc_increment("Col1", 1, 9);
Each function call only replaces the parameters relevant to it, so you may have to clear out parameters if necessary before making different function calls.
rc = lrvtc_clear_column("Col3");
rc = lrvtc_clear_row(4);
VTS provides no indexes, so search though the key column to get its index (variable iRow)
then use it to obtain data from other columns in the same row:
int colSize;
int iRow;
char *LookFor = "Pam";
// Obtain the count of rows populated for column named "Col1":
colSize = lrvtc_column_size("Col1");
lr_message("*** Col1 size = %d",colSize);
for( iRow = 1; iRow <= colSize; iRow ++ ) {
// Retrieve, for the physical row index given, all columns:
rc = lrvtc_query_row( iRow );
lr_message("Row %d Col1=%s", iRow, lr_eval_string({Col1}));
if (LookFor == lr_eval_string({Col1})){
// Update columns, given the physical row index number:
rc = lrvtc_update_row1("Col1;Col2",iRow,"Any;Some",";");
// Retrieve, for the column name given, rows:
rc = lrvtc_query_column("Col3", 3);
// Update the value in the Column and Row specified:
rc = lrvtc_update_message("Col1", iRow , "20");
// Clear value in specified cell given its Column name & Row:
rc = lrvtc_clear_message("Col2",iRow);
}
}
- Run the script.
Error return codes are described biefly in vts2.h are:
#define VTCERR_INVALID_CONNECTION_INFO -10000 > verify the server name attribute.
#define VTCERR_FAILED_TO_RESOLVE_ADDR -10001
#define VTCERR_FAILED_TO_CREATE_SOCKET -10002
#define VTCERR_FAILED_TO_CONNECT -10003 > the vtconsole is not running.
#define VTCERR_INCOMPLETE_REQUEST -10100
#define VTCERR_FAILED_TO_RECV_RESPONSE -10101
#define VTCERR_INCOMPLETE_RESPONSE -10102
#define VTCERR_RESPONSE_ARGS_UNMATCH -10103
#define VTCERR_OPERATION_ERROR_BASE -11000
- If VTS has accumulated a set of data you want to keep,
from vtsconsole export them to a text file which you can import again later.
|
|