For every customized step it appears to be resetting the shared public variables.
It shouldn't happen!
You can separate all those lines like below, store data in variables and process them at the end so you don't have to do all in one go. If one of them must run in the middle then you can.
Some examples:
http://www.inanzzz.com/index.php/post/ajqn/api-request-response-testing-with-behat-v2-includes-json-xml-html-and-cli
http://www.inanzzz.com/index.php/post/xw1v/api-request-response-testing-with-behat-v1
EXAMPLE
FeatureContext
class FeatureContext extends MinkContext
{
private $value;
private $username;
private $password;
/**
* @When /^I get a value "([^"]*)"$/
*/
public function iGetValue($value)
{
$this->value = $value;
}
/**
* @When /^I have the username "([^"]*)"$/
*/
public function iHaveUsername($username)
{
$this->username = $username;
}
/**
* @When /^I have the password "([^"]*)"$/
*/
public function iHavePassword($password)
{
$this->password = $password;
}
/**
* @When /^I send a "([^"]*)" request to "([^"]*)" with form data:$/
*/
public function iSendRequestToWithFormData($method, $address, PyStringNode $requestPayload)
{
// Example is here: http://www.inanzzz.com/index.php/post/ajqn/api-request-response-testing-with-behat-v2-includes-json-xml-html-and-cli
// @When /^I send a "([^"]*)" request to "([^"]*)"$/
}
/**
* @When /^I have header data:$/
*/
public function iHaveHeaderData(PyStringNode $requestPayload)
{
// Example is here: http://www.inanzzz.com/index.php/post/ajqn/api-request-response-testing-with-behat-v2-includes-json-xml-html-and-cli
}
/**
* @When /^You run this step to do whatever you wanted to do with your steps above$/
*/
public function iRun()
{
echo $this->value . PHP_EOL;
echo $this->username . PHP_EOL;
echo $this->password . PHP_EOL;
}
}
Gherkin
Scenario: I test things
When I get a value "69"
Then I have the username "hello"
And I have the password "world"
And I send a "POST" request to "www.google.com" with form data:
"""
{
"key1": "value1",
"key2": "value2"
}
"""
And I have header data:
"""
{
"key1": "value1",
"key2": "value2"
}
"""
Then You run this step to do whatever you wanted to do with your steps above
Result
Feature: Whatever
Scenario: I test things
When I get a value "69"
Then I have the username "hello"
And I have the password "world"
And I send a "POST" request to "www.google.com" with form data:
"""
{
"key1": "value1",
"key2": "value2"
}
"""
And I have header data:
"""
{
"key1": "value1",
"key2": "value2"
}
"""
69
hello
world
Then You run this step to do whatever you wanted to do with your steps above
1 scenario (1 passed)
6 steps (6 passed)
0m0.857s