所以,我已经开始创建一些使用Selenium RC直接在浏览器中测试我的Web应用程序的Ruby单元测试.我正在使用Selenum-Client作为红宝石.我已经为我继承的所有其他selenium测试创建了一个基类.
这会创建大量SeleniumDriver实例,并在每个实例上调用所有缺少的方法.这基本上是并行运行测试.
其他人如何自动化这个?
这是我的实施:
class SeleniumTest < Test::Unit::TestCase def setup @seleniums = %w(*firefox *iexplore).map do |browser| puts 'creating browser ' + browser Selenium::SeleniumDriver.new("localhost", 4444, browser, "http://localhost:3003", 10000) end start open start_address end def teardown stop end #sub-classes should override this if they want to change it def start_address "http://localhost:3003/" end # Overrides standard "open" method def open(addr) method_missing 'open', addr end # Overrides standard "type" method def type(inputLocator, value) method_missing 'type', inputLocator, value end # Overrides standard "select" method def select(inputLocator, optionLocator) method_missing 'select', inputLocator, optionLocator end def method_missing(method_name, *args) @seleniums.each do |selenium_driver| if args.empty? selenium_driver.send method_name else selenium_driver.send method_name, *args end end end end
这样可行,但如果一个浏览器出现故障,整个测试将失败,并且无法知道哪个浏览器失败了.