2011-02-04 4 views
2

Watir 및 Watir-WebDriver와 동시에 작업 중이며 일부 클래스를 다시 열고 일부 메서드를 다시 정의하여 호환성을 높이려고합니다. 나는 설명 할 수없는 이상한 행동을했다. 나는 무슨 일이 일어나고 있는지 이해하려고 노력하고있다.Ruby 클래스를 다시 열 때 이상한 문제가 발생했습니다.

이것은 Windows에서만 사용할 수있는 watir-1.7.1에서 발생합니다.
루비 1.8.7-P330
RUBYOPT =

require 'watir' 

Watir::ElementCollections.class_eval do 
    def new_method 
    end 
end 

>ruby open-classes-watir1.rb 
open-classes-watir1.rb:3: uninitialized constant Watir::ElementCollections (NameError) 

1. 왜 루비가 유효한 클래스를 재개에 대해 불평 않습니다 테스트

-rubygems?

element_collections.rb: 

module Watir 
    #... 
    class ElementCollections 
    include Enumerable 
    #... 
    end 
end 

을하지만 그게 전부가 아니에요 :

는 문제의 클래스는 다음과 같습니다!

테스트 2.

require 'watir' 

Watir::IE.class_eval do 
end 

Watir::ElementCollections.class_eval do # Requires the magic incantation above 
    def new_method 
    end 
end 

>ruby open-classes-watir2.rb 

그것은이 검은 마법과 지금 잘 실행 : 이제이보세요. Watir과 :: IE는 다음과 같습니다

ie-class.rb: 

module Watir 
    class IE 
    include WaitHelper 
    include Exception 
    include Container 
    include PageContainer 
    #... 
    end 
end 

이유는 무엇입니까?

답변

2

나는 이것을 잠시 뒤로 보았다. http://www.flickr.com/photos/marekj/3615299778/ 'watir'은 commonwatir gem에서 가져옵니다. 'watir/ie'는 watir 보석에서 제공됩니다. 여기에는 두 개의 보석이 있습니다.

+1

나는 "watir/ie"가 필요하다. –

+0

'watir/element_collections'도 필요하다. – DKroot

1

을 정의하는 파일 lib/watir/element_collections.rb이 (가) require 'watir'을 호출하여로드되지 않은 것으로 의심됩니다. lib/watir/ie.rblib/watir/core.rb이 필요하며, 차례로 lib/watir/element_collections.rb이 필요합니다.

이 시도 :

require 'watir' 
require 'watir/core' 

Watir::ElementCollections.class_eval do 
    def new_method 
    end 
end 
+0

필요 'watir/core'는 문제를 해결하지 못합니다. 나는 같은 오류를 얻는다. 나는 이유를 모른다. 'watir/element_collections'작업이 필요합니다. – DKroot

1

require "watir" 아직 실제로 Watir::IE를로드하지 않기 때문에이 일어나고있다. Watir::IEWatir::Browser.new을 수행 할 때 Kernel.autoload에 의해로드됩니다. 스티브에 의해 제안

require "watir" 
Watir::IE # to trigger autoload 

# now Watir::ElementCollections exists 

다른 솔루션 require "watir/core"하는 것입니다 : 이것은 작동하는 방법이다.

+0

예, 작동하지만 코드가 털이 있습니다. 나는 추가를 선택했다 : require 'watir/element_collections' – DKroot

관련 문제