jmeter not write code, the last seconds seconds to extract a dynamic list of values

  • In doing Interface testing jmeter, we often encounter, an interface returns a json string, in this json string, the value of a node is a list, and the length of this list is dynamic. Such as:
     
    A list of users, user information is a list of similar interface, very common in the enterprise, if we do not flip the interface parameters are passed, the length of this list are often not fixed over time.
  • If you just want to get the value of a parameter list of the known position of the index, this is very simple, with a json extractors, or extractor + the specified index number with a positive, can do so extracted.
  • What if you want to extract the value of a parameter list of the last index position, how to do it? Is not it, to use a '1' in the index, you will be able to solve it?
    • Do you also have such a problem? Do you think so too?
    • then......
    • What did you do then? You find yourself with a '1' can not be achieved, you went to Baidu, Baidu tell you, with Beanshell, you write a bunch of incomprehensible 'bible' (java code). You expect a dream come true (because the problem is very simple, the chickens have to spend a chopper), however, the ideal is beautiful, the reality is very backbone of your hard work pay did not get due returns. God, ah, you're not kidding me, a simple question, you get me a full day to individuals, help me to write code Bluff are 'X' it (in this case, you are not complaining).
    • World where we may not meet, are reduced to one ah!
    • But, I might 'Mountain darkly, vista', found a 'tunnel'
  • A parameter value + regular correlation function to obtain a dynamic list of the last index position
    • Value to the extractor out with all the expected positive parameters (such as: I want to extract all id value data list)
       
    • In this case, the debugger sampler, we will see Figure:
       
    • Note that the focus of the figure, there is a 'id_matchNr' = ***, what is it? This is to match the total number of results, that is, this value tells us the number of the list (provided that, the regular expression is not wrong). See a list of the total length, think of what? This value is not directly used as the index list, you can get the last parameter value! Bingo, with ideas, open dry!
    • 关联函数__v, ${__V(id_${id_matchNr})} ${id_matchNr}是得到列表最大值,用一个关联函数,就得到列表最后一个的参数值。 注意: 列子中的’id' 是我们正则提取器中的存储“引用名称”
    • 验证:把关联函数${__V(id_${id_matchNr})},放入你需要的地方,运行后,查看该参数的值,再把列表拷贝出来,搜索看参数值是不是最后一个。
  • 到此,我们就完成了列表最后一个值的提取和使用及验证。

Guess you like

Origin www.cnblogs.com/allening/p/11609178.html