【问题标题】:Testing load document functionality with JMeter使用 JMeter 测试加载文档功能
【发布时间】:2011-11-08 05:45:50
【问题描述】:

我正在测试具有“加载文档”功能的服务。我需要为每个请求发送一个独特的文档。在 HTTP 请求采样器配置菜单中,我看到我可以随请求一起发送文档。但是,我不知道如何为每个请求发送不同的文档。有没有办法让 JMeter 稍微修改一个文档,生成一个指定的文档,或者甚至可以选择一系列外部生成的文档来提交请求?

【问题讨论】:

    标签: java testing jmeter


    【解决方案1】:

    您可以使用 While Controller 下的 CSV Data Set Config 循环读取和发送预先创建的测试文档名称。

    这看起来像:

    1. 创建不同测试文档的集合以随您的请求一起发送;
      可选:将创建文档的文件夹路径存储为 jmeter 变量 - 在脚本中使用;
    2. 创建测试文档列表;
      您可以使用如下所示的代码在 BeanShell Sampler 中执行此操作;
    3. 添加While Controller循环发送测试文档;
      CSV Data Set Config to While Controller as child - 从列表中读取测试文档名称。

    详细说明:

    ${__javaScript("${testFile}"!="<EOF>",)} - 读取列表直到文件末尾

    BeanShell Sampler 代码生成测试文件列表:

    import java.text.*;
    import java.io.*;
    import java.util.*;
    
    String [] params = Parameters.split(",");
    
    String contentList = params[0];
    String testDataDir = params[1];
    
    File dir = new File(System.getProperty("user.dir") + File.separator + testDataDir);
    BufferedWriter out = null;
    
    try {
    
        if (!dir.exists()) {
            throw new Exception ("Directory " + dir.getName() + " not found.");
        }
    
        File contentFile = new File(System.getProperty("user.dir") + File.separator + contentList);
    
        if (contentFile.exists()) {
            contentFile.delete();
        }
    
        FileWriter fw = new FileWriter(contentFile, true);
        out = new BufferedWriter(fw);
    
        System.out.println("\n--------------------------------------------------------------------------------------");
        System.out.println("CONTENT LIST:\n");
    
        if ((dir.exists()) && (dir.listFiles() != null) && (out != null)) {
            for (File f : dir.listFiles()) {
                if (contentFile.length() == 0) {
                    out.write(f.getName());
                } else {
                    out.write("\n" + f.getName());
                }
    
                out.flush();
    
                System.out.println("Content " + f.getName() + " added to " + contentFile.getName() + ".");
            }
        }
    
        System.out.println("--------------------------------------------------------------------------------------\n");
    }
    catch (Exception ex) {
        IsSuccess = false;
        log.error(ex.getMessage());
        System.err.println(ex.getMessage());
    }
    catch (Throwable thex) {
        System.err.println(thex.getMessage());
    }
    finally {
        out.close();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      相关资源
      最近更新 更多