【问题标题】:How can i test multiple Browsers in one Watir Script using test-unit gem如何使用测试单元 gem 在一个 Watir 脚本中测试多个浏览器
【发布时间】:2014-06-18 23:45:35
【问题描述】:

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

这就是我所拥有的,在一个 VM 上运行一个浏览器。

文件: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,加上很多断言。

【问题讨论】:

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


    【解决方案1】:

    使用测试::Unit 2.x

    gem 安装测试单元

    例子:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 2013-06-18
      • 2012-08-03
      • 1970-01-01
      • 2017-06-16
      • 2014-05-02
      • 1970-01-01
      相关资源
      最近更新 更多