loadrunner字符串处理函数

news/2024/8/26 3:49:43 标签: loadrunner, string, action, search, output, buffer
 在Loadrunner中提供了C对字符串出了的相关功能函数,如下:

lr_save_datetime

把当前日期和时间保存到一个参数中

lr_save_int

把一个整数保存为参数

lr_save_searched_string

保存一个字符数组相对于字符串出现的部分。

lr_save_string

把一个字符串保存到参数中

lr_save_var

把字符串的一部分内容保存为参数

lr_eval_string

返回参数的实际内容或返回一个包含参数的字符串的实际内容

     下面我们将对这些函数作一一说明,并举例实践。

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

参数解释: 

format

所检索的日期/时间信息的格式

offset

当前日期和时间的偏移量, 采用形式有: DATE_NOW, TIME_NOW, ONE_DAY, ONE_HOUR, ONE_MIN. 例如: TIME_NOW + ONE_HOUR

name

保存的参数名称,用来存储日期/时间信息。

例子:

  
Action() { lr_save_datetime( " Tomorrow is %B %d %Y " , DATE_NOW + ONE_DAY, " next " ); lr_output_message(lr_eval_string( " {next} " )); return 0 ; }

运行结果为:

Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(5): Tomorrow is 七月 06 2011
Ending action Action.
Ending iteration 1.
Ending Vuser...

int lr_save_int ( int value, const char *param_name);

参数解释: 

value

将要保存到参数得整数值

param_name

保存的参数名称

例子:

  
Action() { int num; num = 5 ; lr_save_int(num * 2 , " param1 " ); lr_output_message(lr_eval_string( " {param1} " )); return 0 ; }

运行结果为:

Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(6): 10
Ending action Action.
Ending iteration 1.
Ending Vuser...

int lr_save_searched_string (const char *buffer, long buf_size, unsigned int occurrence, const char *search_string, int offset, unsigned int string_len, const char *parm_name );

参数解释:

buffer

The STRING or CARRAY buffer, part of whose contents you want to save.

buf_size

The buffer size.

occurrence

The occurrence number of the search_string (0-based count). For example, if the search_string occurs three times, and you want the second occurrence, set occurrence to 1.

search_string

The string to search for in the buffer.

offset

The number of characters to skip after the end of the search string occurrence.

string_len

The number of characters to save.

parm_name

Parameter name to be used in subsequent lr statements to refer to the saved information. Name is enclosed in double-quotes.

例子:

  
Action() { char cBuff[] = " abc Emma Woodhouse abc Elizabeth Bennet abc William Price " ; lr_save_searched_string(cBuff, strlen(cBuff), 2 , " abc " , // Search for third occurrence of "abc" 1 , // Skip the space after "abc" 4 , // Put the next four characters... " Fannys_brother " ); // ... in parameter Fannys_brother. lr_output_message( " %s " ,lr_eval_string( " Fannys_brother={Fannys_brother} " )); return 0 ; }

运行结果为:

Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(9): Fannys_brother=Will
Ending action Action.
Ending iteration 1.
Ending Vuser...

int lr_save_string (const char *param_value, const char *param_name);

int lr_save_var (const char *param_value, unsigned long const value_len, unsigned long const options, const char *param_name);

char *lr_eval_string (const char *instring );

     以上三个函数我们经常会用在一起。例如:

例子:

  
Action() { lr_save_string( " testaaaab " , " InName " ); lr_output_message( " %d " ,strlen( " {InName} " )); lr_output_message( " %d " ,strlen( " {InName} " ) - 1 ); lr_save_var( lr_eval_string( " {InName} " ), strlen( " {InName} " ) - 1 , 0 , " ShortName " ); lr_output_message( " %s " ,lr_eval_string( " ShortName={ShortName} " )); lr_output_message( " ShortName=%s " ,lr_eval_string( " {ShortName} " )); return 0 ; }

Starting iteration 1.
Starting action Action.
Action.c(5): 8
Action.c(6): 7
Action.c(9): ShortName=testaaa
Action.c(10): ShortName=testaaa
Ending action Action.
Ending iteration 1.

      *****注:在loadrunner中,字符串处理函数用的比较多,其用法也比较简单。多加以练习操作,在项目实践中可以很快的做到得心应手。*****


http://www.niftyadmin.cn/n/656015.html

相关文章

LoadRunner关联常用函数的学习

原文地址:LoadRunner关联常用函数的学习 [转帖]作者:Cheers_Lee我先声明一下,本文是转帖的,自己看完后觉得很不错,所以转过来和大家分享,一起学习。 原帖地址:http://www.51testing.com/?34866/action_vie…

MVC5 + EF6 完整入门教程三

原文:https://www.cnblogs.com/miro/p/4053473.html 期待已久的EF终于来了。 学完本篇文章,你将会掌握基于EF数据模型的完整开发流程。 本次将会完成EF数据模型的搭建和使用。 基于这个模型,将之前的示例添加数据库查询验证功能。 文章提纲 概…

linux的系统监视器图片_深度操作系统(2020.08.06)更新发布

深度系统更新,欢迎大家升级体验!1关于新版本号规则的说明从本次版本发布开始,版本号将采取公司统一命名规范,采用大版本号(小版本号)的方式,例如:20(1000)、20(1010)等,之后 alpha、beta、rc 将…

js_求1—10000的完数

// 1-10000以内的完数 // 完数&#xff1a;因子之和相加等于这个数 // 例如&#xff1a;6的因子为1&#xff0c;2&#xff0c;3&#xff1a;1236let i ,j; let sum ; for(i1;i<10000;i){sum 0;for(j1;j<i;j){if(i%j 0){sum j;}}if(i sum){console.log(i)} } 转载于:ht…

python开发的著名网站_python开发著名网站_python开发的著名软件 - CSDN

根据权威机构统计,每日Python人才需求高达5000 ,但目前很少有程序员知道Python在市场中,竞争小,很容易得到快速和高薪就业。也许你不太了解十大Python常用的开发工具,现在我将告诉你。PythonMicro Python是基于ANSI C的语法Pyton 3,基本上是一样的,它有自己的解析器,编译器,虚拟…

bash: ifconfig: command not found 解决办法

转自&#xff1a; http://gardenyuan.iteye.com/blog/1001970 原本使用ifconfig 可以使用&#xff0c;今天是怎么了&#xff0c;可能安装软件修改了&#xff0c;百度~~ [oraclelocalhost /]$ ifconfig 提示&#xff1a;“bash: ifconfig: command not found” 于是我切换到root…

[SDOI2010] 地精部落 (DP+组合)

一句话题意 给定1到n求其全排列中没有三个及以上递增&#xff08;减&#xff09;的方案数&#xff0c;ans%p&#xff08;p不一定为素数&#xff09; 错误打法一 我看到这道题后首先想到的是容斥&#xff1a; ans全排列-至少3个不满足的至少4个...... 但是考虑不到有两个不连续的…

Ubuntu 配置docker镜像加速器

1. 安装&#xff0f;升级Docker客户端 推荐安装1.10.0以上版本的Docker客户端&#xff0c;参考文档 docker-ce 2. 配置镜像加速器 针对Docker客户端版本大于 1.10.0 的用户 登录阿里云 搜索镜像加速 获取自己的专属地址 您可以通过修改daemon配置文件/etc/docker/daemon.json来…