加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 04:37:15 所属栏目:百科 来源:网络整理
导读:所以,我已经开始创建一些使用 Selenium RC直接在浏览器中测试我的Web应用程序的Ruby单元测试.我正在使用 Selenum-Client用于ruby.我已经为我继承的所有其他selenium测试创建了一个基类. 这会创建大量SeleniumDriver实例,并在每个实例上调用所有缺少的方法.这
所以,我已经开始创建一些使用 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吗?我认为它创建了非常好的摘要报告,显示了您需要的详细信息.我可能错了,因为我已经有一段时间不使用它了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读