te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - In JMeter and BeanShell, how can I make a variable lowercase? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - In JMeter and BeanShell, how can I make a variable lowercase? - Stack Overflow

programmeradmin3浏览0评论

In JMeter's User Parameters, how can I make a variable lowercase?

Left column

my_lowercase_variable

Right column

${__BeanShell('${my_variable}'.toLowerCase())}  //fails

or

${__javaScript('${my_variable}'.toLowerCase())}  //fails

Such that ${my_lowercase_variable} is lowercase of ${my_variable}. Tried with quote and without and escaping and such. No luck. Any tricks or tips wele.

In JMeter's User Parameters, how can I make a variable lowercase?

Left column

my_lowercase_variable

Right column

${__BeanShell('${my_variable}'.toLowerCase())}  //fails

or

${__javaScript('${my_variable}'.toLowerCase())}  //fails

Such that ${my_lowercase_variable} is lowercase of ${my_variable}. Tried with quote and without and escaping and such. No luck. Any tricks or tips wele.

Share Improve this question edited May 25, 2011 at 18:17 Jason Plank 2,3365 gold badges32 silver badges40 bronze badges asked Jan 21, 2011 at 4:11 sf2ksf2k 6022 gold badges7 silver badges25 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 3

Note to self.

It turns out to be a two liner in BeanShell Sampler rather than a __BeanShell mand. Not exactly in the examples unfortunately.

I added the BeanShell Sampler under the Thread Group, then made a variable. No parameters in the form were required only the two liner script below. As long as I don't change the variable I can copy the data to another variable, change that instead, and then make a Value reference to that wherever needed.

First define a variable in some User Parameters or such ie:

Name: my_initial_reference 
Value: ITS IN CAPS

Add a Bean Sampler under the User Preferences or definition list (just next, it's not a child process)

Put in:

String blah = "${my_initial_reference}"; // 
vars.put("blah", blah.toLowerCase());  //${blah} = "its in caps" now available

Now under that with Name/Value pairs I can map ${blah} as the value to whatever process name requires it.

Note that the Debug response will still show the initial value in caps but you'll also see blah=its in caps which is what I wanted to use.

Simply can add a function

${__lowercase(${VAL},VALUE)}
${__uppercase(${VAL},VALUE)}

Note: VAL can be correlated or paramiterized value (e.r VAL= TO LOWER or VAL= TO UPPER). We can use this function in beanshell (pre-processor/post-processor/sampler). Jmeter version using (2.6).

Can use it where ever we want in the script as ${VALUE}.

${__javaScript('${foobar}'.toLowerCase())} does work. If the output is ${foobar} instead of desired value, it means that the variable has not been declared

Note that variables are defined only after the "User Defined Variable" ponent has been parsed. Variables cannot be reused within a single "User Defined Variable" ponent e.g.:

The second row in that image will not be able to refer to the variable my_variable in the first row. To be able to refer to the first variable, two "User Defined Variable" ponents is needed. The first variable will be in the first ponent and the second variable in the second one, e.g.:

With that, ${my_lower_case_variable} will successfully be converted into some value.


${__BeanShell("${my_variable}".toLowerCase())} works too. (Note that Bean Shell requires double quotes. The code in your question uses single quotes.)

Another way is to use vars.get:

  • ${__javaScript(vars.get('my_variable').toLowerCase())}

  • ${__BeanShell(vars.get("my_variable").toLowerCase())}

Hmmmm, your bean shell code didn't work for me. The bean shell sampler returned:

Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval  Sourced file: inline evaluation of: ``String blah = AAP;  vars.put("blah", blah.toLowerCase());  //${blah} now availab . . . '' : Typed variable declaration : Void initializer

I added two double quotes to solve it:

String blah = "${my_initial_reference}";
vars.put("blah", blah.toLowerCase());  //${blah} now available

The beanshell and JavaScript functions in this use will fail, because they don't import the packages you need in order to use .toLowerCase.

If you really need to use a function to convert case (rather then declaring them as lowercase in the first place), you may need to write a full beanshell post-processor script in order to import the needed packages.

  • http://jmeter.apache/usermanual/functions.html#__BeanShell
  • http://jmeter.apache/usermanual/functions.html#__javaScript
  • http://www.javadocexamples./java_examples/org/apache/jmeter/

var blah = "${my_initial_reference}";

blah.toLowerCase();

发布评论

评论列表(0)

  1. 暂无评论