loadrunner Web_类函数之web_reg_save_param()

web_reg_save_param()--常用函数

注册将动态数据信息保存到参数的请求。

不推荐使用该函数,推荐使用web_reg_save_param_ex或web_reg_save_param_xpath。

INTweb_reg_save_param(为const char* PARAMNAME,<属性的列表>,LAST);

 

参数说明:

object:评估到类型为WebApi的对象的表达式。通常是webfor Java和Visual Basic。另请参见函数和常量前缀。

ParamName:一个以null结尾的字符串,指示要创建的参数的名称。

List ofAttributes:有关每个属性的详细信息,请参阅属性列表。

属性值字符串(例如,“Search =all”)不区分大小写。

LAST:指示参数列表结束的标记。

 

web_reg_save_param函数是用于在Web脚本中关联HTML语句的服务函数。

一般信息:

web_reg_save_param是注册类型函数。它注册一个请求,以在服务器响应中查找和保存文本字符串。仅在执行下一个操作函数(如web_url)之后才执行操作。

 

仅当启用录制期间的相关性时才会记录web_reg_save_param(请参阅VuGen的录制选项)。 VuGen必须处于基于URL的记录模式或基于HTML的记录模式,并且选中包含仅显式URL的A脚本选项(请参阅VuGen的记录选项)。

 

此函数注册从下载的页面检索动态信息的请求,并将其保存到参数。对于相关性,在使用动态数据的随后函数调用中将参数括在大括号(例如,“{param1}”)中。由web_reg_save_param注册的请求查找指定边界之间的字符(但不包括),并保存从左边界之后的字节开始,到右边界之前的字节结束的信息。

 

如果希望字符串周围有前导和尾随空格,并且您不想在参数中使用它们,请在左边界的末尾和右边界的开始处添加一个空格。例如,如果网页包含字符串, "Where and when do you want to travel?", the call:

web_reg_save_param("When_Txt","LB=Where and ", "RB= do",

        LAST );

with a spaceafter "and" and before "do", will result in"when" as the value of When_Txt. However,

web_reg_save_param("When_Txt","LB=Where and", "RB=do",

        LAST );

without thespaces, will result in a value of " when ".

 

不支持嵌入边界字符。web_reg_save_param导致在最近的左边界之后的下一个出现的简单搜索。例如,如果您已将左边界定义为字符“{`和右边界作为字符”}“,那么将保存以下缓冲区c:

          {a{b {c}

已定位左边界和右边界。因为不支持嵌入边界,所以`}'匹配最近的`{`出现在c之前。 ORD属性为1.只有一个匹配实例。

web_reg_save_param函数还支持数组类型参数。当指定ORD = All时,匹配的所有匹配项都保存在数组中。数组的每个元素由ParamName_index表示。在以下示例中,参数名称为A:

web_reg_save_param(“A”,“LB / ic =<a href=", "RB=\'>”,“Ord = All”,LAST);

第一个匹配保存为A_1,第二个匹配保存为A_2,依此类推。您可以使用以下术语检索匹配的总数:ParamName_count。例如,要检索保存到参数数组的匹配总数,请使用:

TotalNumberOfMatches= atoi(lr_eval_string(“{A_count}”));

下表指示如何使用边界参数来保存参数字符串的部分:

 保存到参数LB RB的字符串部分

整个字符串为空

由边界边界界定的字符串

一个字符串的开始直到第一个右边界空边界

最后一个左边界直到结束边界为空

所有Web脚本以及以HTTP或无线会话协议(WSP)重放模式运行的WAP脚本支持此功能。

 

List ofAttributes

Convert:可能的值为:

HTML_TO_URL:将HTML编码的数据转换为网址编码的数据格式

HTML_TO_TEXT:将HTML编码的数据转换为纯文本格式

此属性是可选的。

IgnoreRedirections:如果指定“IgnoreRedirections= Yes”,并且服务器响应是重定向信息(HTTP状态代码300-303,307),则不会搜索响应。相反,在接收到重定向响应之后,将GET请求发送到重定向位置,并且对来自该位置的响应执行搜索。

此属性是可选的。默认值为“IgnoreRedirections= No”。

LB:参数或动态数据的左边界。如果不指定LB值,它将使用数据开头处的所有字符作为边界。边界参数区分大小写,不支持正则表达式。要进一步自定义搜索文本,请使用一个或多个文本标志。此属性是必需的。请参见“边界参数”部分。

NOTFOUND:未找到边界并生成空字符串时的处理选项。

当未找到边界时,“Notfound =error”(默认值)会引发错误。

“Notfound = warning”(“Notfound = empty”在早期版本),不会发出错误。如果未找到边界,则将参数计数设置为0,并继续执行脚本。如果您想查看是否找到字符串,但您不希望脚本失败,则“警告”选项是理想的选项。

注意:如果为脚本启用了错误继续,则即使当NOTFOUND设置为“error”时,如果未找到边界,但是错误消息写入扩展日志文件,脚本将继续。

此属性是可选的。

ORD:表示匹配的序数位置或实例。默认实例为1.如果指定“All”,则将参数值保存在数组中。请参见参数数组示例。

此属性是可选的。

注意:为了向后兼容性,支持使用Instance而不是ORD,但不推荐使用。

RB:参数或动态数据的右边界。如果不指定RB值,它将使用所有字符,直到数据结尾为边界。边界参数区分大小写,不支持正则表达式。要进一步自定义搜索文本,请使用一个或多个文本标志。此属性是必需的。请参见“边界参数”部分。

RelFrameID:相对于请求的URL的HTML页面的层次结构级别。可能的值为ALL或数字。单击RelFrameID属性获取详细说明。此属性是可选的。

注意:GUI级别脚本不支持RelFrameID。

SaveLen:从指定偏移量中找到的值的子字符串的长度,以保存到参数。此属性是可选的。默认值为-1,表示保存到字符串的结尾。

SaveOffset:找到的值的子字符串的偏移量,以保存到参数。偏移值必须为非负数。默认值为0.此属性是可选的。

Search:搜索的范围 - 在哪里搜索分隔的数据。Thepossible values areHeaders (Search only the headers), Body(search only body data, not headers),Noresource(search only the HTML body, excluding all headers and resources), orALL(search body , headers, and resources). The default value is ALL. Thisattribute is optional.(可能的值是标题(仅搜索标题),正文(仅搜索正文数据,而不是标题),Noresource(仅搜索HTML正文,不包括所有标题和资源)或全部(搜索正文,标题和资源)。默认值为ALL。此属性是可选的。)

 

Example: web_reg_save_param

下面的实例是,对关联保存的参数,转换为一个数组随机取值,作为后面的请求参数使用。

 

 

The following examples are presented forweb_reg_save_param.

示例1:保存简单文本字符串

保存单个字符串的情况

需要处理数组的情况

示例2:使用二进制边界保存文本

示例3:保存使用偏移量和长度指定的文本

示例4:包含特殊字符的边界

Example 1:Saving simple text strings

在此示例中,web_reg_save_param将响应中的值保存到web_submit_form调用。 保存的值将用于后续的web_submit_form调用。

在MercuryTours示例程序中,服务器对以下web_submit_form调用的响应包含以下单选按钮选项:

<trbgcolor=#66cccc><th>Flight<th>Departure time<th>Cost

<tr bgcolor=#66CCff><td align=center><input type = radioname=outboundFlight value=230;378;11/20/2003 checked >Blue Sky Air230<td align=center>8am<td align=center>$ 378

<tr bgcolor=#eeeeee><td align=center><input type = radioname=outboundFlight value=231;337;11/20/2003>Blue Sky Air 231<tdalign=center>1pm<td align=center>$ 337

and so on.

To submit a reservation, the outboundFlight value is required.web_reg_save_paramsaves the outboundFlight value.

Case of saving a single string

To reserve the default flight, save the"checked" value, and pass it to web_submit_form. The html segment forthe default value is:

name=outboundFlight value=230;378;11/20/2003 checked >

/*This web_reg_save_param call applies to the following action function:web_submit_form. */

    web_reg_save_param("outFlightVal",

    "LB=outboundFlight value=", "RB=checked >", LAST );

    web_submit_form("reservations.pl",

        "Snapshot=t4.inf",

        ITEMDATA,

        "Name=depart","Value=London", ENDITEM,

        "Name=departDate","Value=11/20/2003", ENDITEM,

        "Name=arrive","Value=New York", ENDITEM,

        "Name=returnDate","Value=11/21/2003", ENDITEM,

        "Name=numPassengers","Value=1", ENDITEM,

        "Name=roundtrip","Value=<OFF>", ENDITEM,

        "Name=seatPref","Value=None", ENDITEM,

        "Name=seatType","Value=Coach", ENDITEM,

        "Name=findFlights.x","Value=83", ENDITEM,

        "Name=findFlights.y","Value=16", ENDITEM,

        LAST );

/*

The result of the web_reg_save_param having been called before theweb_submit_form is:

Action.c(15): Notify: Saving Parameter "outFlightVal = 230;378;11/20/2003"

*/

// Now use the saved outFlightVal

    web_submit_form("reservations.pl_2",

        "Snapshot=t5.inf",

        ITEMDATA,

        "Name=outboundFlight","Value={outFlightVal}", ENDITEM,

        "Name=reserveFlights.x","Value=92", ENDITEM,

        "Name=reserveFlights.y","Value=10", ENDITEM,

        LAST );

/*

Action.c(34): Notify: Parameter Substitution: parameter"outFlightVal" = "230;378;11/20/2003" */ 

Caserequiring handling arrays

If you want to test the last option returned bythe web_submit_form call, save all the matches and then handle the array.

This example shows the use of web_reg_save_param with "ORD=ALL"to get an array of parameters. The last item in the array is then used tocorrelate aweb_submit_form call.

char outFlightParam[50]; // The name of the parameter for correlation

char outFlightParamVal[50]; // The formatted value of outFlightParam

/*

This web_reg_save_param call applies to the following action function,web_submit_form. Because of the "ORD=ALL" argument, it saves all thevalues that have the given left and right boundaries to an array of parameters.

The SaveLen argument is used to restrict the length to 18 charactersbecause the default value is "230;378;11/20/2003 checked >". Werestrict the length so as not to capture the " checked ".

*/

    web_reg_save_param("outFlightVal",

        "LB=outboundFlightvalue=", "RB=>",

        "ORD=ALL",

        "SaveLen=18",

        LAST );

    web_submit_form("reservations.pl",

        "Snapshot=t4.inf",

        ITEMDATA,

        "Name=depart","Value=London", ENDITEM,

        "Name=departDate","Value=11/20/2003", ENDITEM,

        "Name=arrive","Value=New York", ENDITEM,

        "Name=returnDate","Value=11/21/2003", ENDITEM,

        "Name=numPassengers","Value=1", ENDITEM,

        "Name=roundtrip","Value=<OFF>", ENDITEM,

        "Name=seatPref","Value=None", ENDITEM,

        "Name=seatType","Value=Coach", ENDITEM,

        "Name=findFlights.x","Value=83", ENDITEM,

        "Name=findFlights.y","Value=16", ENDITEM,

        LAST );

/*

The result of the web_reg_save_param having been called before theweb_submit_form is:

Notify: Saving Parameter "outFlightVal_1 = 230;378;11/20/2003"

Notify: Saving Parameter "outFlightVal_2 = 231;337;11/20/2003"

Notify: Saving Parameter "outFlightVal_3 = 232;357;11/20/2003"

Notify: Saving Parameter "outFlightVal_4 = 233;309;11/20/2003"

Notify: Saving Parameter "outFlightVal_count = 4"

The next problem is to get the highest array element, identified with theparameteroutFlightVal_count. This parameter is automatically created bythe script recorder. You do not have to enter anything in the script.

*/

/* Get the name of the parameter, in this case "outFlightVal_4".

Put it in brackets so it can be an input to anlr_eval_string call.

Note that the brackets in the second argument tosprintf are notindicating a script parameter to sprintf. They are string literals thatwill be part of outFlightParam after the call.

In the second call to sprintf, those brackets indicate a parametertolr_eval_string.

*/

    sprintf(outFlightParam, "{outFlightVal_%s}",

        lr_eval_string("{outFlightVal_count}"));

/* outFlightParam is now "{outFlightVal_4}" */

    /* Now get the "Value" argument forweb_submit_form, in the

        format"Value=xxxx")

    */

    sprintf(outFlightParamVal, "Value=%s",

        lr_eval_string(outFlightParam));

    lr_message("The value argument is : %s",outFlightParamVal);

    // The value argument is : Value=233;309;11/20/2003

    /* Now the string outFlightParamVal can be passed

        to web_submit_form */

    web_submit_form("reservations.pl_2",

        "Snapshot=t5.inf",

        ITEMDATA,

        "Name=outboundFlight",outFlightParamVal,ENDITEM,

        "Name=reserveFlights.x","Value=92", ENDITEM,

        "Name=reserveFlights.y","Value=10", ENDITEM,

        LAST );

Example 2:Saving a text by using binary boundaries

以下示例使用BIN类型边界。左边界由3F和DD组成。 右边界由CC和b组成。web_reg_save_param("p","LB/BIN=\\x3F\\xDD", "RB/BIN=\\xCCb", LAST );

Example 3:Saving a text specified with an offset and length

以下示例指定偏移量和长度。HTML字符串“Astra on TESTSERVER”的边界是“Astra”(注意该字后面的空格)和“TestServer”。 这应该返回“on”,但由于偏移量为1(即从第二个字符开始),要保存的数据长度为1,则保存到TestParam的字符串为“n”。

web_reg_save_param("Param1", "LB=Astra", "RB= TESTSERVER",

    "SaveOffset=1", "SaveLen=1",LAST );

 

Example 4:Boundaries containing special characters

The following example shows the use of escaping inthe C language when the boundaries contain special characters.

以下示例显示了当边界包含特殊字符时在C语言中使用转义。

以下HTML细分在每个“<strong>”后面包含新的行字符(段落标记),并在每个类名称周围添加引号。 我们要保存“Georgiana Darcy”到参数“UserName”。 包含新行和引号的段必须包含在左边界中,因为在段之前的“Name:”是必需的,以使事件是唯一的。 在这种情况下不能使用ORD属性,因为相关元素之前的列表的长度不同。

<span class="surveyQuestionReview"><strong>UserID:</strong></span><strong>

    </strong> <spanclass="surveyAnswerReview">Revere18041775</span> <br>

<span class="surveyQuestionReview"><strong>Name:</strong></span><strong>

    </strong> <spanclass="surveyAnswerReview">Georgiana Darcy</span> <br>

<span class="surveyQuestionReview"><strong>Company:</strong></span><strong>

    </strong> <spanclass="surveyAnswerReview">Pride and Prejudice</span><br>

The function is:

web_reg_save_param("UserName",

"LB=Name:</strong></span><strong> \n    </strong><span class=\"surveyAnswerReview\">",

        "RB=</span><br>",

        LAST );

请注意:新行字符的\ n,并且引号字符需要转义:\“。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值