如何使用$ ie推广不同的页面级别($ ie1 ...)

时间:2012-07-10 15:22:24

标签: ruby class watir

我有一个类来检查页面标题是否存在。我需要多次执行它。在每种情况下,我都在不同级别运行ie - ie1,ie2。在我的代码中,我检查$ ie,我如何将这个概括为$ ie1等等?

class Text_neg
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

1 个答案:

答案 0 :(得分:0)

初始化Text_neg类时,应传入要使用的ie对象。然后Text_neg可以将它存储在它知道的变量中,并且不必为每个ie对象递增。

看起来像是:

class Text_neg
  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:/))
      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

然后为每个IE对象运行它,你会这样做:

Text_neg(text, object, $ie1)
Text_neg(text, object, $ie2)
etc