在以下功能文件中,我的要求是为每三个字段放置一个doc_id
。为了澄清,我想针对每个ProductName
检查manufacturerName
,RevisionDate
和doc_id
。我提出了以下方法,但我认为这绝对不是首选方法。谁能建议我一个更好的方法。
Background:
Given I am in landigpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I click the search go button
Then I should get in vault search page
And Search result of "<field>" should match with database
Examples:
| doc_id | field |
| 15 | ProductName |
| 15 | ManufacturerName |
| 15 | RevisionDate |
Examples:
| doc_id | field |
| 16 | ProductName |
| 16 | ManufacturerName |
| 16 | RevisionDate |
答案 0 :(得分:1)
您可以使用单个示例表:
Background:
Given I am in landigpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I click the search go button
Then I should get in vault search page
And Search result of "<field>" should match with database
Examples:
| doc_id | field |
| 15 | ProductName |
| 15 | ManufacturerName |
| 15 | RevisionDate |
| 16 | ProductName |
| 16 | ManufacturerName |
| 16 | RevisionDate |
我没有看到任何其他方式以您需要的方式传递参数。这就是我对Cucumber不喜欢的事情。它并不灵活。
答案 1 :(得分:1)
Bacckground:
Given I am in landigpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I click the search go button
Then I should get in vault search page
And the search results should match the database
Examples:
| doc_id |
| 15 |
| 16 |
并使这项工作:
When /^I enter "<\w+>"$/ do | doc_id |
@doc_id = doc_id
...
end
Then "the search results should match the database" do
db_results = db.find(@doc_id) # or something similar
... # compare db_results to actual results
end
这仍然很糟糕,因为你的Gherkin中有doc_id,你依赖于一个预先填充的数据库,你有一个场景大纲;但是,嘿,请将其保存为其他问题:)
答案 2 :(得分:1)
嗨,我猜你们混淆了Data Tables和情景大纲。 上面的解决方案是:
Background:
Given I am in landingpage page after login
Scenario Outline: valid
When I enter "<doc_id>"
And I select to navigate to search page
Then Search result of field should match with database
| ProductName |
| ManufacturerName |
| RevisionDate |
Examples:
| doc_id |
| 15 |
| 16 |
该表格可以轻松转换为您可以在步骤中使用的列表或地图。