zoukankan      html  css  js  c++  java
  • loadrunner字符串处理函数

         在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.cnblogs.com/Automation_software/ 只求在IT界有一个清闲的世界让我静心的去专研,不求功名利禄,只为心中的那份成就感及自我成长、自我实现的快感。
  • 相关阅读:
    C#yield return用法示例
    C#多线程示例
    AspNetCore.Authentication
    C#委托与事件
    按值和按引用传递参数
    基于iView的无限级菜单
    Sortable By Attribute
    未能加载文件或程序集“BLL”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。
    有关导出Excel特殊字符的问题
    openFileDialog的使用
  • 原文地址:https://www.cnblogs.com/Automation_software/p/2098688.html
Copyright © 2011-2022 走看看