Loadrunner中常用函数的功能

上一篇 / 下一篇  2012-03-23 11:52:43 / 个人分类:Loadrunner 应用

web_custom_request

这个函数是对--使用各种方法和body创造一个http请求。

如果是手写脚本,在这个函数写,需要使用一个web_add_headerorweb_add_auto_headerfunction,让发送custom request之前明确被发送的http header是什么

 RecContentType

The type of resource that was recorded. This attribute contains information about primary and secondary resources. The most frequently used primary types aretext,application, andimage. The secondary type varies according to the resource. For example, "RecContentType=text/html" indicates navigation to html text. "RecContentType=application/msword" indicates the use of the MS Word application.

Note that this argument is ignored when theResource Attributeargument is set. The Resource argument is another available attribute for Action functions.

这个标识的是被记录是资源的类型。这个属性包含关于原始和第二资源的信息。最经常使用的是初始类型是text application image .第二类型根据资源不同而不同。例如text/html指出到html text的导向。

当在资源属性中参数设定后,这个属性被忽视。

 

Body Attribute

The body of a request is passed as the value of the attribute argumentsBody,BodyBinary, orBodyUnicode, depending on the content. The body can be a single argument, or partitioned intomultiple body segments,that is, aseriesof arguments. For example, in the following call toweb_custom_request, LoadRunner partitions the body into three segments: a unicode section, followed by a binary section, followed by regular text. The final body is the result of all three sections concatenated together in the same order as they are passed to the function.

一个requestbody是根据属性参数Body,BodyBinary, orBodyUnicode的设定值传出去的。是依赖内容的。这个body可以是单一的参数,或者是划分成多个body片段,一系列的参数。例如,在紧跟的web_custom_request中,ld划分一个body为三个部分,a unicode section, followed by a binary section, followed by regular text。最终的body是所有三个部分的集合。

web_custom_request(

                    ...
                    "BodyUnicode=REPRICE"
                    "BodyBinary=\\x08\\x00\\xCC\\x02\\x00\\x00"
                    "Body=.\r\n"
                   "-dxjjtbw/(.tp?eg:ch/6--\r\n",
                   LAST);

The deprecated web_custom_request parameter,Binary, can also be used to indicate a binary body, but only if a singleBodysegment is passed to the function.

All body values are ASCII, null-terminated strings.空值终止字符串

Body- indicates regular, printable text. Null bytes cannot be represented (except see note below). All characters are specified with a backslash.

Body指示 规则可打印的textnull字节不能被代表。所有的字符被用一个backslash来标识。

Note: In older scripts, you may see non-printable characters encoded within aBodyargument in hexadecimal code (e.g. "\\x5c") in which case "Binary=1" must also be passed as a parameter. NULL bytes can be represented in this way ("\\00"). In contrast, newer scripts partition the body into multiple body segments e.g. "Body=...", "BodyBinary=...", Body=...".

在旧的脚本,你可以看见不可打印的特征编码在一个Body的参数 使用十六进制。"\\x5c"。在新的脚本中 这个body分成片段。

BodyBinary- indicates binary code. Non-printable characters are encoded in hexadecimal in the form. \\xHH, where HH specifies the hexadecimal value. NULL bytes are specified by "\\00"

BodyBinary-代表二进制的代码。不可打印的字符被录制在16进制在一个form.

BodyUnicode- US-English, specifically Latin1 UTF-16LE (little-endian) Unicode only. The actual parameter is stripped of the extra zero byte appending each character to enable easier reading of the text. It is re-appended by web_custom_request before sending to the Web server.
For non-printable characters use a single backslash. Null bytes cannot be represented.

注意:对一个body的长度超出100K,一个变量的名字出现代替这个属性。这个变量在lrw_custom_body.h被定义。

Raw Body Attribute

Binary content can be sent in the request using theBodyBinaryattribute (or theBodyattribute when "Binary=1" is also specified). However, this method requires that content is converted into ASCII text using escape backslashes for non-printable text.

二进制的内容能够被request发送,使用bodyBinary的属性。那么,这个方法要求内容使用escape将不可打印的text转换成ASCII text

To enable a more simple representation of the raw data, theRaw Bodyattribute instead enables you to pass a pointer to the binary content.

更简单的代表raw data ,RawBody属性 确实能让你通过一个pointer传递二进制neritic

The syntax for sending raw body content is a set of 4 arguments to web_custom_request(). They must appear in the following order:

The correct order is:

RAW_BODY_START,

a pointer to the data buffer,

(int) length,

RAW_BODY_END

The syntax is illustrated in the following example:

char *abc= .../* a pointer to the raw data */

web_custom_request("StepName",

     "URL=http://some.url ",

     "Method=POST",

     RAW_BODY_START,

     "abc",

     3,

     RAW_BODY_END,

     LAST);

The pointer data buffer must not be NULL, even when the length is 0.

The Raw Body group cannot be used with the Binary parameter set ("Binary=1").

The data buffer can not be parameterized. That is, any parameter reference (e.g. "{MyParam}") in the data buffer will not be substituted with the corresponding parameter value, and will be used as is.

 

"Resource=0" 01的值,指出这个URL是否是关键性的还是资源性的。对于关键性的将报出错误。

 

Snapshot- the file name of the snapshot file (infextension), used for correlation.

Recording Level / Mode (Web)

The Recording Level orModefor Web Vusers. The possible values are:

HTML level: Instructs VuGen to recordHTML actionsintuitively, in the context of the current Web page. The actions are recorded as URL steps (web_url), link steps (web_link), image steps (web_image), and form. submission steps (web_submit_form).VuGen records only the HTTP requests that return HTML pages, but not scripts or applications.

HTTP level: Instructs VuGen to recordall requestsfrom the server as URL steps (web_urlstatements). It does not generate theweb_link,web_image, orweb_submit_formfunctions. This method is more scalable, but less intuitive when reading a generated script.

In older versions, theHTTP levelis called NORESOURCE.

 EncTypespecifies a Content-Type, such as "text/html", to be specified as the value of the "Content-Type" REQUEST header for the current replay.web_custom_requestperforms no body encoding. The Body argument specifies the body to be used as is (or after applying "Binary" processing), with any encoding having already been applied. Therefore, specifying anEncTypethat does not match the body may cause a server-side error. In general, it is recommended that you do not edit theEncTypeas recorded.

EncType为当前的回放时,明确request headerContent-Type的值 例如"text/html"。为的是当前回放时请求头部的content –type的值是什么。是有EncType来明确的。因,使用已经需要的编码方式。因此,如果明确一个EncType将会引起服务器端的错误如果声明的和服务器不匹配时。当录制的时候,推荐不需要修改这个属性参数。

AnyEncTypespecification silently overrides any web_add_[auto_]header for Content-Type. When "EncType=" (empty value) is specified, no "Content-Type" request header is generated. When "EncType" is omitted, then any applicable web_add_[auto_]header is used. If there is no header and "Method=POST", then "application/x-www-form-urlencoded" is used as a default. Otherwise, no Content-Type request header is generated.

The Extra Resource Attributes are only inserted when performing HTML-based recording and the non-HTML generated elements option is set toRecord within the current script. step.This is the default setting. For more information, refer to theCreating Vuser Scriptsguide.

 

UserAgent

"User-Agent" is the name of an HTTP header identifying the application, usually a browser, which represents the user in the interaction with the server.

"User-Agent"是一个HTTP头的名称来明确这个应用程序。通常情况下 一个浏览器,该浏览器就代表证用户和服务器之间的交互

For example, the header "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" identifies Microsoft Internet Explorer 6.0 for Windows NT. Other User-Agent strings are used for different browsers and for other, non-browser applications. Usually, all requests from an application use the same User-Agent value, which the recorder specifies as a Run-Time Setting. However, even within a regular browser session, there may be non-browser components (for example, Active-X) that interact with a server directly, and usually have a different User-Agent string than the browser. Specifying a UserAgent indicates that this is such a non-browser request. The specified string is used in the "User-Agent:" HTTP header, and affects the Replay's behavior. in some points, for example, by not using the browser cache, assuming the specified URLs are resources, etc.

通常,所有的从一个应用程序中的发出的请求都是使用相同的User-Agent的值。对于录制的脚本在running-setting中设置。通常 即使在一个规则的浏览器session中,也存在非浏览器的元件(例如Active-X )这些元件直接和服务器交互,并且通常使用和一个浏览器不同的User-Agent string。明确一个UserAgent指出这是一个非浏览器的request.这个明显的String使用在HTTP header "User-Agent:"。在某些方面影响着回放的行为,例如,不使用 浏览器的cache,假设的指出的URL是一个resources.

 

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a Web page only on certain conditions. To modify the HTTP header in the request seeweb_add_header, or to modify all subsequent requests seeweb_add_auto_header.

 

可请求时以修改HTTP header传给服务器的信息。修改HTTP header。使用你能获得的header 容许在 相应中有其他的内容类型例如压缩文件。或者你可以用某一种条件来request一个web page..具体需要可以查看web_add_header.

Web_link: text的值必须是<value = >,不应该是html中具体的text.

 Web_urlWeb_custom_request有什么区别

这个是在你请求的html中发现了各种resouce

另一个是那些resouce已经保存在cache中不需要重新下载。应该有server端的reponse body存储在cache中。

Web_submit_form.Web_submit_data

Web_submit_data函数

Performs an "unconditional" or "contextless" form. submission.

Action:

The HTTP address of the action to perform. when submitting the data.

Method:The form. submission method: POST or GET (default: POST).

Web_submit_form函数

Theweb_submit_form.function is anaction functionthat submits a form. Theweb_submit_form.function may be executed only in the context of a previous operation.

里面需要的参数不同。

server认证的函数

Web_set_user

Specifies a login string for a Web server.当这个认证确认后,为后来的参数化和关联的功能有好处。

set_userfunction specifies a login string for user "Private1" using the password "secret":

web.set_user("Private1", "secret", "www.myhost.com:8080");

Check Functions –进行文字验证的函数

包括出现的图片、文字、注册信息的验证--

 

运行web_find,提示为checks not enabled.web_find is skipped.

这个函数必须是在web_custom_request之后才可以执行。所以resulting in slower execution time thanweb_reg_find.。在java中,这个函数已经被取缔。

 

Web.reg_find

检查的是html web中的字。属性中使用SaveCount=abc_count—将这个结果保存成一个属性的值。一个变量。

在后面的函数可以使用这个变量来判断是否发现了被检查的“字”。

If (lr.eval_int(“<abc_count>”)==0)

In this example,web.reg_findis used to check for the login name. Commented out, is an alternative example of how to use the function to look for leading and trailing strings.

try{

       // Run the Web Tours sample program

       web.url("MercuryWebTours",

              "URL=http://localhost/MercuryWebTours/",

              new String[]{

                     "Resource=0",

                     "RecContentType=text/html",

                     "Referer=",

                     "Mode=HTML",

                     web.LAST

              });

       /* In a real script, you will probably use parameterization

       for LoginName. For this example, we simply create one parameter.

       */

              lr.save_string("jojo" , "LoginName" );

       // Set up check for successful login by looking for the login name

       web.reg_find("Text=<LoginName>",

              new String[]{

                     "SaveCount=WelcomeCount",

                     web.LAST

              });

/*         ******** Alternative ************

An alternative check which does not require knowing the login name, is to look for the strings that precede and follow the login name when the login is successful.

       web.reg_find("Text=",

              new String[]{

                     "TextPfx=Welcome,",

                     "TextSfx=, to the MercuryTours",

                     "SaveCount=WelcomeCount",

                     web.LAST

              });

*************************************/

// Now log in

       web.submit_form("login.pl",

              new String[]{},

              new String[]{

                     "Name=username", "Value=<LoginName>", web.ENDITEM,

                     "Name=password", "Value=bean", web.ENDITEM,

                     "Name=login.x", "Value=35", web.ENDITEM,

                     "Name=login.y", "Value=14", web.ENDITEM,

                     web.LAST

              });

       /* Check the Welcome Count and take whatever actions are

              appropriate for your script. */

       if (lr.eval_int("<WelcomeCount>") == 0 )

              lr.message("Login " + lr.eval_string("<LoginName>") + " unsuccessful");

       else

              lr.message("Login " + lr.eval_string("<LoginName>") + " successful");

}

catch (Exception e){}

 


TAG: 常用函数

 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 6262
  • 日志数: 7
  • 建立时间: 2012-03-21
  • 更新时间: 2013-04-18

RSS订阅

Open Toolbar