Posts tagged ‘How to capture and save file’

How to capture and save file on local machine in VuGen LoadRunner

As we know LoadRunner does not recognize the Client side activities, so the activity of saving file on local machine will not be recorded by LoadRunner. Below is the one way to resolve this.

Just before the URL which opens the PDF, capture the whole page into a string through correlation and write the captured string into a PDF file using File handling.

Sample Code:

Code Captures the PDF value in variable – c_PDF_Data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
char * filename = "c:\\PerfTuit.pdf";
long File_Size;
long Download_time;
long HttpRetCode;
long file;
int flag;

/*Set the parameter size large enough to save the data.*/

web_set_max_html_param_len("500000");

/*Mention left and right boundary as blank of web_reg_save_param function to capture the pdf returned by the server.*/

web_reg_save_param("c_PDF_Data ","LB=","RB=","Search=Body",LAST);

/*get the loading of PDF status in flag */

flag=web_submit_data("PerfTuit.aspx",

"Action=http://{p_SampleURL}/subDomain/area/ PerfTuit.aspx",

"Method=POST",

"RecContentType=application/pdf",

"Referer=http://{p_SampleURL}/subDoamin/area/",

"Snapshot=t01.inf",

"Mode=HTML",

LAST);

if(flag==1){

lr_error_message("status fail");

lr_exit(LR_EXIT_VUSER, LR_FAIL);

}

/* we have captured the pdf file into string, Now we will write the captured string into the PDF file.*/

/*First we will save the size of downloaded file into variable named sizePDF*/

File_Size= web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

/* other details*/

Download_time = web_get_int_property( HTTP_INFO_DOWNLOAD_TIME );

HttpRetCode = web_get_int_property( HTTP_INFO_RETURN_CODE );

lr_output_message("File size is %d ",  File_Size);

lr_output_message("Download Time is %d ",  Download_time);

lr_output_message("HTTP Return Code is %d ",  HttpRetCode);

/*Write the string captured into file.*/
if ((file = fopen(filename, "w+")) == NULL) {

lr_output_message ("Unable to create %s", filename);

return -1;

}
fwrite(lr_eval_string("{c_PDF_Data}"), File_Size, 1, file);

fclose(file);