loadrunner之脚本篇——将内容保存为参数
在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之脚本篇——将内容保存为参数的更多相关文章
- loadrunner 脚本开发-参数化之将内容保存为参数、参数数组及参数值获取
转自:http://blog.sina.com.cn/s/blog_13cc013b50102v49c.html(查看原文) 在VuGen中默认使用{}的字符串称为参数 注意:参数必须在双引号中才能用 ...
- loadrunner 脚本开发-参数化之将内容保存为参数、参数数组及参数值获取Part 2
脚本开发-参数化之将内容保存为参数.参数数组及参数值获取 by:授客 QQ:1033553122 ----------------接 Part 1--------------- 把内容保存到参数数组 ...
- Loadrunner之脚本的调试和保存(六)
一.调试脚本 脚本录制完毕后,按F5键或单击菜单上的RUN按钮,可以运行脚本. 在VIRTUAL USER GENERATOR中运行脚本的作用,主要是查看录制的脚本能否正常通过,如果有问题 ...
- Loadrunner之脚本篇——事务函数
1.事务的开始和结束名称需要相同 lr_start_transaction(“transaction_name”); …//事务处理 lr_end_transaction(“transaction_n ...
- loadrunner之脚本篇——录制方式HTML-based和URL-based Script
A. HTML-based Script 针对 Web (HTTP/HTML)虚拟用户的缺省录制级别.它指示VuGen录制当前web页面上下文中的HTML action.录制会话期间并不录制所有资 ...
- loadrunner之脚本篇——代理录制
版本:Loadruner 11.0 A.PC端录制Web应用程序 步骤1:根据实际情况,选择对应的协议 本例中选择Web(HTTP/HTML),如下 步骤2:找到代理设置界面 点击 Start Rec ...
- Loadrunder脚本篇——关联数组(参数数组)
导言 前面说过可以用关联取出服务器相关的一些动态变化的信息,前面也提过web_reg_save_param中可以设置ord=all,代表从服务器中取出的是一个数组,它试用的场景是当我访问一个发帖网站, ...
- LoadRunner脚本篇
LoadRunner脚本篇 1概述 2脚本录制 3脚本编写 4脚本调试 关 键 词:LoadRunner 性能测试脚本 摘 要:编写一个准确无误的脚本对性能测试有至关重要的意 ...
- Loadrunner下载脚本
由于最近又在SGM做性能测试,扒拉出一篇去年5.6月份的一个脚本. 最近写的翻来看看其实也蛮简单的,还是就不放博客了. Action(){ //定义文件大小 int flen; //定义响应数据内容大 ...
随机推荐
- python 循环结构
for循环 list或tuple可以表示一个有序集合.如果我们想依次访问一个list中的每一个元素呢?比如 list: L = ['Adam', 'Lisa', 'Bart'] print L[0] ...
- iOS swift版本无限滚动轮播图
之前写过oc版本的无限滚动轮播图,现在来一个swift版本全部使用snapKit布局,数字还是pageConrrol样式可选 enum typeStyle: Int { case pageContro ...
- 华为终端-新浪微博联合创新,3D建模+AR 成就全新社交体验
近日,全球首款搭载3D感知摄像头的手机华为Mate 20发布. 通过Mate 20自带的景深摄像头及麒麟980的NPU加速能力,手机能够在获取物体表面信息后,完成高速的精细化3D建模. 那么,如何让3 ...
- 我的 Android 开发实战经验总结
我的 Android 开发实战经验总结 字数4440 阅读5137 评论43 喜欢250 曾经一直想写一篇总结 Android 开发经验的文章,预计当时的我还达不到某种水平,所以思路跟不上,下笔又捉襟 ...
- scp -P 非22端口拷贝
scp 远程拷贝非22端口的服务器文件的方法:上传文件到服务器scp -P 29966 /Users/ianMac/Desktop/progit.zh.pdf root@远程ssh服务器的ip:/ho ...
- 【实用】如何在windows下快速截图?
如何在windows下快速截图? 快速截图是很多人的需求.截图的工具和方案也很多,但是,这里给出一个通用的,被大众认为最高效的一个解决方案. 我们都知道键盘上有一个"prt sc" ...
- spring cloud与K8S
链接:https://www.zhihu.com/question/50806354/answer/139653085 spring cloud +docker 当然没有问题,只是当我们搭建集群实现高 ...
- java中.currentTimeMillis的用法和含义
用法:可以用法获取当前时间的毫秒数,可以通过毫秒数进行时间比较,时间转化以及时间格式化等.public class SystemTime {public static void main(String ...
- 页面加载,使用ajax查询某个类别,并且给它们添加(拼接)连接
直接上代码 $(function(){ var a = ''; $.get("productType1_findAll.action",function(data){ consol ...
- sql 分组后查询最大所有列信息
CREATE TABLE students (course varchar(10), stu_name varchar(10), city varchar(10), score int ) inser ...