Just according to the interface document, you can easily develop scripts for get and post requests, can you do it?

The content described in the general interface document:

Develop scripts for get requests, the description of the interface document is as follows:

Create an empty script inside loadrunner:

In the action blank, click insert—>step

Enter web_custom_request, double-click to select the function, and fill in the following parameter values:

The generated script is as follows:

Run the compilation to see if there are any syntax errors:

In the log, you can see that code=0 is returned, indicating that the interface request is successful. Don’t pay attention to the returned garbled information here.

Do you think the script of the get request is easy to handle, and the next step is to look at the post request, or use the above function to complete it.

Use the post request to develop the script of the login interface: the document description is as follows, and there are few parameters.

Fill in the following values:

The generated script content is as follows:

Compile and run the script and see the log information: the log level needs to be adjusted to the following level

The scripts have been successfully developed, so is there a problem? When running the scene, how do I know that my script has always been successful?

Is it true that when some friends run the script normally, the script does not report an error, but the actual data inserted into the database does not increase?

This problem must have been encountered by many friends, so what should I do?

It is necessary to make an if judgment on the return value of the script. When it succeeds, it will pass, and if it fails, it will fail. In this way, the transaction will automatically count success or failure

  • First add the transaction to the script

start business

end business

  • How to write if judgment?

Go back to the log that was played back just now, use the associated method mentioned before, double-click the line code=0

web_reg_save_param("code", //The name of the variable

"LB=\"code\":", //Left boundary value, double quotes need to be escaped

"RB=,", //Right boundary value

"Ord=1", // When there are multiple values, take the number

LAST);

Here is another method to teach you, enter the help file of loadrunner, check the use of each function, loadrunner interface, press F1 on the keyboard, and enter the function name in the input box, such as atoi

When there are multiple examples, choose the C language for the HTTP protocol

The judgment is as follows:

// write if judgment

// int atoi (characters that need to be converted into integers); // convert the specified characters into integers

// char *lr_eval_string(the name of the parameter you want to get currently); // Get the value of the specified current parameter

if(atoi(lr_eval_string("{code}"))==0) { //When code=0, the transaction is successful

lr_end_transaction("login", LR_PASS);

} else { //When code is not equal to 0, the transaction fails

lr_end_transaction("login", LR_FAIL);

} Run the script, you can see the pass information in the log

Summarize

At present, I have learned several commonly used request functions, and their functions are as follows:

  • Web_url: can only be used for get requests
  • Web_submit_data: get, post, submit form form
  • Web_custom_request: It can be used for get or post request, and the post request is a standard json string

Finally: In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free【保证100%免费】

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

Guess you like

Origin blog.csdn.net/IT_LanTian/article/details/131555203