0

我有一个检查页面标题是否存在的类。我需要执行几次。在每种情况下,我都在不同级别的 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
4

1 回答 1

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
于 2012-07-10T17:36:36.053 回答