Parameterization of scripts

Source: Internet
Author: User

 

First, why should we parameterize the script?

A) To reduce the script size and number, we can reduce the number of scripts by parameterization,

Without parameterization, we may need to copy and modify many scripts to achieve the goal.

B) make the business closer to the real customer's business. Each virtual user uses different parameter values to simulate

This approach is close to the customer's actual situation.

 

Second, how to parameterize

 

A) edit the script and use parameters instead of constants;

 

 

B) set parameters and data sources;

So how to parameterize it? Right-click the content to be parameterized and choose replace with a parameter (for example ). Enter the parameter name, which is assumed to be password.

At this time, we should note that when the parameterization is complete

There are two more parameterized files, that is, the text file after the two numbers are parameterized. Of course, in general, we should not place this parameterized file under the script directory, instead, it should be placed under a special file to ensure that the parameterized file is separated from the script. For example, we create a folder named parameter and put all parameterized text files in this folder.

 

So what should we do when there are a lot of parameterized files, because when a project is very large, there are many recording services, there will be a lot of parameterized files, or even a few hundred MB, in this case, to facilitate the management of parameterized files and save space, we will merge the parameterized files into a folder. For example, the preceding two parameterized files can be merged and separated by commas, for example, after merging the parameterized files.

 

 

 

Let's take a look at the parameterized properties:

A) parameter type attributes:

1. "date/time" (date/time) parameter type:

The "date/time" type replaces the parameter with the current date and/or time. To specify the date/time format, you can select from the menu list or specify the actual format. The format should be

Corresponds to the date/time format recorded in the script. You can also click the corresponding

Button to add, delete, or restore the format,

 

2. "group name" (group name) parameter type:

Replace the parameter with the name of the vuser group. When creating a solution, you must specify the name of the vuser group. No

When the vugen script is run, the group name is always "NONE ". However, when running vugen

The name will be none.

 

3. "iteration number" parameter type: Replace the parameter with the current iteration number.

4. "load generator name" (Server Load balancer name) parameter type: negative value of the vuser script

Load generator name replacement parameter. The server Load balancer is the computer that runs the vuser.

5. "random number" (Random Number) parameter type: replace with a random integer.

Parameter. You can set the range of random numbers by specifying the minimum and maximum values.

6. "unique number" (unique number) parameter type: Replace the parameter with a unique number. "Block

Size indicates the size of the number block allocated to each vuser. Every vuser

The parameter value increases progressively at each iteration starting from the lower limit (start) of its range.

 

7. "vuser ID" parameter type: LoadRunner uses the virtual user ID to replace the parameter value,

This ID is controlled by the Controller. When running the script in vugen, vugen will be-1.

8. file parameter type: You can edit the parameter file in the parameter attribute or edit the parameter directly.

Data files are selected by path and extracted from existing databases. This is the most common parameter type of parameterization.

B) Browse attributes:

This is used to select the path of the parameter file. A problem that needs to be noted here is that we are generally doing

Parameter files are not separately placed in a folder during parameterization.

But as we have already mentioned above, the parameterized file is usually merged into a file and put

A folder dedicated to parameter Management ensures that the parameterized file is separated from the script, so we need to select

Parameter path. Otherwise, the parameters in the parameter file cannot be read, as shown in.

 

 

 

After selection, all the parameters in the parameterized file are listed, such:

 

 

 

 

 

Note: readers may find that if we copy this script to another machine,

Is there an error in this path? That is to say, our scripts are not portable.

The absolute path is written here. If it is switched to another disk or machine, an error will be reported during running. How can this problem be solved?

Solve this problem? Here we use relative paths to solve this problem. This is our browse setting

Set it to a relative path and use "." To replace the root directory of the script.

 

C) data import method:

LoadRunner allows you to use Microsoft query or specify the database connection string and SQL language.

Use parameterization to import data from an existing database. Here the two data import methods

The difference is that when Microsoft query is used, do not create a new data source, which is directly connected during the import wizard.

To connect to the database, but to manually specify the database character server, you must first prepare the data source. Currently, this type

Method.

 

D) Select next now attributes:

Note: All select next now attributes are selected for virtual users.

That is, the policy is set for the Controller. It cannot be seen during script debugging.

It determines how the virtual user selects parameters.

Sequential: the virtual user vuser reads data in the parameter file in the row order,

If the parameter file does not have enough data, the first value is returned and the loop ends until the end.

Random: Each vuser randomly reads parameter data from the table.

Unique: the unique number, that is, the parameters obtained by each vuser are inconsistent. Here, the differences between users are emphasized.

Same link as ***: if multiple parameters are defined in a script

This is the corresponding relationship. For example, the username and password are the corresponding relationship, that is, the password should always be used

This option is required when the account name is matched.

E) Update value on attributes:

Note: The policy set here is for script iteration, that is, all the policies here

It only plays a role in the number of script iterations, but does not affect vuser selection parameters.

Each iteration: each iteration of the script accesses the next value in the data table.

Note: If a parameter is used multiple times during an iteration, in this example,

Two user names and passwords are used in one iteration. The same data is used for the two iterations, instead of the two

Data.

Each occurrence: The parameter value is updated during each iteration.

 

Note: If a parameter appears multiple times during an iteration

Also need to be updated

 

Once: The same parameter is directly obtained in the same vuser. The data in the table is not involved in the iteration.

Process.

 

 

 

 

The parameterization process has been completed. Here, we will summarize the parameters that should be noted during the parameterization process.

Problem:

1) parameter files should be as few as possible, because the parameters are stored in the memory and occupy the memory resources;

2) Separation of parameterized files and scripts;

3) the path of the parameter file should be relative;

4) In some cases, parameters should be obtained from the database to make them more authentic;

5) Select the parameter type;

6) parameter data is generally determined by the business

 

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.