При использовании Behat Можете ли вы иметь несколько PyStrings в определении шага?

У меня есть определение шага, в котором я хотел бы иметь несколько PyStrings, введенных в файл объекта. Возможно ли это, и если да, то какой синтаксис вы бы использовали для этого?

В настоящее время мое определение шага выглядит так:

 @Then /^(?:I )?get a value "([^"]+)" when I have a username "([^"]+)" and a password "([^"]+)" and I send a "([A-Z]+)" request to "([^"]+)" with form data: and header data:$/

Тогда мой фактический файл функций выглядит так:

 Then I get a value "orange" when I have a username "jsmith" and a password "password" and I send a "POST" request to "www.google.com" with form data:

"""{
"key1": "value1",
"key2": "value2",
}
"""and header data:

"""{
"key1": "value1",
"key2": "value2",
}
"""

0

Решение

Кажется, что для каждого настраиваемого шага происходит сброс общих открытых переменных.

Этого не должно быть!

Вы можете разделить все эти строки, как показано ниже, хранить данные в переменных и обрабатывать их в конце, чтобы вам не приходилось делать все сразу. Если один из них должен бежать посередине, тогда вы можете.

Некоторые примеры:

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

ПРИМЕР

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;
}
}

корнишон

  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

Результат

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
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector