如何使用测试单元gem在一个Watir脚本中测试多个浏览器

时间:2014-06-18 23:45:36

标签: ruby selenium watir-webdriver testunit selenium-grid2

所以这不是关于并行运行多个浏览器。它依次运行的是IE11,然后是IE10,然后是FireFox,所有这些都连接到Selenium Grid2的不同虚拟机上。

这就是我所拥有的,在一台虚拟机上运行一个浏览器。

文件:example_grid_ie11.rb

require "rubygems"
require "test/unit"
require "watir-webdriver"

class GoogleSearch < Test::Unit::TestCase
  def setup
    caps = Selenium::WebDriver::Remote::Capabilities.ie
    caps.version = "11"
    caps[:name] = "Testing with IE 11"

    @browser = Watir::Browser.new(
    :remote,
    :url => "http://vm-auto.3mhis.vm:4444/wd/hub",
    :desired_capabilities => caps)
  end

  def teardown
    @browser.close
  end

  def test_search
    @browser.goto "google.com"
    @browser.text_field(:name => "q").set "watir"
    @browser.button.click
    @browser.div(:id => "resultStats").wait_until_present
    @browser.screenshot.save ("GoogleSearch_IE11.png")
    assert @browser.title == "watir - Google Search"
  end
end

现在,我无法弄清楚我是否可以运行多个设置方法和多个拆卸,以及哪个浏览器在拆解时关闭。

test-unit gem,给我一个很好的结果XUnit Style,加上很多断言。

1 个答案:

答案 0 :(得分:0)

使用Test :: Unit 2.x

gem install test-unit

示例:

https://github.com/test-unit/test-unit

多种设置:

class TC_MyTest < Test::Unit::TestCase
   def setup # first
      @standard = MyClass.new
   end

   setup # second
   def setup_alpha
      @alpha = MyClass.new
   end

   setup # third
   def setup_beta
      @beta = MyClass.new
   end

   def test_stuff
      assert_true(1 == 1)
   end
end
多次拆解:

class TC_MyTest < Test::Unit::TestCase
   def test_stuff
      assert_true(1 == 1)
   end

   def teardown # last
      @standard = nil
   end

   teardown # second
   def teardown_alpha
      @alpha = nil
   end

   teardown # first
   def teardown_beta
      @beta = nil
   end
end