Load test for a webpage with basic authorization and how to modify the requests
Hi,
I have a load test that uses basic authorization for the user login .So I need to retrieve the information for username and password for n number of users and run a load test for all of them simultaneously.I am able to retireve it for one and run it but failed to change the info for different users and put it back again in the requestheader.
Connection (2) has request (2) with Authorization = "Basic dm1xYTNcTG9hZDI6cGFzc3dvcmQ=" .This decodes as "vmqa3\Load1:password" where username is vmqa3\Load1 and password is "password".So how can I change it in my script for "n" number of users .The value needs to be changed like Load1,Load2..... etc n times and to load it back in the request body different for each user.
For example for user2 i.e i.e Load2,it should be vmqa3\Load2:password and decoded form is "dm1xYTNMb2FkMTpwYXNzd29yZA=="
My script is like this.I tried it for two users but right now it is not changing the authorization in the request body to have different username information.It is just signing with the same information as "vmqa3\Load1:password".
Please help me find what is wrong with the script and how can I change the info and pass it differently for each user.
function SignInSignOutvmqa31()
{
var VirtualUsers, TestInst, i, TaskVar, request,Load;
VirtualUsers = new Array();
Logins = new Array();
// Creates a new load test
TestInst = LoadTesting.CreateTestInstance("TestInstance4");
for(i = 1; i<=2; i++)
{
// Obtains the task
TaskVar = LoadTesting.HTTPTask("Task8");
TaskVar.TargetServer = "vmqa3:80";
// Creates a virtual user and specifies the task and test for it
VirtualUsers = LoadTesting.CreateVirtualUser("VirtualUser" + aqConvert.VarToStr(i));
VirtualUsers.Task = TaskVar;
VirtualUsers.Group = TestInst;
// Modifies the request variable
request = TaskVar.Connection(2).Request(2);
header = TaskVar.Connection(2).Request(2).RequestHeader;
headerArray = header.split("\r\n");
accountAndPassword = headerArray[4];
//decodedAccountAndPassword = decode64(accountAndPassword.substring(21, 500));
//Log.Message ("account=" + decodedAccountAndPassword);
//account = decodedAccountAndPassword.split(":")[0];
//password = decodedAccountAndPassword.split(":")[1];
//Log.Message("account=" + account);
//Log.Message("password=" + password);
headerArray[4] = encode64("vmqa3\Load" + i + ":password");
header = "Basic" + headerArray[4];
Log.Message(headerArray[4])
}
// Runs the task
TestInst.Run("Task8");
}
Thanks,
Sumedha