VuGen: Dynamic data in web_submit_data

This was developed as a result of load testing a bridal registry site written with BlueMartini. There needed to be a way for the Vuser to clean up its bridal registry at the end of each iteration. However, I couldn’t be assured of a specific number of items (because the item catalog changed frequently, and we varied the number of items added).

The web_submit_data function looks for a symbolic “LAST” to determine when it has reached the end of a variable argument list. This was modified by inserting it into a predefined argument array at the end of the dynamic data. This way, the number of parameters passed to web_submit_data was always the same, but not all entries in the array would be processed.

The code below is the original prototype of the technique, using a generic website.

#include "as_web.h"
 
/*
Deal with a dynamic number of data items returned AND use them in a web_submit_data function
without knowing how many there will be in total.
The example here goes to Yahoo's most recent upgrades on stock ratings.
The number of these items can change over time so when we try to retrieve the quotes for the values
We must deal with differing numbers of values to place in the web submit data.
This script deals with at most 20 dynamic values but you could expand it as you wish
*/
 
Action1()
{
    int idx;
    int instance;
    char stock_ticker[10];
    char name[20][32];
    char value[20][32];
 
    // save the dynamic values in a parameter called 'stocks'
    // -- use ORD=ALL to save all instances of the parameter in one variable
    web_reg_save_param("stocks", "LB=q?s=", "RB=&d=t", "ORD=ALL", LAST);
 
    web_url("Up/Downgrades",
    "URL=http://www.kd98dw904idndkl.com/c/u.html",
    "Resource=0",
    "RecContentType=text/html",
    LAST);
 
    // write each of the dynamic stock ticker symbols into an
    // array entry to be used in the name/value pairing for the submit
    for (instance = 1; instance <= atoi(lr_eval_string("{stocks_count}")) ; instance++)
    {
        sprintf (stock_ticker, "{stocks_%d}", instance);
 
        strcpy (name[instance], "name=s");
        sprintf (value[instance], "value=%s", lr_eval_string(stock_ticker));
    }
 
    // make the last name entry LAST so that the function will stop being parsed at the end of the entries
    strcpy (name[instance], "LAST");
 
    web_submit_data("q",
    "Action=http://www.kd98dw904idndkl.com/q",
    "Method=GET",
    ITEMDATA,
    name[1],value[1],ENDITEM,
    name[2],value[2],ENDITEM,
    name[3],value[3],ENDITEM,
    name[4],value[4],ENDITEM,
    name[5],value[5],ENDITEM,
    name[6],value[6],ENDITEM,
    name[7],value[7],ENDITEM,
    name[8],value[8],ENDITEM,
    name[9],value[9],ENDITEM,
    name[10],value[10],ENDITEM,
    name[11],value[11],ENDITEM,
    name[12],value[12],ENDITEM,
    name[13],value[13],ENDITEM,
    name[14],value[14],ENDITEM,
    name[15],value[15],ENDITEM,
    name[16],value[16],ENDITEM,
    name[17],value[17],ENDITEM,
    name[18],value[18],ENDITEM,
    name[19],value[19],ENDITEM,
    LAST);
 
    return 0;
}

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events