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

Development of loadrunner Virtual user script (1)

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

Share

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

1. Loadrunner virtual user development-detailed analysis of variables

Definition of variables

Local and global variables

1. The variables defined in init action end are local variables.

2. Variables defined in gloabal are global variables

3. When will the global variable be defined?

Fixed throughout the process, such as url address, KEY others, need to be defined as global variables.

Simple example:

In action, define a variable a, assign a value of 10, and then print a, and you can see that the result prints out 10. 0.

As you can see, when printing in LR, you only need to use the LR function lr_output_message, and the C language function printf does not work.

In C language, you can define variables when you use them, but in LR, you need to define them at the beginning, not in the middle.

Variables defined inside the vuser_init\ vuser_action\ vuser_ end function are local variables and can only be used within that function.

For example, if a variable is defined in action and an is printed in vuser_end, an error occurs during compilation and the defined an is not found.

To define a global variable, you need to define it in the function globals.h.

The following defines the variable p in globals.h, and then invokes the variable in init and end to get memory, and the playback result is normal.

II. LR virtual user script development-common syntax and misunderstandings in use

1. The use of pointers

The following is an example of a script and its interpretation:

The running result is as follows, and the result prints out An and loadrunner

2. The usage of array

Example 1:

In the print result, why not p=ABCDE instead of pumped ABCDELoadrunner? This is because in LR or C, when does it end when a pointer is printed as a string? when it encounters\ 0, this is the syntax of C. The result of P prints from A, and then to E, and then continues to print Loadrunnerprinted characters. In C language, there is a default\ 0 after the string, so after printing the string Loadrunnerprinted letters! It's over.

Example 2:

See the above example of counting the length of a string. For the string "Loadrunner benchmark!", why does sizeof get a length of 14, and Strlen gets 13? Because sizeof counts the default\ 0, while strlen does not.

Example 3:

Why is the output here abcdea instead of abcde? Because the length defined by the array is 5, and the string abcde is followed by the default\ 0, plus this is the length of 6, which is too long, so\ 0 is discarded. After printing the abcde, we continue to print a.

Example 4:

If you change the length of the array to 6, the output will be abcde

What to pay attention to:

1) pay attention to the semicolons in Chinese

2) initialize variables as much as possible before they are used

3) use character arrays as little as possible

4) when using an array, make sure the array is long enough.

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