英文:
Can I use Gherkin keyword Background in Cypress to only run for certain "tagged" Scenarios
问题
我使用Cypress Automation,并通过Cypress-Cucumber-preprocessor编写的Gherkin特性。
最近,我们重构了特性,以便在每个特性文件的顶部使用Background
,这样它就会在每个Scenario
中被调用。
然而,现在我们只需要在某些场景中的某些测试利用顶部的Background。
研究
我一直在审阅Cypress文档,但似乎找不到这种可能性。
问题
Gherkin关键字Background
是否可以仅限于具有某些标签(例如@NormalLoad
或@HighLoad
)的某些场景?
英文:
I use Cypress Automation with features written in Gherkin via the Cypress-Cucumber-preprocessor.
We recently refactored the features to use Background
at the top of each feature file so that it is called with each Scenario
.
However, now we need only certain tests in the scenario to utilize the Background at the top.
Research
I've been reviewing Cypress documentation and cannot see if this is possible.
Question
Can the Gherkin keyword Background
be limited to only some scenarios that have certain tags (e.g. @NormalLoad
or @HighLoad
) ?
答案1
得分: 4
"Background
语句会在此功能的每个场景中运行。
相反,您可以使用hook Before
,针对功能上的特定标签。这样脚本将执行与 Background
相同的操作。
除了 Background
之外,Before
钩子将在具有适当标签的任何功能上运行。
英文:
The Background
statement would run in every scenario of this feature.
Instead you could use the hook Before
targeting a specific tag on the feature. This way the script would be doing the same as Background
.
Other than Background
the Before
hook run on any feature that has the appropriate tag(s).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论