%% Last Updated: - [[2021-02-10]] - [[2020-12-04]] - [[2020-12-04]] Related - [[C]] %% VUGen is the component of [[LoadRunner]] that is used for the scripting and debugging of load tests. ## Using LoadRunner VUGen ### [[Random name generator in LoadRunner]] ### Exclude URLs Use the following code in VUGen to exclude URLs: ``` web_add_auto_filter ``` An alternative is found in the Run Time Settings, but sometimes Performance Center does not pick up Run Time Settings. ### Extracting one parameter inside one block out of many #### Problem The response consists of several blocks, each one with the same format, like so: ``` A: apple B: basketball C: children A: aardvark B: bonobo C: caterpillar A: Abigail B: bitterblue C: colourful ``` Assume that the order could change and the extraction of the right parameter cannot be guaranteed by simply always extracting the first value of C. The question is how to extract the value for parameter C ('children' in this case) in the block where A is 'apple'. #### Solution - Save all values of `A` into an array via `web_reg_save_param` with `Ordinal=All`. - Create a loop with a counter. In each loop: - Check whether `A_i` (where `i` is the counter) = `apple`. - If `A_i` and `apple` are the same (use `fxn strstr`), save value of `C_i`. - Else go to the next loop and try `A_(i+1)`. #### Code ``` RetrieveSubmittedApplicationVerification() { //Retrieve submitted application verification details lr_start_transaction("0005_RetrieveSubmittedApplicationVerification_NFR"); web_reg_save_param("message","LB=\"message\" : \"","RB=\"\n",LAST); web_reg_save_param("c_docToken", "LB=\"typeId\" : \"LEN_VER_0300\",\n \"typeName\" : \"Bank Statement\",\n \"docToken\" : \"", "RB=\"", LAST); web_reg_save_param("c_downloaddocTokens", "LB=version\" : \"1\",\n \"docToken\" : \"", "RB=\"", "Ordinal=All", LAST); web_reg_save_param("c_docNames", "LB=name\" : \"", "RB=\"", "Ordinal=All", LAST); web_custom_request("RetrieveApplicationVerificationDetail", "URL=domain.com.au/some/url, LAST); lr_end_transaction("0005_RetrieveSubmittedApplicationVerification_NFR", LR_AUTO); counter = 0; //////////////////////// // Find the document with the relevant filename and correlate its docToken as c_downloaddocToken while (counter != atoi(lr_eval_string("{c_docNames_count}"))) { counter++; sprintf(v_docNames, "{c_docNames_%d}", counter); lr_output_message("v_docNames is %s", v_docNames); sprintf(v_docNamesVal, "%s", lr_eval_string(v_docNames)); lr_output_message("v_docNamesVal is : %s", v_docNamesVal); lr_output_message("v_filename is %s", v_filename); if ((strstr(v_docNamesVal , v_filename)) != NULL) { //Change this value to the filename of the file that needs to be downloaded. sprintf(v_downloaddocTokens, "{c_downloaddocTokens_%d}", counter); lr_output_message("v_downloaddocTokens is %s", v_downloaddocTokens); sprintf(v_downloaddocTokensVal, "%s", lr_eval_string(v_downloaddocTokens)); lr_output_message("v_downloaddocTokens is : %s", v_downloaddocTokensVal); lr_save_string(v_downloaddocTokensVal, "c_downloaddocToken"); counter = atoi(lr_eval_string("{c_docNames_count}")); } } return 0; } ``` ### Route LoadRunner traffic through [[Fiddler]] Put this code in `vuser_init()`: ``` web_set_sockets_option("SSL_VERSION","TLS"); ``` In Run-time Settings, Go to Internet Protocol > Proxy. Tick Use proxy server and type the address `HTTP:127.0.0.1` and Port `8888` (or whatever Fiddler is listening on) and tick "Use the same proxy server for all protocols". ### Setting debug messages to show Set log level to only display errors, and then use this code to tailor what debug messages you want to see: ``` lr_set_debug_message(LR_MSG_CLASS_PARAMETERS, LR_SWITCH_ON); lr_output_message("Submission ID is:%s", lr_eval_string("{c_confirmationNumber}")); lr_set_debug_message(LR_MSG_CLASS_PARAMETERS, LR_SWITCH_OFF); ``` ## Troubleshooting ### Response not as expected but succeeding validations pass Solution: there may be some headers which should be sent that aren't being sent. Compare the headers of the recording and the replay and add those necessary. Ex: ``` web_add_auto_header("Adf-Rich-Message", "true"); ```