// Article - Reuse values in workflow steps
Written July 28, 2020
What is a workflow?
Rungutan allows you to create non-scripted workflows in order to generate load test cases that simulate user interaction with your APIs.
Furthermore, you can also extract values from your API calls from either the headers or the body itself and reuse them in the future steps of your workflow.
How do I extract values?
The logic is pretty simple.
All you have to do is define an "extract" object in your workflow step and tell us from where we can extract that value for you.
You can fetch the value from both headers as well as the response body, using either a "key" mechanism (eg for headers or json-based response bodies) or using a "regex" to catch the response from a text-based response body.
Extract from headers
In order to get the response from a header, you'd define something like this:
"workflow": [
{
"path": "/login_path",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": "user=user&password=pass",
"extract": [
{
"parameter_name": "authtoken",
"location": "headers",
"key": "PHPSESSIONID"
}
]
}
]
Extract from response body
In order to get the response from the response body, you'd define something like this:
"workflow": [
{
"path": "/some_form_with_csrf",
"method": "GET",
"extract": [
{
"parameter_name": "csrftoken",
"location": "body",
"element_find_regex": "meta name=\"csrf-token\" content=\"(.+?)\""
}
]
}
]
How do I insert values?
The logic is AGAIN, pretty simple.
If you properly defined the extract field in the workflow step, then you can reuse it in any future step, in either the payload or the headers through a bash-like notation -> ${parameter-name-here}.
Inject into headers
In order to inject your value into the headers, you'd define something like this:
"workflow": [
{
"path": "/login_path",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": "user=user&password=pass",
"extract": [
{
"parameter_name": "authtoken",
"location": "headers",
"key": "PHPSESSIONID"
}
]
},
{
"path": "/my/profile",
"method": "GET",
"data": "",
"headers": {
"Authorization": "Bearer ${authtoken}"
}
}
]
Inject into payload
In order to inject your value into the payload, you'd define something like this:
"workflow": [
{
"path": "/some_form_with_csrf",
"method": "GET",
"extract": [
{
"parameter_name": "csrftoken",
"location": "body",
"element_find_regex": "meta name=\"csrf-token\" content=\"(.+?)\""
}
]
},
{
"path": "/some_form_with_csrf",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": "[email protected]&password=test1.com&_token=${csrftoken}&login=Login"
}
]
What are the normal use cases?
Using this logic, you are able to define complex test cases with minimal code development and fast resolution.
If you're interested in seeing a few samples, you can check it out in our Documentation - Sample Workflows.
For instance, here's how you can login to a Magento based authentication platform:
{
"test_name": "Magento sample workflow",
"num_clients": 10,
"run_time": 60,
"test_region": [ "us-east-1" ],
"threads_per_region": 1,
"workflow": [
{
"path": "https://example.com/login_path",
"method": "GET",
"headers": {
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)"
},
"extract": [
{
"parameter_name": "csrftoken",
"location": "body",
"element_find_regex": "input name=\"form_key\" type=\"hidden\" value=\"(.+?)\""
}
]
},
{
"path": "https://example.com/login_path",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)"
},
"data": "form_key=${csrftoken}&login%5Busername%5D=user1&login%5Bpassword%5D=pass123",
"extract": [
{
"parameter_name": "session",
"location": "headers",
"key": "PHPSESSID"
}
]
},
{
"path": "https://example.com/categories",
"method": "GET",
"headers": {
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)",
"PHPSESSID": "${session}"
}
},
{
"path": "https://example.com/checkout/cart/add/product/684/",
"method": "POST",
"headers": {
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)",
"PHPSESSID": "${session}"
},
"data": "product=684&qty=50"
},
{
"path": "https://example.com/checkout",
"method": "GET",
"headers": {
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)",
"PHPSESSID": "${session}"
}
},
{
"path": "https://example.com/rest/v1/guest-carts/shipping-information",
"method": "POST",
"headers": {
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)",
"PHPSESSID": "${session}",
"Content-Type": "application/json"
},
"data": "{\n \"shippingAddress\": {\n \"countryId\": \"NZ\",\n \"region\": \"\"\n },\n \"shippingMethod\": {\n \"shipping_method_code\": \"freeshipping\",\n \"shipping_carrier_code\": \"freeshipping\"\n }\n}"
},
{
"path": "https://example.com/rest/v1/guest-carts/set-payment-information",
"method": "POST",
"headers": {
"User-Agent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 (RUNGUTAN)",
"PHPSESSID": "${session}",
"Content-Type": "application/json"
},
"data": "{\n \"shippingAddress\": {\n \"countryId\": \"NZ\",\n \"region\": \"\"\n },\n \"shippingMethod\": {\n \"shipping_method_code\": \"freeshipping\",\n \"shipping_carrier_code\": \"freeshipping\"\n }\n}"
}
]
}