如何在jmeter中将动态值传递给url

时间:2016-05-12 07:17:19

标签: jmeter performance-testing

我必须为url提供动态值,其中包含用户数量及其年龄,可以通过网页选择。但是我希望使用override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if(indexPath.section == 1) { tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .Checkmark } } override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { if(indexPath.section == 1) { tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .None } } Jmeter中提供。 请帮助我,因为我是BeanShell PostProcessor的新手。

这是路径:

  

器/目的地/包机场%5B%5D = LGW&安培;单位%5B%5D = 000577%3ADESTINATION&安培;当= 29-05-2016&安培;直到=安培;灵活性=真安培; flexibleDays = 3及的 noOfAdults = 2及noOfSeniors = 0&安培; noOfChildren = 1&安培; childrenAge = 3 &安培;持续时间= 7114&安培;第一= 0&安培;检索类别=搜索&安培; searchRequestType =插件&安培; SP =真安培; MULTISELECT =真

2 个答案:

答案 0 :(得分:1)

从我看来你可以使用CSV数据集配置。

  1. 使用您要为其提供测试的数据创建.txt文件;
  2. 将上述.txt文件放在.jmx文件所在的文件夹中;
  3. 在您的测试计划中:根据您的请求采样器 - 放置CSV数据集配置; enter image description here
  4. 然后,如果您需要在一个threadgroup中使用您的动态值=>在您的网址中将这些数据称为 $ {quanity} $ {age}

    如果您需要在threadgroups =>中传递这些值添加BeanShell断言 enter image description here

    然后(在另一个Tread组中)将这些引用为 $ {__ property(_quantity)} $ {__ property(_age)}

    希望,这有帮助。

答案 1 :(得分:0)

  1. 首先,您需要Beanshell PreProcessor,而不是Beanshell PostProcessor。
  2. 所有这些参数基本上都是名称/值对,可以通过HTTPSamplerBase类定义。 HTTPSamplerBase类实例可作为sampler预定义变量用于Beanshell PreProcessor,因此如果将以下代码添加到Beanshell PreProcessor" Script"区域

    sampler.addEncodedArgument("airports[]","LGW");
    sampler.addEncodedArgument("units[]","000577:DESTINATION");
    sampler.addEncodedArgument("when","29-05-2016");
    sampler.addEncodedArgument("until","");
    sampler.addEncodedArgument("flexibility", "true");
    sampler.addEncodedArgument("flexibleDays","3");
    sampler.addEncodedArgument("noOfAdults","2");
    //etc
    

    您的HTTP请求将使用您通过Beanshell设置的值填充。

  3. JMeter变量可以通过vars简写来表示,它代表JMeterVariables类实例。

    String airport = vars.get("airport");
    sampler.addEncodedArgument("airports[]", airport);
    //etc
    

    有关如何在Jmeter中使用Beanshell测试元素的全面信息,请参阅How to Use BeanShell: JMeter's Favorite Built-in Component文章。

    请记住,建议尽可能避免编写脚本,以便有其他方法来实现您的任务 - 去吧。