Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Upload and download files on LOADRUNNER

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

(1) upload files on LoadRunner

Web_submit_data ("importStudent.do"

"Action= https://testserver/console/importStudent.do",

"Method=POST"

"EncType=multipart/form-data"

"RecContentType=text/html"

"Referer= https://testserver/console/displayStudentList.do",

"Snapshot=t12.inf"

"Mode=HTTP"

ITEMDATA

"Name=uploadFile", "Value=D://Excel//data161955.zip", "File=yes", ENDITEM

LAST)

Note: script recording can be done using either Http/Html protocol or Click and Script protocol. The above scripts are recorded using Http/Html. It should be noted that no matter which protocol is used for recording, the file path and file name to be uploaded can only be English characters, not Chinese characters. Otherwise, the binary stream uploaded to the file may be recorded into the script in LR at the same time.

This problem also shows that LR's support for Chinese is far from enough.

The following is a more detailed example of the application.

Action ()

{

/ / defines the variable trans_time of type double, which is used to hold the execution time of the transaction.

Double trans_time

/ / defines the variable status of type int, which is used to hold the returned value of the transaction execution.

Int status

Lr_start_transaction ("Test")

/ / use the built-in function lr_get_transaction_duration to get the execution time of the transaction.

Trans_time=lr_get_transaction_duration ("Test")

Status= web_submit_data ("importStudent.do"

"Action= https://testserver/console/importStudent.do",

"Method=POST"

"EncType=multipart/form-data"

"RecContentType=text/html"

"Referer= https://testserver/console/displayStudentList.do",

"Snapshot=t12.inf"

"Mode=HTTP"

ITEMDATA

"Name=uploadFile", "Value=E://datafile//data01.zip", "File=yes", ENDITEM

LAST)

/ / add manual transactions. If the return value of the test transaction execution is 0, the transaction execution succeeds, otherwise the execution fails.

If (status = = 0)

Lr_end_transaction (Test, LR_PASS)

Else

Lr_end_transaction (Test, LR_FAIL)

/ / print transaction execution time.

If (trans_time)

Lr_output_message (transaction execution time:% f seconds, trans_time)

Else

Lr_output_message ("transaction execution time unknown!")

Return 0

}

The following is an example of the application of the web_submit_data function in LR's help documentation, as can be seen from this example.

Web_submit_data ("Attachments"

"Action= http://barton.cottage@.Devonshire.uk/Attachments?YY=45434",

"Method=POST"

"EncType=multipart/form-data"

"TargetFrame="

"RecContentType=text/html"

"Referer= http:///barton.cottage@.Devonshire.uk/Compose?YY=20435",

"Snapshot=t5.inf"

"Mode=HTML"

ITEMDATA

"Name=userFile0"

"Value=E://sense_sensibility//Elinor.txt"

"File=yes"

"ContentType=text/html", / / Override default "text/plain" for .txt files

ENDITEM

"Name=userFile1"

"Value=E://sense_sensibility//Marianne.jpg"

"File=yes"

ENDITEM

LAST)

(2) LoadRunner download file

Action ()

{

/ * download help documentation * /

/ / define an integer variable to save the size of the obtained file

Int flen

/ / Save file handle

Long filedes

/ / Save file path and file name

Char file [256] = "/ 0"

/ / define a random number

Char * strNumber

/ / Returns the string argument after evaluating embedded parameters.

StrNumber=lr_eval_string ("{RandomNum}")

/ / Save the path to the file variable

Strcat (file, "D://Excel//")

/ / concatenate the obtained random number after the file variable

Strcat (file,strNumber)

/ / concatenate the downloaded file suffix .rar after the file variable

Strcat (file, ".rar")

/ / so far, a LoadRunner has obtained a complete file name

/ / set the maximum length of the parameter. Note that the value must be greater than the file size.

Web_set_max_html_param_len ("20000")

/ / use the association function to obtain the contents of the downloaded file. Here, no left and right boundaries are defined, and all the contents of the server response are obtained.

Web_reg_save_param ("fcontent"

"LB="

"RB="

"SEARCH=BODY"

LAST)

/ * download help file * /

Lr_start_transaction ("download help File")

/ / send a request to download the help file

Web_url ("DownLoadServlet"

"URL= https://testserver3/servlet/DownLoadServlet?filename=help",

"Resource=1"

"RecContentType=application/x-msdownload"

"Referer="

"Snapshot=t41.inf"

LAST)

/ / get the file length in the response

Flen = web_get_int_property (HTTP_INFO_DOWNLOAD_SIZE)

If (flen > 0)

{

/ / Open the file in write mode

If ((filedes = fopen (file, "wb")) = = NULL)

{

Lr_output_message ("failed to open file!")

Return-1

}

/ / write the contents of the file

Fwrite (lr_eval_string ("{fcontent}"), flen, 1, filedes)

/ / close the file

Fclose (filedes)

}

Lr_end_transaction (download help File, LR_AUTO)

Return 0

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report