如何在Capybara中更改Cucumber测试的测试默认驱动程序?

Goa*_*lie 9 ruby-on-rails cucumber capybara

Capybara提供的文档中,您可以更改特定测试组的default_driver:

describe 'some stuff which requires js', :js => true do
  it 'will use the default js driver'
  it 'will switch to one specific driver', :driver => :selenium
end
Run Code Online (Sandbox Code Playgroud)

如果我想为特定的黄瓜测试组做这个怎么办?我该如何添加这些参数?

When /^I do something$/  do
  fill_in "a_text_box", :with => "stuff"
  fill_in "another_text_box", :with => "another_thing"
end
Run Code Online (Sandbox Code Playgroud)

谢谢!

DVG*_*DVG 5

Capybara.current_driver = :webkit # temporarily select different driver
#... tests ...
Capybara.use_default_driver       # switch back to default driver
Run Code Online (Sandbox Code Playgroud)


Kev*_*ell 5

在黄瓜中,我分两步完成:

/features/support/env.rb,放置以下行:

Capybara.javascript_driver = :webkit
Run Code Online (Sandbox Code Playgroud)

然后在黄瓜特征中,就在特定场景@javascript之前,在场景之前添加- 像这样:

@javascript
Scenario: Successful sign in - with no flash message if using current firefox
When I'm using a current version of Firefox
When I visit the practitioner home page with "jane.doe@example.com"'s token
Then I should be signed in as practitioner "Jane Doe"
And I should be on the practitioner activities welcome page
And I should not see a flash message warning me I have an unsupported browser
Run Code Online (Sandbox Code Playgroud)

这告诉黄瓜javascript在运行特定场景时使用驱动程序.

这就是我使用Capybara Webkit做到这一点的方式 - 我确信其他驱动程序是相似的.

  • Capybara 现在会自动切换到与您的场景中的标签匹配的任何命名驱动程序,而不是“@javascript”的特殊情况。例如,如果您创建一个“平板电脑”驱动程序并使用“@tablet”标记您的场景,那么“平板电脑”驱动程序将自动使用! (2认同)