1 Association and Interceptance of Response Content
In the full process test, the association and interception of the response content will often be involved, mainly involving the following two scenarios:
Ø Getsessionor cookie information as a dependency condition for subsequent requests.
For example, in the case of submitting an order, if you want to simulate an online user submitting an order, the corresponding cookie must contain the corresponding status information. This part of the status information needs to be intercepted from the server response and sent to the server in subsequent requests.
In LR, web_reg_save_param_ex can meet most commonly used content interception scenarios. It is required to call the API before the request, and enter the left and right boundaries to enter the content that needs to be intercepted into an LR parameter.
Other association APIs are as follows, and the basic usage methods are the same. The main difference is that some specific response content structures require some more flexible interception rules to extract the required content, such as regular expressions and Xpath, etc.
Ø Get the traffic flow output of the previous operation as the input for the checkpoint or next operation
Some more special scenarios may not be solved by a single API, and it is necessary to combine the string function provided by C.
For example, the data returned by the most common work number query interface of Huawei IT system below sometimes includes work number and sometimes includes work number and name.
In a certain test scenario, all work numbers need to be extracted. At this time, the general left and right boundary relationships may not be processed. Please refer to the following method.
The interception results are as follows
It should be noted that the formatted output of the sscanf function is %d, which only corresponds to general shaping. If the corresponding shaping number is too long (long shaping), it may be necessary to use other formats such as %ld, otherwise the intercepted number will be incorrect. This is where bugs are prone to occur. Using the string processing function that comes with C can be used for more flexible scenarios, but the relative scripts will be a little more complicated. For the complete API, please refer to the list below.
2 Time and date in the business process
In many scenarios, the time and date in the test script need to be modified, such as date-related operations in the business process, cache tags for some resources, etc.
Ø Increment of date
Assuming that the request parameters of a certain business involve a date, this date cannot be repeated. When there are fewer request parameters, you can simply +1. However, if you need more request parameters, you cannot use a method like lr_param_increment due to the special date, you can use lr_save_datetime for processing.
Although the API document does not specify how to transfer parameters by day increment, according to the definition of the API, it can be seen that the second parameter offset is used to control the increment time. The test script can refer to this definition to flexibly construct date parameters.
Ø Generate default timestamp
web_save_timestamp_param("tStamp", LAST );
Save to tStamp parameter.
Ø Generate a time stamp for the specified format
If these samples cannot match the test requirements, you can refer to other time-related APIs to modify the test scripts yourself.
3 Cache and session status loading
Tests in many business scenarios are performed under the premise of caching and session state. A typical scenario is that the user needs to log in to perform certain business operations such as placing an order. Therefore, the test script generally records the login and then performs subsequent business operations.
This method has some disadvantages, such as my test purpose is not to log in but to place an order, because some login modulesperformanceThe defect will cause the return session status to be slow, etc.
Utilize web_dump_cache and web_load_cache, you can skip the login module and directly conduct stress testing of the service under test without expiration of the session state.
It should be noted that the status information in the loaded cache must exist on the server side, otherwise the script will fail to run. Therefore, the session timeout time of the application server will generally be appropriately extended to match the use of this API.
4 Encryption and decryption signature
Here we mainly take the RSA algorithm as an example. The RSA signature of the request parameters is involved in the PTS payment interface test (note that signature and encryption are not exactly the same thing), and the concept of signature may be involved in all business scenarios that require evading the possible counterfeiting requests.
The business model for signature is as follows:
1. Party A constructs a key pair (public key + private key) and publishes the public key to Party B
2. Party A uses the private key to sign the data, and then sends "Signature + Data" to Party B.
3. Party B uses public key + digital signature to verify data
Construction and processing of encrypted packets (encryption and decryption based on javascript)
The API library used here is/wwwtyro/cryptico/
Loading third-party js library
Since the API of third-party libraries is fine and many functions return js objects cannot be passed in LR, the entry of the library needs to be modified. Edit, add 3 functions to the end that directly return text.
Note: This sample is only used for debugging. During actual testing, the server's public key will be used directly. The file needs to be modified at that time.
The operation results are as follows
If it is a signature, the usage will be different.
5 Mobile application testing
The following summarizes the recording scenarios of several typical mobile applications. Vmall's subsequent mobile application testing tasks can refer to this table to use the corresponding recording method.
Recording scene type |
Applicable conditions |
How to record |
Agent recording |
Mobile devices can connect to the same network, and the application supports proxy settings. |
Configure a proxy server in the mobile app and add the address of VuGenProxy. Note: If the recording contains ssl traffic, it needs to be installed on the device.LoadRunnerProxy SSL CA Certificate (Accesshttp://lr_proxy_ip:80/) |
Server side recording |
Cannot record from real devices. The device, server and VuGen are all in the same network, and only one server needs to be recorded. |
Install VuGen’s Mobile Sniffer Agent on the server Fill in the Sniffer Agent address on the server |
Network packet capture generation |
There are already ready-made network packages, such as pcap files generated using WireShark or tcpdump -s 0 -w commands |
Record with traffic analysis options |
Mobile phone simulator recording |
It cannot be recorded from real devices, the test range is limited to Android devices, and there are available Android emulators. |
Select the corresponding emulator and record it |
Record on your phone |
The device under test is Android and has rooted |
Install on your phoneLoadRunner Mobile Recorder, generate scripts in VuGen using the pcap file generated by this app. |
6 Browser simulation
Ø Simulation of different browsers
Parts that can be simulated
User-Agent message header: It must be consistent with the simulated browser, and can be obtained by viewing the packet capture data of httpwatch on different browsers.
Number of single domain name connections: Generally, the number of single domain name connections in older versions of browsers is relatively low. Currently popular browsers generally relax this limit to 6-8 connections. If the test script uses the default browser configuration, the number of concurrent connections will be too low and the actual pressure will not match. Pay attention to the red box part in the screenshot below.
After you modify the browser simulation configuration (such as changing the browser version from low to high), the behavior of the test tool will change and your test results will also change.
The parts that cannot be simulated:
In the interaction between browsers and web applications, some content is unusablePerformance TestingTool simulation, even if you want to simulate it, it is meaningless.
The browser pops up the window to download the file:
This action performance test cannot be simulated, the tester only needs to simulate reading the Http buffer and writing it to the file.
JS operation:
Generally speaking, in addition to Ajax-related js, other types of js mainly involve rendering and drawing of local DOM, as well as requested encryption or signature, etc. The speed of these local js tasks has nothing to do with the performance of the remote server. Therefore, it is not feasible to cover these js running logic by imitating a browser in LoadRunner, because all local running logic is irrelevant to the network layer, which should be ignored in typical web application performance testing scenarios, unless the front-end performance of the web is intended to be tested, but this is beyond the scope of LR.
7 Using Scenarios for Port Mapping
PortMapping is a relatively important component in LR. The purpose of designing this component is to perform some special processing on certain IP+Port traffic during the recording script. With the iterative update of the LR version, the component's functions are now very rich.
The following is a typical scenario configuration for PortMapping is given as a reference.
1. Record all http requests
Use the default configuration, no modification is required.
2. Record all http requests, but exclude requests sent to the specified IP
3. Record all http requests, but exclude requests sent to the specified IP port
4. Record requests for the specified IP and the specified port
Note that this configuration has 2 Entry
5. Record SSL requests for the specified IP and specified port
6. Recorded requests using TLS 1.0
Since the above configuration will affect all addresses and ports, the following configuration can be left blank.
7. Records sent to multiple IPs, using different SSL, TSL configuration but with the same port
8. Use PEM certificate and password to record SSL3 requests sent to the specified IP
The PEM certificate is obtained by converting the CER certificate with openssl, and the specific operation method is omitted.
After the configuration is completed, you can use the TestSSL button to test it.
9. When the recording process is slower than manual operation and ssl is not used. Record in direct connection mode.
The biggest difference between recording in direct connection mode is that it is directly connected to the server under test, rather than communication between the proxy and the server in proxy mode. The default recording mode of LR is proxy mode. When encountering problems similar to slow recording, you can try to solve this method.
8 Testing based on asynchronous communication mode
This chapter mainly explains the testing based on asynchronous communication mode (the concepts and applicable scenarios of poll, long poll, push and websocket, the recognition rules of asynchronous transactions, the corresponding test script recording and writing, and the association skills)
Ø Illustrations of several typical asynchronous communication models:
Each mode has great differences in the real-time and performance of messaging, so there are different applicable scenarios.
Polling
Long Polling
PUSH
Ø Identification of asynchronous communication mode
You can configure communication pattern recognition rules through the following interface. Note that the URL, interval and size of the communication matching are very critical parameters. Improper settings will cause the test script to communicate with the server in an incorrect way. Fortunately, if the business cannot be adjusted, you can continue to check. If the business can be adjusted, the model error will be a greater hidden danger, resulting in distortion of the test results.
Ø Generation and debugging of asynchronous communication mode scripts
After the correct recognition rules are configured, the LR will automatically wrap the asynchronous communication request scripts with a specific API to generate preliminary test scripts when recording is completed, so that the communication requests can be distinguished from ordinary Http requests, because these requests are used to maintain communication rather than to return to the web page or call the interface. Testers can further enhance and modify these preliminary generated test scripts based on the API's instructions. There are mainly the following APIs for packaging:
web_reg_async_attributes defines the beginning of asynchronous communication
web_stop_async defines the end of asynchronous communication
The calling parameters of the above API include the callback function calls, and the main usage scenarios are as follows:
The complete API list is as follows
Ø WebSocket Testing
The above asynchronous communication modes have been gradually eliminated with the development of IT technology. Currently, WebSockets, which have good performance in real-time and performance, are becoming more and more popular. LoadRunner is
9 DFE Application Scenario-Complex Request Construction
What is DFE?
For example, the following request script for an application based on GWT-RPC (GoogleWeb Toolkit)
How do testers handle such Body requests to simulate such RPC calls?
The main function of DFE is to simplify the processing of various coded request messages (including GWT-RPC, Base64, Json, etc.) and improve the writing efficiency of test scripts.
DFE flow chart
When the request message is complex, multiple DFE chains can be used to generate messages that are easily processed by the tester.
In combination with the above example, the unprocessed GWT-RPC message format is as follows
After configuring the DFE of GWT, the message format in the script has been converted (the target format is XML), and it will be much easier to perform parameterization or message construction at this time.
How to use DFE?
Ø Construction and processing of complex message packets
JSON is very popular in calling various service interfaces. Here we mainly use complex json requests to construct complex json requests as an example.
The operation API for json data has been added in the LR12.53 version (according to Haitao, LR will be upgraded to 12.52 by the end of July), and before this, you can only use workarounds to construct.
Here is an example of an interface test script imported from the CSPart relationship of Huawei Configuration Cloud Project in 2015
The original simple request format is roughly as follows:
If the test scenario needs to construct a more complex structure based on this message format, in addition to directly splicing strings to construct json, DFE features can also be used to construct complex request messages, and the scripts are more flexible and easy to maintain.
Turn on DFE
To configure the DFE chain, select the Json toXml extension here because we need to convert the original json request to xml for processing, because LoadRunner does not handle Json's API but has an XML API.
Design a request template, and the import of CS relationships of any scenario can be extracted, updated and copied from the structure of this template.
A tip, writing this template manually is prone to errors. You can use the DFE function to convert the original json request to xml.
All DFE-related APIs are as follows
Below is a template for constructing messages.
The following code contains XML extraction, replacement attributes, insertion and copying. The API used is as follows
The more critical point is that the positioning of XML elements is Xpath. If the XML API call parameters use the wrong Xpath script, it will run unsuccessfully or output an incorrect json request. If you are not very familiar with Xpath, it is recommended not to write it by hand. Here is a tip, use XML templates.ChromeOpen it and use Chrome's Copy function to generate Xpath.
It is particularly important to note that the more complex the test script, the higher the chance of bugs appearing.
In this example, the xml splicing will become larger and larger as the script is iteratively spliced. If it exceeds the declared size, it will cause an error in memory overflow. This problem is more hidden because everything is normal at the initial run of the script and errors will occur only after a certain number of times. This is used to initialize the all_xml variable before each Action iteration, or reassign memory to the variable to fix the problem.
Note that when multiple node attribute parameterization is performed, the output of these XML APIs is the input of the next XML API. If it is filled in incorrectly, it will cause a bug.
Note the function web_convert_from_formatted, which converts the spliced XML into the corresponding Json of the interface.
During debugging, you can place the json request constructed by the LR script into POSTMan or other similar tools to test, which is more efficient.
The following is a slightly complex Cpart's configuration to mount 3 Spart nodes. The following is formatted and displayed as follows:
Ø UtilizationjavascriptConstruct a request message
10 Testing based on Java interface
Since the integration verification center currently does not have a Java Vuser license, it will not be considered for the time being. Jmeter pressure measurement is preferred for similar scenarios.
It should be noted that no matter what testing tool is used for stress testing, since a lot of the logic in the jar package is not transparent to the tester, it is necessary to carefully analyze the differences in the actual pressure model. Take Dubbo as an example. Since Dubbo's connection is a singleton mode, always uses a long connection. In a single instance, no matter what the value of the concurrent thread group you configure, the concurrent pressure is passed through this long connection. In real scenarios, the call pressure does not necessarily increase over a fixed number of connections (the number of Consumer instances), and the network IO that a single long connection can carry will also be affected by the complexity of the interface's object delivery. If this particular pressure model does not take into account the possible deviation of the test results.
11 Request serialization
In interface testing, request and response serialization is often involved, and currently there are two main types: php and json.
Since the serialization method will also have an impact on performance, it is recommended to test multiple serialization methods of the same interface if conditions permit.
PHP serialization
In the test of Vmall OPENGW gateway, some scenarios are used to call the interface in PHP serialization, such as the following example.
NSP service request parameters (PHP serialization) in OPENGW interface:
a:1:{i:0;a:18:{s:7:"cmbCono";s:0:"";s:15:"isMultiPayOrder";i:0;s:9:"isRiskPay";i:0;s:6:"openId";s:0:"";s:9:"orderCode";s:10:"5200008038";s:13:"paymentAmount";d:24380.0;s:14:"paymentChannel";i:8;s:10:"paymentFee";d:0.0;s:13:"paymentMethod";s:7:"SBERPAY";s:9:"paymentNo";s:10:"5200008038";s:13:"paymentStatus";s:1:"1";s:11:"paymentTime";s:24:"2016-03-01+14:47:09+0800";s:11:"paymentType";i:63;s:7:"salesId";i:25;s:17:"tradeSerialNumber";s:25:"CP20160301144710514391289";s:12:"uniOrderCode";s:0:"";s:16:"uniPaymentAmount";d:0.0;s:6:"userId";s:18:"260086000000723101";}}
The parameters requested here cannot be simply replaced by parameterization, for the following reasons:
PHP marks different types of data with different letters. The article Using Serialized PHP withYahoo! Web Services provided by Yahoo Development Website gives all letter marks and their meanings:
a - array
b - boolean
d - double
i - integer
o - common object
r - reference
s - string
C - custom object
O - class
N - null
R - pointer reference
U - unicode string
The numbers after some types represent length, and simple parameterization cannot modify this length identifier. When the parameter length changes, the server-side deserialization fails and the test script cannot be executed.
A workaround method is to use other tools to generate the parameters required for the test in advance, and LR can directly call these ready-made parameters. Below is an example of using python to generate parameters, of course you can also use other familiar programs.
The above python script can batch generate PHP serialization request parameters based on the existing order number, and then import the LoadRunner parameter file for parameterization. If you need to modify other parameters, you can modify the key value of the corresponding output in the script.
The manifestation of disadvantages
As the test parameters grow larger, the final parameter file may become very large or even exceed the LR limit. At this time, another workaround is needed to replace the parameter with the same length as the OrderCode remains unchanged. At this time, the parameter file only needs to prepare enough OrderCode, so the volume of the parameter file can be greatly reduced.
1. Custom functions to add character replacement
char *strReplace(const char *src, const char *from, const char *to)
{
char *value;
char *dst;
char *match;
int size;
int fromlen;
int tolen;
// Find out the lengths of the source string,text to replace, and
// the replacement text.
size = strlen(src) + 1;
fromlen = strlen(from);
tolen = strlen(to);
// Allocate the first chunk with enough for theoriginal string.
value = (char *)malloc(size);
// We need to return 'value', so let's make acopy to mess around with.
dst = value;
// Before we begin, let's see if malloc wassuccessful.
if ( value != NULL )
{
// Loop until no matches are found.
for ( ;; )
{
// Try to find the search text.
match = (char *) strstr(src, from);
if ( match != NULL )
{
// Found search text at location 'match'.
// Find out how many characters to copy up to the'match'.
size_t count = match - src;
// We are going to realloc, and for that we willneed a
// temporary pointer for safe usage.
char *temp;
// Calculate the total size the string will beafter the
// replacement is performed.
size += tolen - fromlen;
// Attempt to realloc memory for the new size.
//
// temp = realloc(value, size);
temp = (char *)realloc(value, size);
if ( temp == NULL )
{
// Attempt to realloc failed. Free the previouslymalloc'd
// memory and return with our tail between ourlegs.
free(value);
return NULL;
}
// The call to realloc was successful. But we'llwant to
// return 'value' eventually, so let's point itto the memory
// that we are now working with. And let's notforget to point
// to the right location in the destination aswell.
dst = temp + (dst - value);
value = temp;
// Copy from the source to the point where wematched. Then
// move the source pointer ahead by the amount wecopied. And
// move the destination pointer ahead by the sameamount.
memmove(dst, src, count);
src += count;
dst += count;
// Now copy in the replacement text 'to' at theposition of
// the match. Adjust the source pointer by thetext we replaced.
// Adjust the destination pointer by the amountof replacement
// text.
memmove(dst, to, tolen);
src += fromlen;
dst += tolen;
}
else //No match found.
{
// Copy any remaining part of the string. Thisincludes the null
// termination character.
strcpy(dst, src);
break;
}
} //For Loop()
}
return value;
}
int lr_replace( const char *lrparam, char *findstr, char *replacestr )
{
int res = 0;
char *result_str;
char lrp[1024];
// Finalize the LR Param Name
sprintf( lrp, "{%s}", lrparam);
// Do the Search and Replace
result_str = strReplace( lr_eval_string(lrp), findstr, replacestr );
// Process results
if (result_str != NULL )
{
lr_save_string( result_str, lrparam );
free( result_str );
res = 1;
}
return res;
}
2. Modify the script
Use third-party JS library for PHP serialization
/topics/0/270/
Using the above js library, refer to the js call method in the encryption and decryption signature chapter to enhance the LR test scripts to serialize directly in the script. The specific operations are omitted here. You can refer to the corresponding chapter to practice it yourself.
12 Custom error page handling
Ø What is a custom error page?
The http return code of the custom error page is generally 2xx or 3xx. Assuming that an exception occurs in the business process, the test tool will not set the transaction status to fail in this case.
Ø Purpose
Solve the detection problem of non-standard business process errors.
Ø Method
When only interface testing is involved, only a small number of checkpoints are needed. However, in scenarios involving the entire process, due to the large number of requests, it is very cumbersome to add too many checkpoints to deal with non-standard errors.
The correct approach is to configure non-standard error marks into the rule list of the ContentCheck page.
Sample:
If the specified sign is found in the response body of any request, the script run result will be set to fail.
Below is a counterexample of the configuration, if not found, it is marked as failed.
These configurations can be easily imported and exported in different test projects, making them very convenient to reuse.
Ø Limitations
The scope of the inspection is limited to Body only, and Headers are not within the scope of the inspection.
13 Cross-Script Test Data Sharing
Purpose: Solve the problem of parameter sharing between Vuser or scripts.
Features: This tool uses a NoSQL-based engine, so it has good performance and can support larger-scale test parameters.
Typical application scenarios: Script A adds the product to the shopping cart, Script B modifies the shopping goods, and Script C places an order for the shopping cart goods. VTS can be used to share product data, which is very useful in full-process testing.
Currently, VTS is not installed on the test machine, so you can refer to the installation path of the 62 press.
C:\Users\Administrator\AppData\Local\Temp\2\LR11.52Trial\AdditionalComponents\Standalone Applications
Start using local port 4000,http://localhost:4000The interface is as follows
Enable API access port, default is 8888
Import data, the data source can bemysqlOr CSV file, here we take CSV as an example
In the LR script, the init part writes the connection logic of VTS, the action part writes the data operation logic, and the end part writes the disconnect logic. as follows
The operation results are as follows
For specific details, please refer to the official API documentation.
14 A method of measuring business indicators
In the order payment business process, some consumers once complained that the order was unpaid for a long time after payment. In order to verify this problem, in the joint commissioning test of PTS and OMS systems, we need to measure the delay of the order displayed as paid after successful payment.
Since it is a cross-system call, it is relatively difficult to directly count such business indicators. Here is a workaround.
When paying a callback, the called timestamp is passed to the paymentMethod parameter of the interface (because the modification of this parameter does not affect the business logic), so that the payment start time is recorded in the database. Corresponding to tbl_ord_payment.paymentMethod, the corresponding processing of the test script is as follows.
When the order status is updated, its end time is tbl_ord_payment.payment_date. Therefore, the statistics of this delay can be found in the following SQL query. The yellow part is a batch mark specially designed when constructing test data. You can directly clean and analyze the test results according to this mark.
15 Distributed Testing
When a single press cannot construct sufficient pressure, multiple presses need to be turned on for distributed testing. The main problem in the configuration process is that the Agent connection caused by the firewall is unsuccessful. Please refer to the following method to set it up.
Windows
In addition to the firewall configuration, the permission settings of LR Agent also need to be checked. The default is to choose to run vuser without logging in, as shown in the figure below.
After the Agent of the remote press is installed and started, it can be configured in the Controller on the main control machine. The following example uses a remote press and a local press as a load generator. If the remote press status is not Ready, it means that the Agent is not started or the corresponding port cannot be accessed and needs to be checked.
LR Agent can also be installed inLinuxFirst, because the License configuration is involved, it can be ignored.
Pressure test end bottleneck
When the master node is mounted with more LoadGenerators or uses more Vusers, LoadGenerator may become a bottleneck. Therefore, when implementing large concurrent distributed tests, it is necessary to monitor the CPU, memory and bandwidth overhead of the press itself to avoid the pressure test end becoming a bottleneck.
16 Script recording problem check
The entire test process is inevitably often used to record scripts. Although the recording is not complicated, it will also encounter many problems that lead to failure of recording. The following lists some common recording problems and solutions.
Ø No script is generated after recording, but the event counter on the recording toolbar is growing
This shows that LR failed to recognize http traffic, and the program under test may have used ssl. At this time, you need to select the correct ssl protocol version, such as ssl2, ssl3 or TSL. These can be configured via the Option button of the Port Mapping interface.
Ø No script is generated after recording, and the event counter on the recording process toolbar increases very little
This means that no traffic is recognized by the test tool, and no traffic is generated on the test program on the network. For example, connection failure or PortMapping configuration error caused by antivirus software. Sometimes multiple tags in the browser can also affect this.
Ø Specific events cannot be recorded
In this case, it is possible that such events are directly discarded by the LR, because the test tool only records requests with http responses of 2xx and 302 by default. If it is another return code, it will be ignored, such as 304.
You can add a value to the following path by modifying the registry
[HKEY_CURRENT_USER\Software\MercuryInteractive\Networking\Multi Settings\QTWeb\Recording]
"GenerateApiFuncForCustomHttpStatus"="304"
Ø The recording program does not respond during recording
Generally, the LR cannot connect to a certain server. The reason can be viewed through the Recording Log, such as the following
A common occurrence in the testing of Huawei IT applications is that some addresses cannot be connected due to the isolation between the test environment and the production environment. Generally, these addresses have nothing to do with business processes, such as collecting user behavior data and other addresses that are not related to the object being tested. This can be ignored.
In this example, the server IP+5222 port is inaccessible. After troubleshooting, the address and the port are not related to the service being tested. You can ignore the IP and port through PortMapping in the recording option, refer to the configuration below.
If this address is related to the port and the service being tested, you need to checkbox.
Ø A server authentication error message appears during recording.
Currently, the test scenarios of Vmall basically do not involve https. As the popularity of https becomes, similar problems will be encountered in the subsequent test tasks.
This problem is mainly because the test side cannot verify the validity of the server certificate, so the LR's CA certificate can be added to the trusted root certificate node. The file name of the LR certificate iswplusCAOnly_Expiration_2022.crt can be found under bin/certs in the installation directory.
Ø A browser crash occurred during recording.
For unknown reasons, try changing the browser version and type.
17 Appendix
17.1 Tool update instructions
/en/latest/help/WebHelp/Content/WelcomeContent/c_WhatsNew.htm
/en/latest/help/WebHelp/Content/LR_TopNav_contentPDFs.htm
17.2 Script Enhancement Plugin
VuGen PowerPack
/HPSoftware/VuGenPowerPack
This tool is a plug-in package that can improve the efficiency of writing test scripts