0

我在 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)

4

1 回答 1

0

详细阐述 Željko Filipin 的评论:

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,这可能是一个错字。

于 2012-07-11T10:55:03.257 回答