您可以使用标记的钩子来执行此操作: “可以基于场景的标签有条件地选择钩子来执行。仅为某些场景运行特定钩子,你可以将钩子与标签表达相关联。”来自 文档 。
Feature File :- Hainvg 2 Scenarios, one for UI and other one for API @UI Scenario: This is First UI Scenario running on chrome browser Given this is the first step When this is the second step Then this is the third step @Non-UI Scenario: This is First Non-UI Scenario running on chrome browser Given this is the first step When this is the second step Then this is the third step ------------------------------------------ Hook Implementation ------------------------------------------ @Before("@UI") public void beforeUISetup(){ Do here :- In several features, related to the UI, I need to perform some actions before every single scenario such as spinning up VMs } @Before("@Non-UI") public void beforeNon-UIScenario(){ Do here :- in non-UI tests, such as API tests, I don't need those browsers to be spun up }
如果您需要首先运行非UI @Before方法,那么我们也可以设置这些@Before的顺序。