Completed
Last Updated: 03 Jan 2017 11:09 by ADMIN
ADMIN
Alex Fidanov
Created on: 01 Jul 2016 08:56
Type: Feature Request
1
Setting and passing variables
Setting and passing variables is not intuitive. IMO it would be better if variables are set in the context of the current http request - for example next to where you would set validations and conditions. Currently, it is not clear that the body, where the variables come from, is actually the body of the previous request.
8 comments
ADMIN
Valeri Hristov
Posted on: 08 Jul 2016 15:22
Please, find attached a simple demo project that demonstrates how to extract a project-level (global) variable from a HTTP Request and then uses it as a value in a HTTP Header for another request. 

The second request is made to www.httpbin.org, which returns a response body with the same values that were sent as request parameters, including the headers. You could check the Last Response Data in the second HTTP Request and see what has been sent.
Attached Files:
Eugeniy
Posted on: 08 Jul 2016 13:39
Now I can't figure out how to share variable across tests. I tried to set "Target Level" both to "Root" and "Test" and access that variable inside request's header. But it's always null.

I also tried to declare that variable at project level - but during test that variable becomes strike-throught and new variable with the same name appears inside "Project Runtime".

May be it's impossible to use variable inside a header?
Eugeniy
Posted on: 07 Jul 2016 16:55
Thank you, I will try one more time.
ADMIN
Valeri Hristov
Posted on: 07 Jul 2016 15:40
The JSONPath is slightly different than XPath, you could check this article for good comparison between them: http://goessner.net/articles/JsonPath. Our documentation does not contain a lot of information about JSONPath yet, but this will come soon. Another good source of use cases is our demo project, you could check it too.

In short, if I understand your situation correctly, if you have the following Response Body that returns AccessToken:
{
  "Payload": {
    "AccessToken": "asdasdasd"
  }
}

You need to setup a Set Variable step like this, after the HTTP Request Step (it will create variable named AccessToken on project-level):
SourceVariable = Body
SourceVariablePath = $.Payload.AccessToken
VariableName = AccessToken
Level = Project

Then you could use the variable with the {{AccessToken}} syntax in subsequent HTTP Requests...

Let me know if you intended something else and I will elaborate more.
Eugeniy
Posted on: 06 Jul 2016 14:30
I don't understand how to set variable json path from body, i put "/Payload/AccessToken" in case I want to use value from AccessToken field, then I used that variable in next request body:
{
  "Password": "1111",
  "AccessToken": "{{AccessToken}}"
}

but finally my server says there is no AccessToken within request(
i'm giving up for now(
ADMIN
Valeri Hristov
Posted on: 01 Jul 2016 13:15
By the way, on your screenshot, if you execute the request, you will see the created variables in the Last Response Data panel (it will appear just below the request properties)... We discussed similar interface as yours, but in the end we decided to split the Step UI, so that the variables to be accessible regardless of the selected Tab (HTTP Request, Verifications, Condition). I think it will make sense to have similar panel for the Set Variable Step too, where you could see what is the new value.

The Variables Pane displays the state of the runtime after the last execution, you cannot see how the variables were created step by step.
ADMIN
Alex Fidanov
Posted on: 01 Jul 2016 12:50
I would expect to be able to set (runtime) variables on the request itself. This way I know that the source of the variables is that particular request (see attached screenshot).

Although I agree that there should be variables that can be globally accessed, runtimes variables make little sense to be global. Again on the screenshot, on R1 or R2 I would not expect to see variables declared after R3. I would rather want to see the runtime variables declared up to that step. This also be an improvement on a larger scale - imagine that my project has 100+ variables that will always be showing out of the context in which they can be used.
Attached Files:
ADMIN
Valeri Hristov
Posted on: 01 Jul 2016 12:23
Currently the Design-time Variables (see docs for details) can be set on Test-level and Project-level and can be accessed by all Steps within a Test (or all Tests). Because they are shared, we put them in one place - the Variables Pane and it does not change when you select different Step (they are all the same).

The Runtime Variables are created by certain Steps (Set Variable and HTTP Request) and again are on Test or Project level, hence they are in the same Pane as the others.

We have improvements for the Variable-related UI in mind for R3 2016, they just did not make it for R2, so if you have ideas (and use cases) we will be glad to have them!