unknownbits
unknownbits

Reputation: 2885

change Watir::Browser.new to IE by default

Can I change the default browser Firefox to IE in watir

Watir::Browser.new

Actually this code open Firefox browser.I want to open IE by default instead of Firefox with this line of code.

It is possible?

Upvotes: 1

Views: 4213

Answers (5)

Frank
Frank

Reputation: 71

Yes, it is possible and it is done this way:

b=Watir::Browser.start('www.google.com',browser=:ie)

you use Watir::Browser object start method and augments(url in quotes, type of browser)

Upvotes: 0

Arup Rakshit
Arup Rakshit

Reputation: 118261

If you create Watir::Browser object,using Watir::Browser.new only,then default browser will be always Firefox. Because that is how the code has been written in the browser.rb:

# File 'lib/watir-webdriver/browser.rb', line 43

def initialize(browser = :firefox, *args)
  case browser
  when Symbol, String
    @driver = Selenium::WebDriver.for browser.to_sym, *args
  when Selenium::WebDriver::Driver
    @driver = browser
  else
    raise ArgumentError, "expected Symbol or Selenium::WebDriver::Driver, got #{browser.class}"
  end

  @error_checkers = []
  @current_frame  = nil
  @closed         = false
end

I want to open IE by default instead of Firefox with this line of code.

Yes possible as below :

b = Watir::Browser.new :ie

Or,otherwise you need to replace :firefox with :ie,in the #initialize method. But I would recommend you not to change the source code.

Upvotes: 0

user2835779
user2835779

Reputation:

Yes you can do so. For that You have to change browser.rb file,

def initialize(browser = :firefox, *args) 
to
def initialize(browser = :IE, *args)

and add IE extension on system path.

Upvotes: 1

Jarmo Pertman
Jarmo Pertman

Reputation: 1905

If you want to use IE with watir-classic instead of watir-webdriver then you can do that by using watir gem on a Windows machine:

require "watir"

b = Watir::Browser.new # opens IE with watir-classic

The same code will open Firefox on a non-Windows machine.

Upvotes: 1

gotva
gotva

Reputation: 5998

https://github.com/gotva/cucumber-watir/blob/master/features/support/env.rb There is settings for environment. IE is presented there. You can use smth like this (pass a env variable) or setup it directly in place you setup watir

require 'watir-webdriver'
Browser = Watir::Browser
browser = Browser.new :ie

Upvotes: 0

Related Questions