0
我在Radrails中使用watir来测试我的应用程序。我在我的测试中使用了两个类,我也使用变量@ie。下面是两个类的代码:未定义的本地变量或主要的方法`ie1'
第一类:
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)
请正确缩进代码。 – tokland 2012-07-11 10:31:34
在“测试机构”你不定义ie1变量,所以它是零。 – 2012-07-11 10:41:00
你应该首先清理你的代码 - 这个语句@ ie = ie/ @ ie = Watir :: IE.attach(:title,@title)和ie = ie没有多大意义。 – 2012-07-11 10:48:12