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