Unplanned
Last Updated: 11 Jan 2018 14:13 by ADMIN
Rob
Created on: 10 Jan 2017 21:47
Type: Feature Request
1
creating variable from two body elements
I have a webapi service that returns an authorization type and token. I would like to be able to create an authToken variable that has "TokenType Token" i.e. Bearer bearerTokenValue====. If I try to do $.TokenType $.Token, it gives me an error.
1 comment
ADMIN
Oleg
Posted on: 11 Jan 2017 09:54
Hi Rob,

Thanks for the feedback. You can currently achieve that if you use two separate consecutive "Set Variable" steps - one to set a "token-type" variable (with the "$.TokenType" JSONPath expression only), and the other one to set a "token-value" variable (with the "$.Token" expression respectively). Later you can combine both variables by using them where needed as: "{{token-type}} {{token-value}}". If you do not want to repeat the full "{{token-type}} {{token-value}}" expression everywhere you need the token, you may define a third variable by adding it directly in the Variables pane, for example label it "full-token" with value "{{token-type}} {{token-value}}" (notice the space between both). This way in your test steps you can create for example a header like this: "Authorization: {{full-token}}".

I agree, that it would be easier to just create a complex expression (like "$.TokenType $.Token"), thus creating a compound variable, but currently the JSONPath field in Set Variable steps accepts just a single expression (the same way as the Source field accepts only a single variable reference. I am not sure what would be the best approach to this, but we will definitely put some thought on this since users would often need to mix an extracted value with some predefined constants or mix multiple extracted values. Any feedback and preferences in this regard would be appreciated.