Search code examples
jmeterjmeter-plugins

How to user variable form webdriver sampler in HTTP Header Manager


I am able to extract auth_key from session storage .

I want load an API with auth_key in HTTP Header Manager

How can this be done.

var foo = WDS.browser.executeScript("return window.sessionStorage.getItem('ngStorage-jwtToken');")       
var obj = JSON.parse(foo);
vars.put("auth",obj.oauth_token)
WDS.log.info(vars.get('auth'))

And I want to use auth as global variable to access on all threads.


Solution

    1. Replace this line:

      vars.put("auth",obj.oauth_token)
      

      with this one:

      WDS.vars.put("auth",obj.oauth_token)
      
    2. Add HTTP Header Manager as a child of the request which header you need to amend and configure it like:

      JMeter HTTP Header Manager

    See General Concepts section of the WebDriver Sampler user manual entry to learn what pre-defined variables are available for the scripting.