运行Jmeter脚本时获取Transformer异常

时间:2016-09-23 18:21:57

标签: xpath jmeter

在运行带有3个线程的JMeter脚本时,加速5秒我得到转换器异常。实际上在我的场景中我想随机点击页面的多个链接,所以我在JMeter中使用了随机变量但是在运行之后,我得到了以下错误,但是,XPath提取器中的XPath表达式看起来很好。

2016/09/23 23:44:03 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2016/09/23 23:44:03 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2016/09/23 23:44:03 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2016/09/23 23:44:03 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 
2016/09/23 23:44:03 INFO  - jmeter.engine.StandardJMeterEngine: Starting 3 threads for group Thread Group. 
2016/09/23 23:44:03 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2016/09/23 23:44:03 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 3 ramp-up 5 perThread 1666.6666 delayedStart=false 
2016/09/23 23:44:03 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
2016/09/23 23:44:03 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2016/09/23 23:44:03 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2016/09/23 23:44:05 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-2 
2016/09/23 23:44:07 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-3 
2016/09/23 23:44:09 WARN  - jmeter.extractor.XPathExtractor: TransformerException while processing ((//span[@class="title"]/a/@href)[$(RandomNumber)]) Expected ], but found: RandomNumber 
2016/09/23 23:44:10 INFO  - jmeter.threads.JMeterThread: Thread is done: Thread Group 1-1 
2016/09/23 23:44:10 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 
2016/09/23 23:44:10 WARN  - jmeter.extractor.XPathExtractor: TransformerException while processing ((//span[@class="title"]/a/@href)[$(RandomNumber)]) Expected ], but found: RandomNumber 
2016/09/23 23:44:11 INFO  - jmeter.threads.JMeterThread: Thread is done: Thread Group 1-3 
2016/09/23 23:44:11 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-3 
2016/09/23 23:44:11 WARN  - jmeter.extractor.XPathExtractor: TransformerException while processing ((//span[@class="title"]/a/@href)[$(RandomNumber)]) Expected ], but found: RandomNumber 
2016/09/23 23:44:12 INFO  - jmeter.threads.JMeterThread: Thread is done: Thread Group 1-2 
2016/09/23 23:44:12 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-2 
2016/09/23 23:44:12 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2016/09/23 23:44:12 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)  

1 个答案:

答案 0 :(得分:3)

  1. JMeter Variables被引用为${RandomNumber} - 您需要使用大括号而不是括号。或者,您可以使用__V()功能,如

    ${__V(RandomNumber)}
    

    因此,您需要将XPath查询更改为以下之一:

    • (//跨度[@类= “标题”] /一个/ @ HREF)[$ {RandomNumber}]
    • (// span [@ class =“title”] / a / @ href)[$ {__ V(RandomNumber)}]
  2. 你的方法似乎很脆弱。我不知道页面上有多少链接以及如何生成${RandomNumber}变量,但我宁愿采用以下方式:

    • 将页面上的所有链接存储到JMeter变量中,例如:

      link_1=http://example.com
      link_2=http://jmeter.apache.org
      ...
      link_matchNr=50
      
    • 通过前面提到的__V()__Random()函数组合,使用之前提取的随机JMeter变量,如:

      ${__V(link_${__Random(1,${link_matchNr},)})}
      

    演示:

    JMeter Combining Variables

    有关如何将不同的JMeter函数和变量组合到单个表达式中的更多信息,请参阅Here’s What to Do to Combine Multiple JMeter Variables文章。