主要的未定义局部变量或方法`ie1'

时间:2012-07-11 10:28:54

标签: ruby internet-explorer class watir

我在Radrails中使用watir来测试我的应用程序。我在我的测试中使用了两个类,其中我也使用变量@ie。以下是两个类的代码:

头等舱:

class Title
def initialize(title,url,ie)
@title = title
@url=url
@ie=ie
@ie=Watir::IE.attach(:title, @title)  
rescue Watir::Exception::NoMatchingWindowFoundException
puts ("could not find browser")
$r.addtoReport(testReport, "check page element", "FAILED", "Page title " + @title +"   not found") 
else
@ie=Watir::IE.attach(:url, @url)
end
end

第二课:

class Text_pos
def initialize(text, object,ie)
@text=text
@object=object
@ie=ie
if @ie.contains_text(@text)
puts("Test for " + @object + " passed")
$r.addtoReport($testReport, "check " + @object, "PASSED", "Test for " + @object + " passed" )
else
puts("Test for " + @object + " failed")
puts (@ie.link(:text => /Exception:/))
h= @ie.link(:text => /Exception:/)
$r.addtoReport($testReport, "check " + @object, "FAILED", h.text) 
end
end
end

稍后在测试体中我执行如下命令:

Text_pos.new("Glossary Of Terms", "login",ie)
Title.new("Company","http://ec2-50-16-62-110.compute-1.amazonaws.com:9100/bobsworld/BPM/Mtebpm000p0001Form.do?resetFilter_action=", ie1)
Text_pos.new("Title", "if page is loaded", ie1)

但我收到错误 - Test for login passed BPM/try.rb:106:in':未定义的局部变量或方法ie1' for main:Object (NameError)

1 个答案:

答案 0 :(得分:0)

阐述ŽeljkoFilipin的评论:

Text_pos.new("Glossary Of Terms", "login",ie)
Title.new("Company","http://ec2-50-16-62-110.compute-1.amazonaws.com:9100/bobsworld/BPM/Mtebpm000p0001Form.do?resetFilter_action=", ie1)
Text_pos.new("Title", "if page is loaded", ie1)

你在第一行使用ie,但在第二行和第三行使用ie1,这可能是一个错字。