`
seawavecau
  • 浏览: 755043 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

VuGen Code Snippets

 
阅读更多

VuGen Code Snippets

This is a repository of code snippets. Please send me any useful sections of code that you have written.

Note that this repository does not contain trivial examples (i.e. something you could learn by looking at the example code in the LoadRunner Online Function Reference – accessed by pressing F1 in VuGen).

Code snippets that have been written as separate Tech Tips:

Writing to a file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Writes a string to the end of a file.
Arguments:
 - file_name: Include the full path in the file name, and escape any slashes. E.g. "C:\\TEMP\\output.txt". Note that file does not have to exist beforehand, but directory does.
 - string: If attempting to write a single line, include a newline character at the end of the string.
Returns 0 on success. On failure, function will raise lr_error_message and return -1.
*/
int jds_append_to_file(char* file_name, char* string) {
  int fp; // file pointer
  int rc; // return code
  int length = strlen(string);
 
  // Check that file_name is not NULL.
  if (file_name == NULL) {
    lr_error_message("Error. File name is NULL");
	return -1;
  }
 
  fp = fopen(file_name, "a"); // open file in "append" mode.
  if (fp == NULL) {
    lr_error_message("Error opening file: %s", file_name);
    return -1;
  }
 
  rc = fprintf(fp, "%s", string);
  if (rc != length) {
     lr_error_message("Error writing to file: %s", file_name);
     return -1;
  }
 
  rc = fclose(fp);
  if (rc != 0) {
    lr_error_message("Error closing file: %s", file_name);
    return -1;
  }
 
  return 0;
}

Check if a file already exists

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Checks if a file already exists on the filesystem.
// Arguments:
//  - file_name: Include the full path in the file name. 
// Returns TRUE (1) if file exists and user has read access to the file, otherwise function returns FALSE (0).
int jds_file_exists(char* file_name) {
  int fp; // file pointer
 
  fp = fopen(file_name, "r+"); // open file in read mode. File must already exist.
  if (fp == NULL) {
    return FALSE;
  } else {
    fclose(fp);
    return TRUE;
  }
}

Saving a file to the hard disk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Saves a file to the hard disk.
// Arguments:
// - file_name: Include the full path in the file name. Note that file must not exist before function is called.
// - file_content: The data to save to the file. Can be binary or string data.
// - file_size: The size/length of the data to save to the file. If it is string data, you can find this using strlen(). If you are saving binary data from a web page, use web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE).
// Returns 0 on success. On failure, function will raise lr_error_message and return -1.
int jds_save_file(char* file_name, void* file_content, unsigned int file_size) {
  int rc; // function return code
  int fp; // file pointer
 
  // Check input values
  if (file_name == NULL) {
    lr_error_message("File name is NULL");
    return -1;
  } else if (file_content == NULL) {
    lr_error_message("File content is NULL");
    return -1;
  } else if (file_size < 1) {
    lr_error_message("Invalid file size: %d", file_size);
    return -1;
  }
 
  // Does the file already exist?
  if (jds_file_exists(file_name) == TRUE) {
    lr_error_message("File %s already exists", file_name);
    return -1;
  }
 
  fp = fopen(file_name, "wb"); // open file in "write, binary" mode.
  if (fp == NULL) {
    lr_error_message("Error opening file: %s", file_name);
    return -1;
  }
 
  rc = fwrite(file_content, file_size, 1, fp);
  if (rc != 1) {
    lr_error_message("Error writing to file. Items written: %d", rc);
    return -1;
  }
 
  rc = fclose(fp);
  if (rc != 0) {
    lr_error_message("Error closing file: %s", file_name);
    return -1;
  }
 
  return 0;
}

Saving a binary file from a webpage (like a PDF or a GIF). Note that this is not a good way to veryify that your LoadRunner/BPM script is running successfully.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Action()
{
  int size;
  char* file = "C:\\TEMP\\test.zip";
 
  // Make this big enough to hold the downloaded file. 
  web_set_max_html_param_len("1048576"); // 1 MB
 
  // Save entire HTTP response body
  web_reg_save_param("FileContents",
    "LB/BIN=",
    "RB/BIN=",
    "Search=Body",
    LAST);
 
  // Note that it is best to use web_custom_request, as this guarantees that only one file is being downloaded by this step.
  web_custom_request("DownloadPlugin", 
    "URL=http://www.example.com/files/test.zip", 
    "Method=GET", 
    "Resource=1", 
    "RecContentType=text/css", 
    "Referer=http://www.jds.net.au", 
    "Snapshot=t1.inf", 
    LAST);
 
  // returns the size of the previous HTTP response
  size = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
 
  jds_save_file(file, lr_eval_string("{FileContents}"), size);
 
  return 0;
}
<!-- No related posts. -->
<!-- AddThis Bookmark Post Button BEGIN -->
分享到:
评论

相关推荐

    LoadRunner中VuGen录制原理

    LoadRunner中VuGen录制原理 LoadRunner中的VuGen录制原理是指LoadRunner性能测试工具中的一种录制机制,该机制能够模拟用户的操作行为,将用户的操作行为转换为可重复的脚本,以便于对服务器的性能进行评估和测试。...

    LoadRunner register_vugen.bat批处理文件

    `register_vugen.bat`是一个批处理文件,主要功能是用于重新注册LoadRunner中的Virtual User Generator(VUGen),VUGen是LoadRunner的重要组件,负责生成性能测试脚本。当遇到VUGen注册问题,如升级、移除再安装或...

    register_vugen.bat

    loadrunner打不开ie,找不到register_vugen.bat文件 ,register_vugen.bat 下载,把register_vugen.bat放到安装的Bin目录下

    LR vugen详细教程

    LoadRunner VuGen(Virtual User Generator)是一款强大的性能测试工具,它广泛应用于软件开发过程中,用于模拟多用户环境,通过录制、编辑和执行脚本的方式,对应用系统进行性能测试。该工具支持多种网络协议,包括...

    register_vugen2019.rar

    首先,我们需要理解"register_vugen2019.rar"是一个压缩包文件,其中包含了关键的批处理文件"register_vugen.bat"。这个批处理文件是专门设计来执行VUGEN的注册过程的。在解压"register_vugen2019.rar"后,我们会在...

    LoadRunner - VuGen

    Mercury 虚拟用户生成器用户指南 虚拟用户生成器(也称为 VuGen)可用于针对各种应用程序类型和通信协议开发 Vuser 脚本。

    loadrunner11 vugen中文手册

    ### LoadRunner 11 Virtual User Generator (VuGen) 中文手册关键知识点 #### 一、LoadRunner VuGen 概述 - **定义**: LoadRunner Virtual User Generator (简称VuGen) 是HP公司(现HPE)开发的一款自动化负载测试...

    LoadRunner VuGen UserGuide.pdf

    ### LoadRunner VuGen知识点概述 #### 一、LoadRunner与VuGen简介 LoadRunner是一款业界广泛使用的性能测试工具,主要用于评估软件系统在高负载下的表现。它能够模拟成千上万个用户同时操作客户端/服务器系统的情景...

    loadrunner11 vugen user guide,controller,analysis中文资料

    《LoadRunner 11:VUGen、Controller与Analysis详解》 LoadRunner是HP公司推出的一款强大性能测试工具,主要用于企业级应用系统的压力测试、负载测试和容量规划。本资料集合了VUGen(虚拟用户生成器)、Controller...

    register_vugen.bat文件,解决lr不能录制问题

    当LR11和QTP安装在同一个XP系统时,往往LR11录制时不能打开IE,即时设置了IE仍不行,此时把register_vugen.bat放到安装的Bin目录下,双击执行,重新进行注册路径后,即可解决问题。

    register_vugen.7z

    LR的系统文件

    LoadRunner VuGen用户指南

    文档讲解了 LoadRunner VuGen板块的使用方法,具体说明了脚本录入与编辑的方法,为负责测试做前提准备。

    loadrunne11之VuGen相关技术

    ### Loadrunner11之VuGen相关技术 #### VuGen总览与录制选项设置 **Loadrunner**是一款由Micro Focus公司推出的性能测试工具,主要用于评估软件系统在压力下的表现。其中,**VuGen**(Virtual User Generator)是...

    register_vugen.bat-for LR高版本安装运行

    高版本LR(LR9、LR10、LR11)安装运行时所需的注册表文件,直接将其拷贝到bin目录即可,欢迎使用!

    HP Virtual User Generator用户指南(11版windows版)

    #### 一、HP Virtual User Generator (VuGen) 概述 **1.1 VuGen 的定义** - **VuGen** 是 HP LoadRunner 的核心组件之一,主要用于创建 Vuser 脚本,即虚拟用户的测试脚本。它通过录制用户在应用中的实际操作来...

    LoadRunner详解(vuser/controller/analysis)之vuser

    - **启动VuGen**:首先启动VuGen,这是一个集成开发环境(IDE),用于创建、编辑和运行Vuser脚本。 - **选择录制协议**:在录制之前,需要根据测试的应用程序类型选择合适的协议。例如,对于Web应用,可以选择...

Global site tag (gtag.js) - Google Analytics