微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – Selenium RC:自动在多个浏览器中运行测试

所以,我已经开始创建一些使用 Selenium RC直接在浏览器中测试我的Web应用程序的Ruby单元测试.我正在使用 Selenum-Client用于ruby.我已经为我继承的所有其他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',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

这样可行,但如果一个浏览器出现故障,则整个测试失败,无法知道哪个浏览器失败了.

解决方法

你试过 Selenium Grid吗?我认为它创建了非常好的摘要报告,显示了您需要的详细信息.我可能错了,因为我已经有一段时间不使用它了.

原文地址:https://www.jb51.cc/ruby/269548.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐