Search code examples
karate

karate - var in * configure headers don't work


I'm trying to add var in * configure headers but it doesn't work.

If i write :

Given header Authorization = 'JWT '+setup.token
Given header Accept = 'application/json'
Given header Content = 'multipart/form-data'

it works so good ! BUT ! I want to put all "header" in * configure headers like this :

* configure headers =     
"""       
{         
'Content-Type': 'multipart/form-data',         
'Authorization': 'JWT #(setup.token)',         
'Accept': 'application/json'       
}     
"""

in this case setup.token is not interpreted and return 1 > Authorization: JWT #(setup.token) in GET method

However, the syntax required to interpret a variable is that of the documentation. Could you help me because I can’t figure out how to pass this variable into the code ?

Thank you ;-)



Solution

  • There is a rule for embedded expressions: https://github.com/karatelabs/karate#rules-for-embedded-expressions

    So make this change (or use an intermediate variable):

    * configure headers =     
    """       
    {         
    'Content-Type': 'multipart/form-data',         
    'Authorization': "#('JWT ' + setup.token)",         
    'Accept': 'application/json'       
    }     
    """