Сценарий сценария огурца и примеры с определениями общих этапов
У меня есть файл Feature, который выглядит следующим образом:
Scenario Outline: Create ABC
Given I open the application
When I enter username as <username>
And I enter password as <password>
Then I enter title as <title>
And press submit
Examples:
| username | password | title |
| Rob | xyz1 | title1 |
| Bob | xyz1 | title2 |
Это требует от меня определения шагов для каждого из этих значений. Могу ли я вместо этого иметь
общее определение шага, которое может отображаться для каждого имени пользователя или пароля или значений заголовка в
раздел примеров.
i.e вместо того, чтобы говорить
@When("^I enter username as Rob$")
public void I_enter_username_as_Rob() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
Могу ли я ввести
@When("^I enter username as <username>$")
public void I_enter_username_as_username(<something to use the value passed>) throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
Ответы
Ответ 1
Вы должны использовать этот формат
Scenario Outline: Create ABC
Given I open the application
When I enter username as "<username>"
And I enter password as "<password>"
Then I enter title as "<title>"
And press submit
Что создаст
@When("^I enter username as \"([^\"]*)\"$")
public void I_enter_username_as(String arg1) throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
arg1
теперь будет иметь ваше имя пользователя/значение.
Ответ 2
Огурец автоматически выдаст пропущенные шаги в консоли. Просто сделайте сухой прогон, и пропущенные шаги будут показаны на консоли.
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty" }, features = { "<path_to_feature>" },
glue = { "<optional_steps_location_java_file>" }, dryRun = true,
tags = { "<optional_NOT_req_for_now>" })
public class RunMyCucumberTest {
}
См. дополнительные параметры огурца