Loop Request to capture Password and pass in the request for corresponding Username

Hi, can any one help me with this scenario?

We have passwords stored in Cyberark vault where we need to fetch password for each username and pass in the Vugen script for login to application under test.

Total user names = 1000 which are in parameter file which is part of Vugen script.

Need to fetch passwords for each username from cyberark using web_reg_save_param function in Vugen script. So when script is ran, username_001 is sent and password for username_001 is captured using web_reg_save_param.
My goal is to capture all 1000 accounts in Vugen_init section using for loop and then pass to actual login request. I was able to capture all passwords using web_reg_save_param and using for loop, but I'm unable to pass corresponding password of the username since the latest password which was captured is getting passed for actual substitution in the script.
I need to pass password for username_005 as password_005. Below is my script.

vuser_init()
{
    int i;

    web_set_sockets_option("SSL_VERSION", "TLS1.2");


    for (i=1; i<=5; i++)
    {
        lr_start_transaction("CCPWebAPI");

        web_reg_save_param("Password_Param",
            "LB=\"Content\":\"",
            "RB=\",\"",
            // "ORD=ALL",
            LAST);

        web_custom_request("web_custom_request",
            "URL=">xyz.stg.cyberark.com/.../Accounts
            "Method=GET",
            "TargetFrame=",
            "Resource=0",
            "Referer=",
            "Body=",
            LAST);

        lr_end_transaction("CCPWebAPI", LR_AUTO);
    }
    return 0;
}

Action()
{

    lr_start_transaction("Substitute_Password");

    //Dummy Request

    web_custom_request("web_custom_request",
        "URL=">xyz.stg.cyberark.com/Accounts
        "Method=GET",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Body=",
        LAST);

    lr_end_transaction("Substitute_Password", LR_AUTO);

    return 0;
}

Edited by JHF: Code in Code-Block

  • Verified Answer

    0  

    Hi  , based on your code it looks like you can only request one password at a time.

    Not sure why you need to get all the passwords in the vuser_init(). A common pattern is to determine in the vuser_init() section which user to use for the remaining of the script. You can easily create a Parameter that gives an Unique user name, only one time. So each running Vuser will get assigned a unique user name. You only need to collect the password of that single user.

    When you want to use a different user each time you go through the Action loop, you might grap the corresponding password in the Action. Seems to be a waist of resources when every user is requesting all those 1000 passwords at the beginning in vuser_init().

    When you want to stick with your approach it is good to learn about Array parameters. I saw that you already experienced with "ORD=ALL". Have a closer look to lr_paramarr_len() and lr_paramarr_idx() functions.

    Trick: When you have a parameter X and you create parameters X_1, X_2, X_3 and a parameter X_count=3 those will work nicely with the above mentioned two parameter functions. The "Ord=ALL" setting does just create multiple parameters based on the parameter-base-name (e.g. X) and appending _1, _2, _3, ... and in the end it creates a _count. One could say that lr_paramarr_len("X") is just a shortcut for atoi(lr_eval_string("X_count"))

    P.S.

    1. Next time you post some sample code look to the 'Insert" menu below the edit box and choose Code.
    2. Go over the online help and make yourself familiair with all the lr_*, web_* functions. You will learn the capabilities and can later go back to lookup the details.

    How to ask questions

    Reward contributions via likes or 'verified answers'