Azher
Azher

Reputation: 493

Using watir-webdriver, can I change the driver temporarily?

Can I change the driver temporarily. Basically I have Phantomjs setup as my default driver but need to use a different driver for 1 feature. The issue is, Phantomjs cannot find a certain element on a page as it is hidden, but on a normal browser it shows perfectly fine and feature passes with no issues.

If anyone has come across the need to temporarily change driver and has a solution, please let me know.

Upvotes: 0

Views: 134

Answers (1)

Justin Ko
Justin Ko

Reputation: 46826

You can use a tags to specify scenarios that should use a specific browser/driver.

For example, you could have the following in your env.rb:

require 'watir'

Before('~@firefox') do
    @browser = Watir::Browser.new :phantomjs 
end

# Use the firefox browser 
Before('@firefox') do
    @browser = Watir::Browser.new :firefox
end

After do
    @browser.close
end

During your scenarios/features that are tagged with @firefox, they will use the firefox browser. Otherwise, they will use your default phantomjs driver.

Upvotes: 3

Related Questions