LoadRunner simulating JSON requests

Source: Internet
Author: User

One, LoadRunner script creation

1.insert-new Step-Choose Custom Request-web_custom_request

2. Fill in the corresponding parameters

3. Generate the script and modify it as follows (the quotation mark in the argument "requires a slash \ Translation before")

Action ()
{
Lr_start_transaction ("Sendorder");
Web_reg_find ("Search=body",
"Savecount=sendorder_count",
"Text=ord_sn",
last);
Web_custom_request ("sendorder.html",
"Url=http://192.168.1.205:9000/default/com.bybon.o2o.services.apiservice.getapiservicemgr.getapiservice.api",
"Method=post",
"Resource=0",
"Reccontenttype=text/html",
"Referer=http://192.168.1.205:9000/default/com.bybon.o2o.services.apiservice.getapiservicemgr.getapiservice.api",
"Snapshot=t229.inf",
"Mode=http",
"Enctype=application/json",
"Body={\" sign\ ": \" 963a8d91fab997a490918ebbfe71cba5\ ", \" param\ ": \"%7b%22ord_sn%22%3a%22%22%2c%22serve_type%22% 3a%221%22%2c%22ord_platform%22%3a%22pcf%22%2c%22ord_src%22%3a%221%22%2c%22mem_id%22%3a%221905%22%2c%22wx_field %22%3a%22%22%2c%22mem_name%22%3a%2218551625706%22%2c%22zipcode%22%3a%22%22%2c%22postscript%22%3a%22%5cu7559% 5cu8a00%22%2c%22tel%22%3a%2218551625706%22%2c%22email%22%3a%22%22%2c%22storecode%22%3a%22a042%22%2c%22sn%22%3a %22%22%2c%22imei%22%3a%22%22%2c%22phone_modelcode%22%3a%22080111%22%2c%22phone_color%22%3a%221%22%2c%22phone_ Volume%22%3a%222%22%2c%22suggest_scheme_code%22%3a%22080111.1.2.14.1%22%2c%22addresslist%22%3a%5b%7b%22addr_ Type%22%3a%224%22%2c%22province%22%3a%222%22%2c%22city%22%3a%2252%22%2c%22district%22%3a%22506%22%2c%22address %22%3a%22test%22%2c%22zipcode%22%3a%22%22%2c%22tel%22%3a%2218551625706%22%2c%22user_name%22%3a%22%5cu6d4b% 5cu8bd5%22%7d%5d%2c%22remark%22%3a%22%22%2c%22offerlist%22%3a%22%22%2c%22appoint_stime%22%3a%222015-06-01+17% 3a00%3a00%22%2c%22appoint_etime%22%3a%222015-06-01+19%3a00%3a00%22%2c%22bill_receiver_name%22%3a%22%22%2c%22bill_tel%22%3a%22%22%2c %22bill_province_name%22%3a%22%22%2c%22bill_city_name%22%3a%22%22%2c%22bill_area_name%22%3a%22%22%2c%22bill_ Address%22%3a%22%22%2c%22bill_title%22%3a%22%22%2c%22bill_company_name%22%3a%22%22%2c%22cnfdet_flag%22%3a2%7d\ ", \" svccode\ ": \" ec013\ ", \" msgsrc\ ": \" Sdfphp\ "}",
last);
if (strcmp (lr_eval_string ("{sendorder_count}"), "0") = = 0)
{
Lr_end_transaction ("Sendorder", Lr_fail);
return 0;
}
Else
{
Lr_end_transaction ("Sendorder", Lr_pass);
}
return 0;
}

4. Capturing page return values

Return format {"code": "0", "MSG": "%e6%88%90%e5%8a%9f", "data": {"ORD_SN": "9000003486"}}

Move the cursor to the top of the script and insert the associated point insert-new step-service-web_reg_save_param

At the top of the script, insert and modify the script as follows

Web_reg_save_param ("User_tags",

"lb=ord_sn\": \ "",

"Rb=\"]} ",

last);

At the end of the script, join the output log to verify success

Lr_message ("user_tags:%s", Lr_eval_string ("{user_tags}"));

5. Do an automated functional test of our interface, write the verification script as follows:

if (Atoi (lr_eval_string ("{user_tags}")) ==0)

Lr_output_message ("user_tags:%s,succeed!", (Lr_eval_string ("{user_tags}"));

else if (Atoi (lr_eval_string ("{user_tags}")) ==1)

Lr_output_message ("user_tags:%s,failed!", (Lr_eval_string ("{user_tags}"));

Else

Lr_output_message ("user_tags:%s,unknow!", (Lr_eval_string ("{user_tags}"));

6. Parameterized scripts

Run the script

---------------------------------------END---------------------------------------

Ii. differences between Web_custom_request and Web_submit_data

The Web_custom_request method can send post and get type requests;

Web_submit_data can only send a post-type request;

All requests sent by the Web_submit_data method can be implemented using Web_custom_request

Web_custom_request can implement requests that web_submit_data cannot implement, such as "query all messages and delete" In this case, we use associations to fetch the identity of all messages into an array when queried, if you use Web_submit_ Data to complete this delete request, it takes a lot of Web_submit_data requests to complete, but the use of web_custom_request can be done by a request, the method is to write their own code to spell a web_custom_request The body value of the method post request.

1. Web_submit_data

Data format submitted in Request: "Name= property name,", "Value= property value"

For example:

"Name=username″," Value=12044″, Enditem,

"Name=password″," Value=123456″, Enditem,

"Name=typeid″," Value=1″, Enditem,

If a property that you want to commit contains multiple values (such as bulk deletion), a single web_submit_data cannot be processed and can only be handled by multiple web_submit_data.

2. Web_custom_request

Submitted data (body) format: "Body= Property name = property Value & Property Name = property value & ..."

The following is a typical web_submit_data and web_custom_request request, and you can see that the data submitted in Web_custom_request (body) exists in this way, as follows:

Web_submit_data ("Searchrecvorgsname",
"Action=http://{url}/searchrecvorgsname",
"Method=post",
"Targetframe=",
"Reccontenttype=text/html",
"Referer=http://{url}/login_wj;jsessionid={jsessionid}",
"Snapshot=t18.inf",
"Mode=html",
ItemData,
"Name=orgsid", "Value={orgsid}", Enditem,
"Name=code", "Value={order_end_station_code}", Enditem,
last);

Web_custom_request ("Searchvehiclepopup",
"Url=http://{url}/searchvehiclepopup",
"Method=post",
"Targetframe=",
"Resource=0",
"Reccontenttype=text/html",
"Referer=http://{url}/login_wanjia;jsessionid={jsessionid}",
"Snapshot=t19.inf",
"Mode=html",
"Enctype=application/x-www-form-urlencoded; Charset=utf-8 ",
"Body=&orgsid={orgsid}&order_start_station_id={order_start_station_id}&targetcode=order_truck_no &targetname=order_truck_name&targetid=order_truck_id ",
last);

The POST request in both cases is recorded by LoadRunner as Web_custom_request:

1. Requests for bulk submissions of multiple data with the same attribute name mentioned above
2. Header Property x-requested-by A POST request with a value of XMLHttpRequest

One of the two ways to implement the request is to note that the property value in the body in web_custom_request must be URL-encoded if it contains some special characters, or the Web server will return a 500 error. A typical example is if the body contains special characters such as "=" in Viewstate,viewstate, which must be encoded by URL at this time, and an encoding conversion function is provided in Loadruner:

Web_convert_param ("Vs1″," sourceencoding=html "," Targetencoding=url ", last);

3. Web_custom_request function Explanation

A. Syntax:

int web_custom_request (const char *requestname,
[Extrares,,] last);

B. Return value: Return Lr_pass (0) represents success, Lr_fail (1) represents failure.

C. Parameters:

(1) requestname: The name of the step, the name that is displayed in the tree view in Vugen.

(2) List of Attribute: property lists, supported by the following types of properties:

A.URL: page address.

B.method: How the page is submitted, post or get.

C.targetframe: The name of the frame where the current link or resource resides.

In addition to the frame's name, you can specify the following parameters:

_blank: Open an empty window.

_parent: Replace the newly changed frame with its ancestor.

_self: Replaces the newly changed frame.

_top: Replaces the entire page.

D.enctype: Encoding type.

Reference: http://blog.sina.com.cn/s/blog_6db2c206010133kn.html

LoadRunner simulating JSON requests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.