Jmeter的预处理器主要是用来在采样器(sample)被执行之前做一些额外的工作,比如参数化等等。

本文写一个例子来说明如何增加一个预处理器,需求如下:我们想在执行采样器前读取Excel文件中的数据作为参数,此预处理器可以配合While循环控制器使用,每次循环读取excel中的一行数据。

@GUIMenuSortOrder(5)
public class ExcelDataPreProcessor extends AbstractTestElement implements
Cloneable, PreProcessor, TestBean {
private static final Logger log = LoggerFactory
.getLogger(ExcelDataPreProcessor.class); private String filename = ""; // file to source (overrides script) private static final long serialVersionUID = 233L; @Override
public void process() {
//做你想做的一些逻辑
System.out.println(this.getFilename());
} public String getFilename() {
return filename;
} public void setFilename(String filename) {
this.filename = filename;
} @Override
public Object clone() {
return super.clone();
}
}

2、写一个对应的Bean

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/ package org.apache.jmeter.modifiers; import java.beans.PropertyDescriptor;
import java.util.ResourceBundle; import org.apache.jmeter.testbeans.BeanInfoSupport;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jmeter.testbeans.gui.FileEditor; public class ExcelDataPreProcessorBeanInfo extends BeanInfoSupport { public ExcelDataPreProcessorBeanInfo() {
this(ExcelDataPreProcessor.class,null);
} public ExcelDataPreProcessorBeanInfo(Class<? extends TestBean> beanClass, String[] languageTags) {
this(beanClass, languageTags, null);
} protected ExcelDataPreProcessorBeanInfo(Class<? extends TestBean> beanClass, String[] languageTags, ResourceBundle rb) {
super(beanClass);
PropertyDescriptor p; p = property("filename"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p.setPropertyEditorClass(FileEditor.class); createPropertyGroup("filenameGroup", // $NON-NLS-1$
new String[] { "filename" }); // $NON-NLS-1$ } }

这个是描述界面布局和相关元素的的

3,在saveservice.properties文件中增加配置:

ExcelDataPreProcessor=org.apache.jmeter.modifiers.ExcelDataPreProcessor
4、增加一个(ExcelDataPreProcessorResources.properties)多语言支持:

Jmeter ExcelDataPreProcessor的更多相关文章

  1. jmeter之线程组的使用

    线程组 在使用jmeter性能测试时,我们都得先添加个线程组,右键testplan-->添加-->Threads-->线程组.在线程组下执行. 问题:为了能够让jmeter在做性能测 ...

  2. 从Fiddler抓包到Jmeter接口测试(简单的思路)

    备注:本文为博主的同事总结的文章,未经博主允许不得转载. Fiddler下载和配置安装 从网上下载fiddler的安装包即可,直接默认,一直点击下一步,直至安装完成. 安装完成后直接打开Fiddler ...

  3. Jmeter正则表达式

    Jmeter正则表达式 文章转自:http://www.cnblogs.com/jamesping/articles/2252675.html 正则表达式可以帮助我们更好的描述复杂的文本格式.一旦你描 ...

  4. Jmeter安装与环境部署

    Jmeter安装与环境部署 版权声明:本文为博主原创文章,未经博主允许不得转载. 博主:海宁 联系:whnsspu@163.com

  5. JMeter压力测试

    Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试但后来扩展到其他测试领域. 它可以用于测试静态和动态资源例如静态文件. ...

  6. 压力测试之badboy和Jmeter的简单使用方法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 所谓压力测试是指,通过确定一个系统的瓶颈或者不能接收的性能点, ...

  7. 用jmeter通过ssl验证访问https

    找了一个支付宝的网站尝试.https://memberprod.alipay.com/account/reg/index.htm 我用的是chrome,点这个小锁 如果是IE也可以在网页上右键,属性, ...

  8. JMeter使用文档

    JMeter使用文档 1.JMeter安装步骤 1.1Windows环境 a.安装jdk(对应windows系统位数) http://www.oracle.com/technetwork/java/j ...

  9. jmeter之连接mysql和SQL Server配置

    下载jdbc驱动 在使用jmeter做性能或自动化测试的时候,往往需要直接对数据库施加压力,或者某些参数只能从数据库获取,这时候就必须使用jmeter连接数据库. 1.下载对应的驱动包 mysql驱动 ...

随机推荐

  1. POJ3417Network

    Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5311   Accepted: 1523 Descripti ...

  2. 一步一步学RenderMonkey

    http://blog.csdn.net/tianhai110/article/details/5668832 转载请注明出处:http://blog.csdn.net/tianhai110/ 网上一 ...

  3. BZOJ1636&&1699:[USACO2007JAN]Balanced Lineup

    浅谈\(RMQ\):https://www.cnblogs.com/AKMer/p/10128219.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...

  4. python中http的一些编码转换

    http的数据需要2种编码解码. 1. url中的特殊字符转换, 比如",', :,//等 python3中通过urllib.parse.quote(..)和urllib.parse.unq ...

  5. ES6学习之Proxy

    定义:“代理器”,用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”(meta programming),即对编程语言进行编程.可以对外界的访问进行过滤和改写. 语法: va ...

  6. HTML5 中文乱码

    <meta charste="utf-8"> 只是告诉浏览器要用utf-8来解释,而文档的编码,是在你保存时的选择决定的.如果保存ANSI 然后用utf-8解释,肯定是 ...

  7. Unity编辑器的扩展:IMGUI

    IMGUI 介绍 所有关于 Editor 的相关 UI,包括 Inspector.Hierarchy.Window.Game 视图上动态创建的那些半透明 UI.还有 Scene 视图上可添加的辅助显示 ...

  8. Spring IOC 少

    控制反转好处 IOC:控制反转也叫依赖注入,IOC利用java反射机制,AOP利用代理模式.所谓控制反转是指,本来被调用者的实例是有调用者来创建的,这样的缺点是耦合性太强,IOC则是统一交给sprin ...

  9. hdu1099

    #include<iostream> using namespace std; __int64 gcd(__int64 a,__int64 b) { return b?gcd(b,a%b) ...

  10. 经典DP 嵌套矩形 (南洋理工ACM—16)

    本来是个很水的DP,结果被自己的代码习惯给打败了 代码: #include<iostream> #include<stdlib.h> #include<string.h& ...