LoadRunner login function test instance

Source: Internet
Author: User

The original Article is transferred from http://blog.163.com/venus-yhj/blog/static/95688270200962991810982.

Learning LR recording Web login script is very useful.

It may be useful to other beginners.

 

 

In this article, I will introduce several functions of LoadRunner for transaction operations, and use an example to explain how to determine whether transactions in LoadRunner are successful, it also describes how to determine whether the script is successfully executed during script execution.

1. Ask a question first. Let's continue with the question.

Record a login script and parameterize the login user and password so that the first two usernames are correct and the third username is incorrect. Set the script to iterate three times, log On with the first, second, and third users respectively. At this time, a transaction tr_login is added to the login commit operation in the script. Now, the question is raised: when running the script

If the first user logs on successfully, is the transaction tr_login successful?

The second user logs on successfully. Is the transaction tr_login successful?

The third user fails to log on. Is the transaction tr_login successful?

The answer is: tr_login transactions are successfully executed three times.

Someone may ask, why is the transaction successful when the login fails? Let's take a look at the following example. I believe the answer will be obtained after the example is completed!

In this example, we recorded the mercurywebtours provided by LoadRunner.

The recording method is not described here. The script after the recording is complete and the user name and password are parameterized is as follows: (the third user name is incorrect during parameterization)

ActIon ()
{
Double trans_time;
Int status;

Web_url ("mercurywebtours ",
"Url = http: // 127.0.0.1: 1080/mercurywebtours /",
"Resource = 0 ",
"Reccontenttype = text/html ",
"Referer = ",
"Snapshot = t1.inf ",
"Mode = html ",
Last );
Lr_start_transaction ("tr_login ");
Trans_time = lr_get_transaction_duration ("tr_login ");

// Lr_get_transaction_duration: the time consumed by the transaction execution.
Web_reg_find ("text = error ",
"Savecount = login_count", last );

// The web_reg_find function can find the content in the corresponding range, similar to the checkpoint, but this function is returned by web_find with one more parameter, that is, the value of savecount can record the number of specified content in the specified range. In this example, we use this value to determine whether the user is successfully logged on.

// Note: After login fails, the login page will have an "error" string. Therefore, we believe that if this string is displayed, it indicates that the login fails and this condition determines whether the login is successful or fails, depends on the specific project, depending on the actual situation

Status = web_submit_form ("login. pl ",
"Snapshot = t2.inf ",
Itemdata,
"Name = username", "value = {name}", Enditem,
"Name = password", "value = {password}", Enditem,
"Name = login. X", "value = 51", Enditem,
"Name = login. Y", "value = 12", Enditem,
Last );

// The result of web_submit_form function execution is assigned to the status variable. If the result is successful, 0 is returned. If the result is unsuccessful, the number greater than 0 is returned.

If (status = 0) // If successful

Lr_end_transaction ("tr_login", lr_pass); // if the submission is successful, set the transaction status to pass
Else
Lr_end_transaction ("tr_login", lr_fail); // if the submission fails, set the transaction status to fail.

If (trans_time) // if the transaction consumes time to output the time
Lr_output_message ("tr_login transaction time % F seconds", trans_time );
Else // if the transaction does not consume time, the output time is uncertain.

Lr_output_message ("the duration cannot be determined .");

If (atoi (lr_evAl_string ("{login_count}")> 0 ){

// If the "error" string is found on the login page, we think the login fails.
Lr_error_message ("Login Failed ");
}
Else {

// Otherwise, the logon is successful.

Lr_output_message ("Login successful .");

Return (0 );

}
Return 0;
}

Okay,

Run this script and the result is:

During the first iteration: (only some key logs are pasted here)

ActIon. C (15): Policy: transaction "tr_login" started.
ActIon. C (17): Registering web_reg_find was successful [msgid: MMSG-26390]
ActIon. C (20): Policy: parameter substitution: parameter "name" = "huruihai"
ActIon. C (20): Policy: parameter substitution: parameter "password" = "huruihai"
ActIon. C (20): Registered web_reg_find successful for "text = error" [msgid: MMSG-26362]
ActIon. C (20): Saving Y: Saving parameter "login_count = 0"
ActIon. C (20): web_submit_form ("login. pl") was successful, 32673 body bytes, 1652 header bytes [msgid: MMSG-26386]
ActIon. C (30): Condition Y: transaction "tr_login" ended with "pass" status
ActIon. C (35): the login transaction takes 0.002523 seconds.
ActIon. C (39): Policy: parameter substitution: parameter "login_count" = "0"
ActIon. C (44): Login successful.
The second iteration:

ActIon. C (15): Policy: transaction "tr_login" started.
ActIon. C (17): Registering web_reg_find was successful [msgid: MMSG-26390]
ActIon. C (20): Policy: parameter substitution: parameter "name" = "wangjin"
ActIon. C (20): Policy: parameter substitution: parameter "password" = "wangjin"
ActIon. C (20): Registered web_reg_find successful for "text = error" [msgid: MMSG-26362]
ActIon. C (20): Saving Y: Saving parameter "login_count = 0"
ActIon. C (20): web_submit_form ("login. pl") was successful, 32673 body bytes, 1652 header bytes [msgid: MMSG-26386]
ActIon. C (30): Condition Y: transaction "tr_login" ended with "pass" status
ActIon. C (35): the login transaction takes 0.006644 seconds.
ActIon. C (39): Policy: parameter substitution: parameter "login_count" = "0"
ActIon. C (44): Login successful.

The third iteration:

ActIon. C (15): Policy: transaction "tr_login" started.
ActIon. C (17): Registering web_reg_find was successful [msgid: MMSG-26390]
ActIon. C (20): Policy: parameter substitution: parameter "name" = "errorname"
ActIon. C (20): Policy: parameter substitution: parameter "password" = "errorpd"
ActIon. C (20): Registered web_reg_find successful for "text = error" (COUNT = 3) [msgid: MMSG-26364]
ActIon. C (20): Saving Y: Saving parameter "login_count = 3"
ActIon. C (20): web_submit_form ("login. pl") was successful, 29263 body bytes, 821 header bytes [msgid: MMSG-26386]
ActIon. C (30): Condition Y: transaction "tr_login" ended with "pass" status (duration: 0.6840 wasted time: 0.0010 ).
ActIon. C (35): the login transaction takes 0.005852 seconds.
ActIon. C (39): Policy: parameter substitution: parameter "login_count" = "3"
ActIon. C (40): Error: Login Failed

Ending ActIon ActIon.

As you can see, the transaction execution result is always successful, but the last login failed.

I parameterized the request address submitted in the last transaction incorrectly. The result is that the transaction failed to be executed.

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.