How to set JMeter Vars from within WebDriver Sampler?

后端 未结 4 1172
囚心锁ツ
囚心锁ツ 2021-01-21 15:25
// I had previously used a CSS/JQuery extractor to get a URL from a page and add it to JMeter vars - accessing it here
var pageURL = \"${valueFromJmeterVars}\";

// navi         


        
相关标签:
4条回答
  • 2021-01-21 15:34

    It won't work because 'vars' in not defined in WebDriver Sampler as in for instance BeanShell Sampler.

    0 讨论(0)
  • 2021-01-21 15:43

    You can access JMeter API classes from within the WebDriver Sampler, it's implemented as JSR 223 standard for instance you can refer JMeter Variables (aka vars as follows)

    In the WebDriver Sampler:

    var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
    var vars = ctx.getVariables();
    
    vars.put('foo','bar')
    

    Now you have ${foo} variable with the value of bar

    See The WebDriver Sampler: Your Top 10 Questions Answered guide for more WDS sampler tips and tricks.

    0 讨论(0)
  • 2021-01-21 15:43

    There isn't a clean way to do this, but it is possible. You can set the response headers in your WebDriver sampler:

    WDS.sampleResult.setResponseHeaders(reserveASpotButton.isEnabled())
    

    Then you can use a regular expression extractor to pull the data from the response headers.

    0 讨论(0)
  • 2021-01-21 15:56

    I believe that you need to cast it to String first, as per Using Selenium with JMeter's WebDriver Sampler guide JMeter Variables are basically Strings and you can't put boolean there.

    just replace

    vars.put("reserveASpotButtonIsEnabled", reserveASpotButton.isEnabled());
    

    with

    vars.put("reserveASpotButtonIsEnabled", reserveASpotButton.isEnabled().toString());
    

    And it should work.

    0 讨论(0)
提交回复
热议问题