Search code examples
seleniumcucumbercapybarapoltergeist

Cucumber steps for two different drivers


I am using two different browsers, capybara poltergeist and a selenium driver (not the capybara selenium driver).

In my cucumber tests I have steps that look like this:

#for selenium
When /^I go to url$/ do |url|
  @driver.get url
end

#for capybara
When /^I visit url$/ do |url|
  visit url
end

My number of tests are growing and this form of work around (naming the steps differently) is growing.

I want to have a more elegant way of doing this, specially when it comes to clicking of buttons.


Solution

  • You could create a method called visit and code it like this:

    def visit (url)
       @driver.get url
    end
    

    Then when you are not using the capybara dsl, the method you defined is called.