Problem:
How can I assign unique data from a CSV file, such as UserID and Password, to each virtual user in my loadtest?
Resolution:
QUESTION
----------------------
How can I assign unique data from a CSV file, such as UserID and Password, to each virtual user in my loadtest ?
ANSWER
----------------------
The script below demonstrates how this can be achieved using the GetUserID() function which has been available since SilkPerformer V. This function returns a unique number for every Virtual User in the test and this can then be used to access an unique row in the CSV file..
NOTE: Before running this script the file login.csv must be in the Data folder as defined in SETTINGS | SYSTEM | DIRECTORIES tab
- User Data Files and it must be added to the project. This can be done via PROJECT pane | DATA FILES context menu (right click)
- Add Data Files
//----------------------------------------------------------------------
// How to access unique lines in a single SilkPerformer .csv file
//----------------------------------------------------------------------
benchmark SilkPerformerRecorder
use "WebAPI.bdh"
dcluser
user VUser
transactions
TInit : begin;
TLoadtest01 : 1;
TEnd : end;
var
hfile : number;
sUserName : string;
sPassword : string;
dcltrans
transaction TInit
begin
// Load CSV and set the delimiter to ","
FileCSVLoadGlobal(hfile, "Login.csv", ",");
// The GetUserID() function will retrieve a unique ID per
// virtual user. This ID is 1 for the first virtual user,
// 2 for the second and n for the n'th virtual user.
// Move to the row in the file using the unique ID obtained
// this means UserID 1 will use row 1, UserID 2 will use
// row 2 and so on...
FileGetRow(hfile, GetUserId());
// Set the username from the file at the specified
// row from the first column
sUserName:=FileGetCol (hfile, 1, 10);
// Set the password from the file at the specified row
// from the second column
sPassword:=FileGetCol (hfile, 2, 10);
end TInit;
transaction TLoadtest01
begin
//write to username and password to the output file for checking
writeln ("UserName: "+sUserName);
writeln ("Password: "+sPassword);
end TLoadtest01;
transaction TEnd
begin
//Unload the CSV File
FileUnload(hFile);
End TEnd;
Borland ID: 5965 Author: Borland Created on:
No comments:
Post a Comment