Cucumber with selenium 打开几个浏览器

Cucumber with selenium opens several browsers

有人可以帮我弄清楚为什么每次我 运行 黄瓜的功能都会打开 4 个浏览器吗?无论我的功能场景数量或步骤数量如何,当我用 cucumber 执行测试脚本时,都会打开 4 个 firefox 浏览器。

这是我的配置文件:

这是支持文件夹中 env.rb 的内容:

require 'capybara/cucumber'
Capybara.default_driver = :selenium

我发现了问题,这是因为我在 step_defintions 文件夹中有几个文件 xxx_steps.rb,并且在每个 xxx_steps.rb 中我有 "require 'watir-webdriver'"

所以每次 Cucumber 遇到 require 'watir-webdriver' 它都会打开一个新的浏览器。

在 java 中,我们使用 @Before,然后用它标记第一个场景 (@setup):

@Before("@setup") public void setUp() {
        driver = utilities.DriverFactory.createDriver(browserType);