LoadRunner- Summary (I)

directory

  • 1. Common functions of scripts

  • 2. Script assertion methods

  • 3. Batch execution scripts

  • 4. Use the function to generate order numbers


1. Common functions of scripts

web_url()

The basic syntax for simulating a user request is as follows:

Web_url (" name displayed in test results ", "URL= hyperlink address to access ", LAST);Copy the code

web_link()

Simulate a user clicking on a hyperlink. VuGen identifies how many hyperlinks are in the HTML body returned by the server after visiting the page. When using the web_link() function, VuGen will automatically find and access the URL on the page that the link name points to, as long as you write the correct link name.

The basic syntax is as follows:

Web_link (" Name displayed in test results ", "TEXT= name of hyperlink to click ", Ord= order, LAST);Copy the code

Web_submit_form (), web_submit_data ()

Implement the POST method in HTTP requests

lr_convert_string_encoding()

To change Chinese to UTF-8 format, the code would look like this:

` lr_convert_string_encoding (` ` "portal", ` ` LR_ENC_SYSTEM_LOCALE, ` ` LR_ENC_UTF8, ` ` "param"); `Copy the code

web_convert_param()

Converts the format of the argument HTML from HTML to URL mode

web_convert_param("HTML","SourceEncoding=HTML","TargetEncoding=URL",LAST);
Copy the code

web_custom_request()

Customize HTTP request rules

lr_output_message()

Contents of the output

lr_set_debug_message()

The log display function manually controls the log display

The format of this function is lr_set_debug_message(log format, whether to apply)

` lr_set_debug_message (16 | 4, 1) mandatory set log is enabled, And is extended log parameter selection show ` ` lr_set_debug_message (0, 1) mandatory set log off ` ` lr_set_debug_message | 2 (1, 1) mandatory set log is enabled, only to see ` basic contentCopy the code

lr_think_time()

Wait for the operating

Lr_eval_string (“{parameter name}”);

Gets the corresponding value from the parameter and converts it to a string

lr_save_string()

Saves a string as a parameter

lr_save_string("https://www.baidu.com","website");
Copy the code

lr_free_parameter()

The value of the argument is released

web_reg_save_param_ex()

associated

web_reg_save_param_regexp

Regular expression association

web_set_max_html_param_len

You can customize the maximum length of the parameter to store the associated return value

web_set_max_html_param_len("9999999");
Copy the code

web_add_auto_filter

filter

web_add_filter

filter

web_add_auto_header

Add headers

web_add_header

Add headers

web_add_cookie

Add a cookie

web_add_cookie_ex

Add a cookie

web_browser

Mock browser

web_button

Simulation button

web_cache_cleanup

Clear the cache

web_check_box

Some box

web_cleanup_auto_header

Clear request headers

web_cleanup_cookies

To clear the cookies

web_concurrent_start&end

Requests in parallel

web_convert_data_param

Time transformation

web_convert_from_formatted

Format conversion

web_convert_to_formatted

Format conversion

2. Script assertion methods

msg = "AllTests" if (strstr(lr_eval_string("{msg}"), 'AllTests') ! =NULL){lr_end_transaction(" transaction ", LR_PASS) lr_output_message(" success ")} else{lr_end_transaction(" transaction ", LR_FAIL) lr_output_message(" failed ")}Copy the code

3. Batch execution scripts

Write batch files and execute scripts with Windows built-in task plan

(1) Write commands in notepad to specify the path of bin and scenario to be executed:

cls SET M_ROOT="C:\Program Files\Mercury\LoadRunner\bin\" %M_ROOT%\wlrun.exe -TestPath "C:\Program Files\Mercury\LoadRunner\scenario\Scenario1_whole_new2.lrs" -Run
Copy the code

(2) Save the file in. Bat format.

(3) Start Task Schedule in Control Panel > Administrative Tools > Services.

(4) Go to the control panel -> Task Plan, add a new scheduled task, by browsing, add the batch file, and specify the execution time.

(5) Note that the saving path of the Result is set in Result Setting, because Scenario will be automatically closed after the execution of the scheduled task is completed.

Bat file contents:

cls
SET M_ROOT="D:\Program Files\MI\Mercury LoadRunner\bin\"
%M_ROOT%\wlrun.exe -TestPath "D:\Program Files\MI\Mercury LoadRunner\scenario\Test\TestScen_1.lrs" -Run
%M_ROOT%\wlrun.exe -TestPath "D:\Program Files\MI\Mercury LoadRunner\scenario\Test\TestScen_2.lrs" -Run
%M_ROOT%\wlrun.exe -TestPath "D:\Program Files\MI\Mercury LoadRunner\scenario\Test\TestScen_3.lrs" -Run
Copy the code

4. Use the function to generate order numbers

LoadRunner takes time function and generates order number with time function

Question raising:

(1) Set the system time

(2) It takes time to generate a unique order number

(3) Time function plus random number to generate non-repeating order number

1. Take system time:

Action() {lr_save_dateTime (" now: %Y year %m month %d day %H hour %m minute %S second ", DATE_NOW, "pNextWeek_date"); lr_output_message("%s", lr_eval_string("{pNextWeek_date}")); Lr_save_datetime (" this time next week is: % % % % Y/m/d/H: % m: % S ", DATE_NOW + (ONE_DAY * 7), "pNextWeek_date"); lr_output_message("%s", lr_eval_string("{pNextWeek_date}")); lr_save_datetime("%Y%m%d%H%M%S", DATE_NOW, "pNextWeek_date"); Lr_output_message (" generate order number: %s with time function ", lr_eval_string("{pNextWeek_date}")); return 0; }Copy the code

Second, time function plus random number to generate a non-repeating order number

int i; char OrderId[20]; Action() { srand(time(NULL)); i=rand()%10; lr_save_datetime("%Y%m%d%H%M%S", DATE_NOW,"now"); sprintf(OrderId,"%s%d",lr_eval_string("{now}"),i); Lr_output_message (" Order number: %s",OrderId); return 0; }Copy the code

AllTests software tests

Share software testing, automated testing, performance testing, test development and other technical articles and resources, welcome to pay attention to!