背景中的步骤不能与示例结合使用。 Behat是一个限制吗?为什么背景中的步骤不能与Behat中的示例结合
我有以下功能文件。
Background:
Given I have the login Page
When I login to the application using "<username>"
Then the list is displayed
When I select an item from the list
Then I am taken to the Dashboard
When I navigate to the Overview Page
Then the Overview Page is displayed
@javascript @frontend @devlocal
Scenario Outline: To verify the Overview page content
Then overview page main headings are displayed
Examples:
| username | role |
| RoleUser | ROLE_USER |
| RoleAdmn | ROLE_ADMIN |
这将产生错误: [贝哈特\小黄瓜\异常\ ParserException]
预期注释或方案或轮廓或步骤令牌,但得到了对线实施例:15中的文件:在/ var /功能/概述.feature
我在“背景”中有这么多步骤的原因是因为这是进入页面的逻辑流程。我有几个使用这些步骤的场景。
我确实有这个问题的工作解决方案,它使用“场景”中的“背景”中的所有步骤。这工作绝对好。不过,对于此功能,我有5种不同的场景,并且如果我在所有5种场景中复制并粘贴相同的步骤,它看起来绝对凌乱和麻烦。 我认为这是我们使用背景部分的主要原因?
这里是我使用的那一刻是什么:
背景: 鉴于我在登录页面
@javascript @frontend @devlocal
Scenario: To verify the Overview page content
When I login to the application using "<username>"
Then the list is displayed
When I select an item from the list
Then I am taken to the Dashboard
When I navigate to the Overview Page
Then the Overview Page is displayed
Then overview page main headings are displayed
Examples:
| username | role |
| RoleUser | ROLE_USER |
| RoleAdmn | ROLE_ADMIN |
想象一下,从所有不同的场景场景部分的所有这些步骤
谢谢伊恩。将6个步骤合并为2个步骤意味着什么?这是否意味着将所有这6个步骤的逻辑合并到2中。这将会有点冗余,不是这样(在不同情况下再次编写相同的代码) – 2014-09-11 12:31:26
您的背景包含每个大纲“继承”的公共逻辑。您可以将该通用逻辑从背景中分离到另一个场景中,因此不必检查每个场景大纲中的后台步骤是否通过,而是可以在单独的场景大纲中执行相同的操作,从而减少所有其他五个场景大纲的负载。在那里你只需要登录并进入特定场景测试开始的页面。 – 2014-09-11 12:49:43
在代码中使用相同的字母在某些方面也可以被认为是冗余的。你有局限性,你想找到尽可能少的重复自己的方法,你可以重新安排你的代码,让它变得更干,这样可以使事情变得更好。 – 2014-09-11 12:52:36