0

我在 RadRails IDE 中使用 Watir。我创建了一个类来检查我的网页上是否存在某些文本:

class Text

  def initialize(text, object)
    @text   = text
    @object = object

    if $ie.contains_text(@text)
      puts "Test for" + @object + "failed"
      puts $ie.link(:text => /Exception:/)

      h = $ie.link(:text => /Exception:/)
      r.addtoReport(testReport, "check" + @object, "FAILED", h.text)
    else
      puts("Test for" + @object + "passed")

      r.addtoReport(
          testReport, 
          "check" + @object, 
          "PASSED", 
          "Test for" + @object + "passed"
      )
    end
  end

end

但是当我尝试在我的测试中执行代码时,我收到以下错误 -

BPM/Company.rb:38:in `initialize': undefined method `contains_text' for nil:NilClass (NoMethodError)
from BPM/Company.rb:79:in `new'
from BPM/Company.rb:79:in `<main>'

我通过这个命令调用类 -

Text.new("Menu", "login")

代码更改 -

def initialize(text, object, ie)
    @text   = text
    @object = object
    @ie=ie
    if @ie.contains_text(@text)
      puts "Test for" + @object + "failed"
      puts @ie.link(:text => /Exception:/)

我通过这个命令调用类 -

Text_pos.new("Terms", "login",$ie)

在描述类之前 ie 被初始化ie=Watir::IE.new

4

1 回答 1

1

$ie 是从哪里来的?-- 看来你没有初始化,即:

ie = Watir::IE.new
于 2012-07-10T09:33:30.210 回答