LoadRunner HTTP Interface Test Script instance

Source: Internet
Author: User

LoadRunner HTTP Interface Test Script instance

The principle of the interface test is to simulate the client to send the request message to the server through the test program, the server receives the request message and then sends the reply message to the client, the client receives the response message result and the expected result to compare the process, the interface test can send HTTP through Java Post or GET request to implement, can also be implemented by LoadRunner, today introduces the next LoadRunner interface Automation Test Example:

The LoadRunner interface test principle is that the Web_submit_data function sends a post or GET request, parameterize the test case data, use correlation to get the result value of the response, match the expected result, and save the relevant parameters in the process to the HTML file. In order to realize the interface automation, the implementation code is as follows:

1, init part: Generate HTML format file, filename is called Test _ system Time (%y%m%d%h%m%s) _ Virtual user number, and write to test result file HTML start identity

Defining result file variables

Long file;

Define a virtual user number variable

Char *vusernum;

Defining test Result variables

Char v_result[1024];

Vuser_init ()

{

Get the virtual user number

Vusernum=lr_eval_string ("_{vuserid}");

Get system time

Lr_save_datetime ("%y%m%d%h%m%s", Date_now, "now_date");

Stitching test Result file name

strcpy (V_result, "d://test/result/test");

strcat (V_result,lr_eval_string ("_{now_date}"));

strcat (V_result,vusernum);

strcat (V_result, ". html");

Build and open the test results file

File=fopen (V_result, "at+");

Write the test file header HTML information

strcpy (V_result, "

Fputs (V_result,file);

return 0;

}

2. Action part: Read the test parameters and expected results from the parameterized file, send the request and get the actual results from the server, compare the test results and write the test results file.

Action ()

{

Test result text

Char v_testres[1024];

Defines whether the returned result is the correct variable

int result;

Get IMSI number

Char *v_imsi=lr_eval_string ("{IMSI}");

Sets the maximum number of bytes the page receives, which should be greater than the size of the server's return content

Web_set_max_html_param_len ("20000");

Get Server return content

Web_reg_save_param ("Filecontent",

"Lb=",

"Rb=",

"Search=body",

last);

Send Request

Web_submit_data ("Login",

"Action=http://host:port/autonavit/search?cmd=clientlogin&termver=5&termcode=30001&termdbver=3",

"Method=post",

"Reccontenttype=text/html",

"Referer=",

"Snapshot=t9.inf",

"Mode=http",

ItemData,

"Name=imsi", "Value={imsi}", Enditem,

last);

Compare expected and actual values for equality

RESULT=STRCMP (Lr_eval_string ("{YQJG}"), Lr_eval_string ("{filecontent}");

if (result = = 0)

{

strcpy (V_testres, "through");

}

Else

{

strcpy (V_testres, "failure");

}

strcpy (V_result, "<tr><td>");

Write test parameters

strcat (V_result,v_imsi);

strcat (V_result, "</td>");

strcat (V_result, "<td id= ' Yq ' >");

Write expected results

strcat (V_result,lr_eval_string ("{YQJG}"));

strcat (V_result, "</td>");

strcat (V_result, "<td id= ' sj ' >");

Write actual results

strcat (V_result,lr_eval_string ("{filecontent}"));

strcat (V_result, "</td>");

strcat (V_result, "<td>");

Whether the write test passes

strcat (V_result, v_testres);

strcat (V_result, "</td></tr>");

Fputs (V_result,file);

return 0;

}

3, End part: Write the end HTML information of the test result file, close the file and finish the test.

Vuser_end ()

{

End and close the file

strcpy (V_result, "</table>

Fputs (V_result,file);

fclose (file);

return 0;

}

LoadRunner HTTP Interface Test Script instance

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.