watir / watir_meta

Former watir.gem that referenced both watir-webdriver and watir-classic
http://watir.com
Other
407 stars 45 forks source link

Extending watir classes. #6

Closed hemanth closed 11 years ago

hemanth commented 11 years ago

Let the code do the talking :

require 'watir'
module Watir
  class FieldElement < InputElement 
    # Some code 
  end 
end 

# Getting uninitilazed constant Watir::InputElement how come?

Same for :

require 'watir'

Watir.driver = :classic
Watir.load_driver

module Watir
  class FieldElement < InputElement 
    # Some code 
  end 
end 

Then, the below code works, after Watir::Browser.new module Watir will be loaded.

require 'watir'

browser = Watir::Browser.new

module Watir
  class FieldElement < InputElement 
    # Some code 
  end 
end 

So, is there a way to extend the class before Watir::Browser.new :question:

jarmo commented 11 years ago

The reason you're getting that error is because watir-classic has an autoload statement for IE class, which loads all the code. The code is actually rudimentary and from the times of FireWatir. It should be removed in the future, but currently you can do something like this if you're using only watir-classic:

require "watir"
Watir.driver = :classic
Watir.load_driver

# trigger autoload
Watir::IE

# your code

I've opened up a separate issue for removing autoload code https://github.com/watir/watir-classic/issues/47

hemanth commented 11 years ago

@jarmo Kool, was almost there, but had to do an Watir::IE will try it very soon and update.

Update : Super class mismatch for class UnknownObjectException and in irb undefined method driver for Watir:Module !

jarmo commented 11 years ago

Oops, somehow i have missed your reply. Sorry about that.

If you're getting error like that then your monkey patch is wrong or you have loaded Watir-WebDriver. Can you show me your code?

hemanth commented 11 years ago

Unable to find the code, but later on Watir.load_driver did work.