JMeter上载具有jmx文件相对路径的文件 [英] JMeter upload file with relative path from the jmx file

查看:469
本文介绍了JMeter上载具有jmx文件相对路径的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在JMeter中创建一个HTTP请求采样器,以自动将文件上传到http服务.有没有办法将随请求一起发送文件"中的文件路径"设置为从jmx文件位置开始的相对路径?

I am creating a HTTP Request Sampler in JMeter to automate uploading file to a http service. Is there a way to set the "File Path" in the "Send Files With the Request" to a relative path from the location of the jmx file?

推荐答案

是. (已在JMeter v2.9中确认)

Yes. (This was confirmed in JMeter v2.9)

您可以在文件名输入字段中使用以下BeanShell表达式:

You can use the following BeanShell expression in the filename input field:

${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}<YOUR FILENAME HERE>

因此,如果您的文件" upload.jpg "与JMX测试文件位于同一文件夹中,则完整值应为

So if your file, "upload.jpg" was located in the same folder as your JMX test file, the complete value would be

${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}upload.jpg

为使其更简洁,请添加一个用户定义的变量"配置元素,在其中将表达式的基数分配给变量,例如

To keep it a bit cleaner, add a "User defined variables" config element where you assign the base of the expression to a variable e.g

SCRIPT_PATH = ${__BeanShell( ...etc

然后,您的文件路径输入值将更易读:

Then your file path input value would read a more readable:

${SCRIPT_PATH}upload.jpg

这篇关于JMeter上载具有jmx文件相对路径的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆