Forum Discussion

sarya's avatar
sarya
Frequent Contributor
15 years ago

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


9 Replies

  • Hi Sumedha,


    TestComplete provides built-in support for Basic authentication, and therefore, you do not need to process the information in your script. To learn how to specify login information for Basic authentication, please see the "Supported Authentication Types" help topic.


  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Allen,



    The help files say like this :

    Basic authentication - The browser displays a dialog box where the user enters his or her user name and password (which are also called credentials). The password is passed to the Web server as Base64 encoded clear text, which means that this password might be intercepted, decoded and reused. This authentication method is fully supported by TestComplete.



    I tried to do in the script by decoding and encoding the login info . Also if we want to run the script against 100 users,do I need to enter username,password information for all the 100 users in the authentication information grid. Can it not be done with the script that I have ?



    Thanks,

    Sumedha


  • Hi Sumedha,


    TestComplete uses the same login information for all virtual users. Could you please tell us why different login information is neded for your test? Are you going to create 100 Windows accounts for your virtual users?


  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Allen,



    My load test wants to have 'n' number of users to login at the same time and they have different login information .The server logs should show as 'n' different users logged in at the same time. Can we not do this scenario where users login with different information. Also you told me to enter the information in the authentication information workspace but how will TC use these different usernames and passwords for login.



    Thanks,

    Sumedha
  • Hi Sumedha,


    Currently, TestComplete can use only a single login/password combination for all virtual users. However, I've registered your request as a suggestion in our DB.


    >>>

    how will TC use these different usernames and passwords for login.

    <<<

    When you specify a login/password for a server name and domain, TestComplete will always use the login and password for all virtual users which work with the server located in the domain. If the test works with different servers, you may need to specify another login/password/server/domain combination.


  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Allen,



    I am doing the load testing using scripts and not visually.I have two instances of scripts :One that tests against IIS server using windows authentication and other using Tomcat .The script that I created takes the requests from the request headers and substitutes a new username/password for each user and logins using that information .I verified the IIS logs and it shows me requests for different usernames and passwords.As you mentioned that TC uses only one username/password for all virtual users then how am I able to use different login information in my scripts for different virtual users.Is there something that I am doing wrong in the script ?



    Thanks,

    Sumedha
  • Hi Sumedha,


    The built-in features of TestComplete allow specifying only a single login/password combination per domain/server. However, it looks like your script overrides TestComplete's behavior, and as a result, different users use different login data (encoded by your script).


  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Allen,



    So does it mean I cant use a script that uses multiple number of users which can login with different username and password combination even though the TC script can do that in the right manner .My company's load test requirement is users have to login with different username and password and display different session ids in the server logs.Running the virtual users against the same username,password is not the requirement for the load test that I want to create.

    So can't I achieve this scenario with Test Complete as I am creating scripts to get login information(POST requests or basic authorization) and edit that info for multiple users and put it back in the requests and run the script ?



    Thanks,

    Sumedha
  • Hi Sumedha,




    Let me clarify: you can implement the scenario you need in your script.




    Since you run your tests from script, create several instances of your Load Testing task and put different login info to each of the instances. To do this, you need to modify your test to make it create an individual task instance for each user:




    VirtualUsers = LoadTesting.CreateVirtualUser("VirtualUser" + aqConvert.VarToStr(i));

    VirtualUsers.Task = LoadTesting.HTTPTaskByName("Task8");

    VirtualUsers.Group = TestInst;




    After that, you can put different login info for different users by changing the task instances from script.