在VuGen中默认使用{}的字符串称为参数

注意:参数必须在双引号中才能用

将字符串保存为参数

lr_save_string("string you want to save", "arg_name");

举例:用参数来替换需要打开的url链接

Action2()

{

lr_save_string("http://172.25.75.2:1080/WebTours/", "web_site");

//打开登录页面

web_url("WebTours",

"URL = {web_site}",   //运行出错//改成"URL= {web_site}"即可

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

LAST);

return 0;

}

运行报错:

Action2.c(6): Error -27226: The "URL = http://172.25.75.2:1080/WebTours/" argument (number 2) is unrecognized or misplaced    [MsgId: MERR-27226]

Action2.c(6): web_url("WebTours") highest severity level was "ERROR", 0 body bytes, 0 header bytes  [MsgId: MMSG-26388]

解决方法:

"URL = {web_site}",URL和等号”=”之间多出了一个空格,去掉该空格即可。

所以使用lr_eval_string()函数的时候也是使用双引号来调用的。

还可以如下方式

Action2()

{

lr_save_string("http://172.25.75.2:1080/", "web_site");

lr_save_string("WebTours/", "web_name");

//打开登录页面

web_url("WebTours",

"URL={web_site}{web_name}",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

LAST);

return 0;

}

获取参数值的字符串表识

可用lr_eval_string函数获取参数值的字符串标表示,然后用lr_output_message()函数输出结果

Action2()

{

lr_save_string("http://172.25.75.2:1080/", "web_site");

lr_save_string("WebTours/", "web_name");

lr_output_message(lr_eval_string("获取参数值的字符串表示:{web_site}{web_name}"));

//打开登录页面

web_url("WebTours",

"URL= {web_site}{web_name}",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

LAST);

return 0;

}

注:如果想获取参数字符串的第一个字母,同c,可以这样:lr_eval_string(“{param}”)[0];

int型数字保存为参数

lr_save_int(int_number, “param_name”)

例如:

Action2()

{

lr_save_int(0, "int_param");

//打开登录页面

web_url("WebTours",

"URL=http://172.25.75.2:1080/WebTours/",

//      "Resource=0",

"Resource={int_parma}",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

LAST);

return 0;

}

把时间保存为参数

通过lr_save_datetime函数来实现。

函数原型:

void lr_save_datetime(const char *format, int offset, const char *name);

format:期望输出的日期格式,如:%Y、%m、%d、%X等

offset:类似与表示时间的一些关键字常量:

DATE_NOW -> 现在的日期

TIME_NOW -> 现在的时间

ONE_DAY -> 一天的时间

ONE_HOUR -> 一小时的时间

ONE_MIN -> 一分钟的时间

需要注意的是,他们可以单独使用,也可以联合使用

DATE_NOW + TIME_NOW -> 当前时间

DATE_NOW-ONE_DAY -> 昨天

DATE_NOW+ONE_DAY -> 明天

两天前的日期

DATE_NOW-2*(ONE_DAY)、 DATE_NOW-2*24*(ONE_HOUR)、 DATE_NOW-2*24*60*(ONE_MIN)

2个小时后的时间

TIME_NOW+2*(ONE_HOUR)

TIME_NOW+2*60*(ONE_MIN)

name:期望将时间保存到的那个参数的名称

format格式参照表:

Code

Description

%a

day of week, using locale's abbreviated weekday names

%A

day of week, using locale's full weekday names

%b

month, using locale's abbreviated month names

%B

month, using locale's full month names

%c

date and time as %x %X

%d

day of month (01-31)

%H

hour (00-23)

%I

hour (00-12)

%j

number of day in year (001-366)

%m

month number (01-12)

%M

minute (00-59)

%p

locale's equivalent of AM or PM, whichever is appropriate

%S

seconds (00-59)

%U

week number of year (01-52), Sunday is the first day of the week. Week number 01 is the first week with four or more January days in it.

%w

day of week; Sunday is day 0

%W

week number of year (01-52), Monday is the first day of the week. Week number 01 is the first week with four or more January days in it.

%x

date, using locale's date format

%X

time, using locale's time format

%y

year within century (00-99)

%Y

year, including century (for example, 1988)

%Z

time zone abbreviation

%%

to include the "%" character in your output string

 
 
举例:

Action()

{

lr_save_datetime("%X",TIME_NOW,"time");

lr_save_datetime("%Y-%m-%d",DATE_NOW,"date");

lr_save_datetime("%Y-%m-%d %X",DATE_NOW+TIME_NOW,"datetime");

lr_save_datetime("%Y-%m-%d",DATE_NOW-ONE_DAY,"yesterday");

lr_output_message(lr_eval_string("系统的当前时间为:{time}"));

lr_output_message(lr_eval_string("系统的当前日期为:{date}"));

lr_output_message(lr_eval_string("系统的当前日期,当前时间:{datetime}"));

lr_output_message(lr_eval_string("昨天的日期为:{yesterday}"));

return 0;

}

运行结果:

Starting iteration 1.

Starting action Action.

Action.c(7): 系统的当前时间为:12:27:54

Action.c(8): 系统的当前日期为:2014-10-22

Action.c(9): 系统的当前日期,当前时间:2014-10-22 12:27:54

Action.c(10): 昨天的日期为:2014-10-21

Ending action Action.

Ending iteration 1.

把内容保存为带格式的参数

lr_param_sprintf(param_name,format,var1,var2,…);

示例:

Action2()

{

int index = 56;

char *suffix = "txt";

lr_param_sprintf("NewParam","log_%d.%s",index,suffix);

lr_output_message("The new file name is %s",lr_eval_string("{NewParam}"));

return 0;

}

运行结果:

Starting action Action2.

Action2.c(24): The new file name is log_56.txt

Ending action Action2.

loadrunner之脚本篇——将内容保存为参数的更多相关文章

  1. loadrunner 脚本开发-参数化之将内容保存为参数、参数数组及参数值获取

    转自:http://blog.sina.com.cn/s/blog_13cc013b50102v49c.html(查看原文) 在VuGen中默认使用{}的字符串称为参数 注意:参数必须在双引号中才能用 ...

  2. loadrunner 脚本开发-参数化之将内容保存为参数、参数数组及参数值获取Part 2

    脚本开发-参数化之将内容保存为参数.参数数组及参数值获取 by:授客 QQ:1033553122 ----------------接 Part 1--------------- 把内容保存到参数数组 ...

  3. Loadrunner之脚本的调试和保存(六)

    一.调试脚本 脚本录制完毕后,按F5键或单击菜单上的RUN按钮,可以运行脚本.       在VIRTUAL USER GENERATOR中运行脚本的作用,主要是查看录制的脚本能否正常通过,如果有问题 ...

  4. Loadrunner之脚本篇——事务函数

    1.事务的开始和结束名称需要相同 lr_start_transaction(“transaction_name”); …//事务处理 lr_end_transaction(“transaction_n ...

  5. loadrunner之脚本篇——录制方式HTML-based和URL-based Script

    A.   HTML-based Script 针对 Web (HTTP/HTML)虚拟用户的缺省录制级别.它指示VuGen录制当前web页面上下文中的HTML action.录制会话期间并不录制所有资 ...

  6. loadrunner之脚本篇——代理录制

    版本:Loadruner 11.0 A.PC端录制Web应用程序 步骤1:根据实际情况,选择对应的协议 本例中选择Web(HTTP/HTML),如下 步骤2:找到代理设置界面 点击 Start Rec ...

  7. Loadrunder脚本篇——关联数组(参数数组)

    导言 前面说过可以用关联取出服务器相关的一些动态变化的信息,前面也提过web_reg_save_param中可以设置ord=all,代表从服务器中取出的是一个数组,它试用的场景是当我访问一个发帖网站, ...

  8. LoadRunner脚本篇

    LoadRunner脚本篇     1概述 2脚本录制 3脚本编写 4脚本调试   关  键  词:LoadRunner 性能测试脚本 摘      要:编写一个准确无误的脚本对性能测试有至关重要的意 ...

  9. Loadrunner下载脚本

    由于最近又在SGM做性能测试,扒拉出一篇去年5.6月份的一个脚本. 最近写的翻来看看其实也蛮简单的,还是就不放博客了. Action(){ //定义文件大小 int flen; //定义响应数据内容大 ...

随机推荐

  1. BAT-使用BAT方法设置IP地址

    ::------以下为批处理文件内容---- @echo off ::set slection1= set/p slection1=请输入IP地址: netsh interface ip set ad ...

  2. servelet 直接输出内容

    package helloworld; import java.io.IOException; import javax.servlet.ServletException; import javax. ...

  3. Servlet Session 跟踪

    HTTP 是一种"无状态"协议,这意味着每次客户端检索网页时,客户端打开一个单独的连接到 Web 服务器,服务器会自动不保留之前客户端请求的任何记录. 但是仍然有以下三种方式来维持 ...

  4. struts.properties文件

    此配置文件提供了一种机制来更改默认行为的框架.其实所有的struts.propertiesconfiguration文件中包含的属性也可以被配置在web.xml中使用的init-param,以及在st ...

  5. JavaScript 框架(库)

    JavaScript 高级程序设计(特别是对浏览器差异的复杂处理),通常很困难也很耗时. 为了应对这些调整,许多的 JavaScript (helper) 库应运而生. 这些 JavaScript 库 ...

  6. < 转载 > 说说JSON和JSONP

    推荐博文---说说JSON和JSONP,也许你会豁然开朗,含jQuery用例 里头说的很详细!

  7. [HTML5&amp;CSS3]Transform具体解释

    Transform字面上就是变形,改变的意思. 在CSS3中transform主要包含以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.以下我们 ...

  8. Android开发:拖拽

    google官网的training和API两个地方都提到了拖拽的实现,两种方法不太一样. 方法一 training(https://developer.android.com/training/ges ...

  9. jQuery EasyUI介绍

    官方定义:http://www.jeasyui.com/ what is JQuery EasyUI ? jQuery EasyUI framework helps you build your we ...

  10. win10 IoT开发 Serial​Device 返回 null

    树莓派3,win10 Iot,串口开发,抄例子,串口获取返回老是null,例子却可以,代码一样,上网查询结果如下: https://stackoverflow.com/questions/341603 ...