Completely discard the script recording, use the Web_custom_request function to customize the LR script

Source: Internet
Author: User
Tags list of attributes printable characters

OriginalHttp://www.cnblogs.com/Bonnie83/p/3525200.html

Beginner performance test, the first step must learn the script recording, but all the way down all kinds of recording failure, playback script failure of endless problems, the reason is that LR itself has a compatibility problem with the test environment caused the recording failure, the deeper reason is that the recorder does not know the principle of LR recording script, Or do not know the client and the server side of the request and response content and communication methods, resulting in the failure of script execution will not be possible. Recently in the project to do an interface test, because the request is co-sponsored by the 3rd party and it is not easy for the 3rd party to provide their platform for us to do the test, so this situation is not able to take the recording script, can only choose to manually write script implementation. learned that the interface is the Post method using the HTTP protocol, think of Web_submit_form () and Web_submit_data () two functions, they implement the HTTP request rules, a look at the Anxi original Web_custom_ The request () function is a "Magnum" function that can be used to customize HTTP requests , with the functionality of the Web_link (), Web_url (), Web_submit_data () functions, and the ability to freely define the required HTTP GET and POST request. Online to see an introduction web_custom_requst, written in very detailed, share (of course, the English good directly to see the help of the LR comes from the document will feel more original):

Appendix: web_custom_request Function Syntax explanation

Grammar:
Int web_custom_request (const char *requestname, <list of Attributes>,[extrares, <list of Resource Attributes> ;,] last);

return value:
Lr_pass (0) stands for success
Lr_fail (1) represents a failure.

Parameters:
1. Requestname: The name of the step, the name displayed in the tree view in Vugen.
2. List of Attribute: The following attributes are supported :
1) URL:
Page address.
2) Method:
How the page is submitted, post or get.
3) EncType:
The encoding type. This parameter gives a content type (Content-typeHTTP requestThe "EncType" of the body will cause errors on the server. We generally recommend that you do not manually modify the "EncType" value when recording.
Any designation for "EncType" overrides the specified Web_add_[auto_]header function.Content-typeContent-typeRequest Header
4) Bodyfilepath:
The path of the file to be transferred as the request body. It cannot be used with the following attributes: Body, or other body property or RAW Body property including Bodybinary,bodyunicode,raw_body_start or Binary=1.
5) UserAgent:
User agent, which is the name of an HTTP header that identifies an application, usually a browser, that renders the interaction between the user and the server.
For example: Head Information "user-agent:mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.0) "Recognizes IE Browser 6.0 under Window NT. Other user-agent values are used to describe other browsers, or non-browser programs. Typically, all requests in an application use the same user agent, which is specified by the recorder as a runtime parameter (run-time setting-browser emulation-user agent). In any case, even in a simple browser process, it is possible to use non-browser components (such as ActiveX controls) that interact directly with the server, usually with user-agent properties that are different from the browser. Specify "useragent" to indicate that this is a non-browser request. The specified string is used by the HTTP header "User-agent:" and in some cases it affects the behavior when the script is played back. For example, do not use browser caching, assuming that the specified URL belongs to a resource, and so on. (LoadRunneritself does not check whether the specified string is the same as the value of the browser itself)
6) Binary:
"Binary=1" means that each of the page request bodies is replaced with a single-byte hexadecimal value with file://x/# #形式出现的值 (where "# #" stands for 2 hexadecimal digits). If "binary=0" (the default value), all character sequences are simply passed by literal values. Pay attention to the use of double slashes. In the C compiler, a double slash is interpreted as a single slash. If you do not need 0 bytes, a single slash can be used in cases where binary is not equal to 1 (for example, using \x20 instead of file://x20/). If you need 0 bytes, you can only use File://x00/and set "Binary=1", \x00 is logically truncated.
7) ContentEncoding
Specifies that the request body is encoded using the specified method (gzip or deflate), and the corresponding "content-encoding:" HTTP header is sent along with this request. This parameter applies to web_custom_request and Web_submit_data.
8) Ftpascii:
"1" uses ASCII mode to handle FTP operations; "0" uses binary mode.
9) TargetFrame:
The name of the frame on which the current link or resource resides. In addition to the frame's name, you can specify the following parameters:
_blank: Open an empty window.
_parent: Replace the newly changed frame with its ancestor.
_self: Replaces the newly changed frame.
_top: Replaces the entire page.
Reccontenttype):
The content type of the response header when the script is recorded. such as text/html, Application/x-javascript and so on. When the resource property is not set, it is used to determine whether the destination URL is a resource that can be logged. This property contains the primary and secondary resources. The most frequently used types are text, application, and image. Minor types vary a lot depending on the resource. For example: "reccontenttype=text/html": Represents HTML text. "Reccontenttype=application/msword": Indicates that MSWord is currently in use.
One) Referer:
The page associated with the current page. If the address of the URL has been explicitly specified, this entry can be omitted.
Resource):
Indicates whether the URL belongs to a resource. 1 Yes; 0 is not. When this parameter is set, the Reccontenttype parameter is ignored. "Resource=1" means that the current operation has little to do with the success of the script in which it resides. If an error occurs while downloading a resource, it is treated as a warning rather than an error, and the URL is downloaded by the "Run-time Setting-browser emulation--download non-html resources" option. The response information for this operation is not parsed as HTML. "Resource=0", which indicates that this URL is important, is not affected by the Send request (RTS) and resolves it when needed.
Resourcebytelimit):
The limit size of the Web page download resource. When the set limit is reached, additional resources cannot be downloaded. Only valid for resources that need to be downloaded. Download process: If the total download size is less than the limit value, the download starts normally. If the set limit value is reached when downloading, the resource size is known (Content-length is specified in the HTTP response header), in which case, if only one buffer is required, the download can be completed normally. If more than one buffer is needed, or if the resource size is unknown, the download will break and close the current connection. This feature can be used to simulate situations where a user does not wait to navigate to another page when a page download is complete. It is not available in HTTP mode and is not available in concurrent Groups (a zone in the VUser script, where all functions in the zone are executed concurrently). Only applies to sockets playback, WinInet is also not applicable.
Snapshot):
The file name of the snapshot.
Mode:
Two recording levels of HTML, HTTP. HTML level--record intuitive HTML actions on the current web interface. Record these actions in step-by-step Web_url, Web_link, Web_image, and Web_submit_form. Vugen only records requests that return an HTML page, and does not process scripts and applications. The HTTP level--vugen records all requests as web_url directives and does not generate Web_link, web_image, web_submit_form functions. This method is more flexible, but the resulting script is not intuitive.
Extraresbasedir):
Root URL, placed in the Extrares group. It is used to parse the relative URL (translator plus: A relative path and an absolute path similar to Windows). The URL can be an absolute path (for example, Http://weather.abc.com/weather/forecast.jsp?locCode=LFPO), or it can be a relative path (for example, "Forecast.jsp?loccode=lfpo"). The true URL is downloaded through an absolute path, so the relative URL path must be parsed using the root path URL. For example, using http://weather.abc.com/weather/as the root path to resolve "Forecast.jsp?loccode=lfpo", the final URL is: http://weather.abc.com/weather /forecast.jsp?loccode=lfpo. If you do not specify "Extraresbasedir", the default root URL is the URL of the main page.

) Body:
The request body. In different applications, the request body is passed through the body, bodybinary, or Bodyunicode parameters, respectively. The request body can use only one of the parameters, or a series of separate parameters can be used to form a multi-request body. For example:
Web_custom_request (

......

"Bodyunicode=reprice"

"Bodybinary=\\x08\\x00\\xcc\\x02\\x00\\x00"

"Body=.\r\n"

"-dxjjtbw/(. tp?eg:ch/6--\r\n",

last);
In the above code, 3 parameters are used to divide the request body, one is a Unicode segment, one is a binary segment, and the last is a regular string. The final request body is the value that these 3 parameters are concatenated in the order in which they are in the function. There is also a seldom used parameter, Binary. It can also describe the binary request body, but only one request body parameter is allowed in the function. All the request bodies are ASCII characters, ending with null.
A body--that represents a regular, printable string. Cannot represent empty bytes. All characters are represented by a backslash. Note: In the old script, you can see that non-printable characters are encoded in the request body as 16 binary. (For example, "\\x5c"), in which case you must use "Binary=1" to identify it. Null bytes are expressed using "file://0.0.0.0/". Instead, the new script places the request body in separate parameters ("body= ...", "bodybinary= ...", body= ...).
bodybinary--represents a binary code. Non-printable characters are encoded in the request body in a 16-file://xhh/manner. Here HH represents the hexadecimal value. Null bytes are expressed using "file://0.0.0.0/".
bodyunicode--American English, especially Latin utf-16le (Little-endian) encoding. This encoding appends a 0 byte to the end of each character to make the character more readable. But the actual parameters in the Vugen remove all 0 bytes. But before sending it to the Web server, the Web_custom_request function will re- add 0 bytes. For non-printable characters, the use of a DSLR slash indicates that an empty byte cannot be represented.

Note: If the request body is larger than 100K, a variable is used instead of the body parameter. The variables are defined in Lrw_custom_body.h.

Raw Body:
The request body is passed as a pointer, which points to a string of data. The binary request body can be sent using the Bodybinary property (or using the Body property to pass, provided the required setting
"Binary=1"). In any case, this approach requires the use of an escape character backslash to convert non-printable characters to ASCII characters. In order to have a simpler way of showing the raw data, the raw body property comes into being, passing pointers to binary data. The pointers are represented using 4 successive sets of parameters, and must be arranged in order:
Raw_body_start
Pointer to data buffer
(int) Length
Raw_body_end

Example:
Char *abc= .../* Pointer to the raw data */
Web_custom_request ("Stepname",
"Url=http://some.url",
"Method=post",
Raw_body_start,
"ABC",
3,
Raw_body_end,
last);
In an app, even if you set the length of the data to 0, the pointer must have a value and cannot be empty. In "Binary=1", you cannot use the syntax above to pass raw data. Data in the data buffer cannot be parameterized. It is also said that any parameter in the buffer (for example, "{Myparam}") cannot be correctly substituted for the corresponding value, but will only be sent in literal values.

3, Extrares: Indicates that the following parameters will be the list of Resource attributes.

4, Last: The end of the indicator.

5. List of Resource Attributes
List of within Resource only when recording options--recording--html-based script--Record Attribu The current script step option is selected TES will be inserted into the code. The non-HTML mechanism in the Web page produces a list of resources, including JavaScript, ActiveX, Java applets, and flash requested by the resource. In the Vugen's recording option, you can set these resources to be recorded in the current operation (this setting by default) or as a separate step.

Completely discard the script recording, use the Web_custom_request function to customize the LR script

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.