Graphical LoadRunner implementation of SOAP interface performance testing

Source: Internet
Author: User
Tags soap regular expression

I. Pre-preparation

The performance test for SOAP uses the Web Services Scripting protocol. Therefore, we should have loadrunner corresponding license. If you need to add license, add the following steps:

1. Open LoadRunner, click "Configure"-"LoadRunner license" above:

Figure 1.1

2. Click "New License" and enter the appropriate license:

Figure 1.2

Two. Create a test script

With the permission of Web services, we are ready to start creating test scripts.

1. Open LoadRunner and click "Create/Edit Script":

Figure 2.1

2. Click "New VUser Script":

Figure 2.2

3. Select "New single Script" and "Web Services" to determine:

Figure 2.3

4. Select action. Edit some action scripts for the virtual user here:

Figure 2.4

5. Enter the action script in the action method, in the following format. Web_add_header Add SOAP message header information, soap_reques to send the message body:

Figure 2.5

6. Within LR, a SOAP request message script format is as follows:

[HTML] View Plain copy print? Action ()    {   int count;      lr_start_transaction ("Onesoaporder");       web_add_header ("SOAPAction", "");      soap_request ("Stepname= Createsoaporder ",  " Url=http://192.168.101.1:8080/mysoapproj/services/soapservice ",  " Soapenvelope=<?xml version=\ "1.0\"  encoding=\ "gb2312\"?> "  " <soapenv:envelope  xmlns:soapenv=\ "http://schemas.xmlsoap.org/soap/envelope/\" > "     " <soapenv: Header> "         <Security>"             "<UsernameToken>"                 "<Username>username</Username>"                 "<Password>password</Password>"            "</UsernameToken>"          "</Security>"        "</soapenv:Header>"       "<soapenv:Body>"        "<msg:createSoapOrder>"          "<msg:SoapOrder>"              <id>987600001</id>           "</msg:businessGroup>"       "</msg:createSoapOrder>"     "</soapenv:Body></soapenv:Envelope>",   "Responseparam=response",   last);       count = lr_xml_find ("Xml={response}",   "query=/envelope/body/ Createsoaporderresponse/resultcode/value ",  " value=0 ",  " Notfound=continue ",   Last);      if (count > 0) {   lr_end_transaction ("Onesoaporder", LR_PASS ); &NBSP;&NBsp }   else{   lr_end_transaction ("Onesoaporder", Lr_fail);  }   return  0;  }  

Action () {int count;

Lr_start_transaction ("Onesoaporder");

Web_add_header ("SOAPAction", "" "); Soap_request ("Stepname=createsoaporder", "Url=http://192.168.101.1:8080/mysoapproj/services/soapservice", " Soapenvelope=<?xml version=\ "1.0\" encoding=\ "gb2312\"?> "<soapenv:envelope xmlns:soapenv=\"/http Schemas.xmlsoap.org/soap/envelope/\ ">"   "<soapenv:Header>"      "<security >        <UsernameToken>             "<Username>username</Username>"             "<Password>password</Password>"        "</usernametoken
> "    " </Security> " " </soapenv:Header> " " <soapenv:Body> "   "<msg:createSoapOrder>"      "<msg:SoapOrder>"         "<id>987600001</id>"      "</msg:businessGroup>"   "&LT;/MSG:

Createsoaporder> "</soapenv:Body></soapenv:Envelope>", "Responseparam=response", last); Count = Lr_xml_find ("Xml={response}", "Query=/envelope/body/createsoaporderresponse/resultcode/value", "Value=0", "

Notfound=continue ", last);
if (Count > 0) {lr_end_transaction ("Onesoaporder", Lr_pass),} else{lr_end_transaction ("Onesoaporder", Lr_fail);}
return 0;
 }

Here's what to note:

1) The domain name of the node in the message, preferably do not change;

2) The URL of soap needs to be modified according to the actual situation;

3) One of the parameters in a method, if it is too long and requires a newline, each line is enclosed in double quotation marks;

4) lr_start_transaction ("Onesoaporder"); method is to create a transaction named Onesoaporder. The end of the transaction is implemented by the Lr_end_sub_transaction method;

5) The "responseparam=response" parameter in the Soap_request method is to store the SOAP return message in response;

6) The Lr_xml_find method is to find the value of a specified node in the XML file. In this example, the XML file is stored in the Response SOAP response packet, and the lookup node is/envelope/body/createsoaporderresponse/resultcode/ The value node (the specific response return path should be replaced by the actual item), which is the return code. Expected result "value=0". If the method finds the expected value, it returns the number of expected values found, or 0 if it is not found;

7) Determines whether the return code is 0 (operation succeeded), based on the value of count, to determine whether the transaction was successful. (Lr_pass indicates a successful transaction; Lr_fail indicates a transaction failure);

8) This message is static, and more virtual users execute the same instruction. If you want to make the parameter "move" (such as the number of values not conflicting parameters), please continue to look down;

7. Ways to change the parameters dynamically:

7.1 Double-click the number 987600001 under the ID label, then right-select Replace with new parameter:

Figure 2.7.1

7.2 The variable can be replaced here, and the type is selected as "Unique number" to ensure that the parameter does not appear duplicate values. The original numeric parameter will also change to a variable in pink brackets:

Figure 2.7.2 (1)

Figure 2.7.2 (2)

7.3 Right-click this parameter, select parameter properties:

Figure 2.7.3

7.4 Set the value information for this parameter:

Figure 2.7.4

For the above figure, do the following instructions:
1) Number range Start (S): The first number of the starting value, the next number will be incremented on this basis.
2) per VUser: Sets the number of numbers that are available for each virtual user. In this figure, each virtual user uses 100 numbers.
3) Number display format (N): This is a regular expression. %04D represents a 6-bit number string, the number of bits is insufficient, the front is 0. The valid value range for 9876%04D is 98760000-98769999, with a total of 10,000 ID numbers.
4) In this example, each virtual user is assigned only 100 number calculations, then 9876%04D can meet the data volume usage of 100 virtual users.
5) The virtual user rules for using numbers, as an example: the first virtual user creates an ID number of 98760000-98760099, and the second virtual user ID number is 98760100-98760199. And so on
6) The data can be adjusted according to the specific performance test requirements. (because there may be other parameters besides the ID that cannot be duplicated, you can refer to the NUM parameter and set a unique variable to implement the uniqueness constraint)

8. Click the Execute button (or F5) to test if the script is correct (below is the result of execution):

Figure 2.8

9. Debug the script and save the script.

Three Run a Load test
Once the script is run, you can create a virtual user and perform a performance test.
1. Open LoadRunner and select "Run Load Test":

Figure 3.1

2. Select the script you just created and load it into the scene:

Figure 3.2

3. Select the number of virtual users you want. The maximum number of virtual users that can be set is determined by license:

Figure 3.3

4. Select the editing plan, according to the specific needs, set the "Pressure", "duration", "decompression" and other data. In general, "duration" is more commonly used:

Figure 3.4

5. Click "Runtime Settings" at the bottom right of the main interface to set the number of times each virtual user executes the script. Here, it can be understood as "per user, expected number of groups created" (This setting is set when the number of executions per virtual user needs to be set.) If you set the duration in step 4, you can set the number of iterations (the default 1 times), and the virtual user will execute the script (the variable will increment) until the specified time ends):

Figure 3.5

6. Perform the performance test:

Figure 3.6

7. Wait for the run to finish and analyze the results.

Four Results analysis
After the run is finished, click the Performance Test main Menu bar "results" and "Analysis results".

Figure 4.1

For specific data analysis methods, refer to the other LoadRunner performance analysis documentation.

Five. PostScript, some precautions

1. In the script, to delete a custom parameter, you need to go to the "parameter list", then delete, delete in the script action, it is impossible to completely delete the parameter.
2. In the script, if a parameter is referenced in multiple places, the parameter should be careful to select the parameter properties, time to update value option. There are three categories of this option: occurrence, iteration, once. When occurrence is selected, the parameter is incremented once each time, and iteration is selected, the parameter appears multiple times within a single loop, and the parameter is changed only once. Once. These choices match the action of the Parameter property "when the value is exceeded" to select the next action.
3. When the LR script is created, it defaults to one transaction for each action, so that a transaction is defined for itself, but there are many more transactions after execution. This setting needs to be based on the specific scripting needs to decide whether to use the item (in this case, it is not required). "VUser"--"Runtime Settings" and "other", "each action is defined as a transaction (D)" This check box controls.

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.