【发布时间】:2010-09-17 19:48:21
【问题描述】:
所以,我开始创建一些 Ruby 单元测试,使用 Selenium RC 直接在浏览器中测试我的网络应用程序。我将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
这可行,但如果一个浏览器失败,则整个测试都会失败,并且无法知道它在哪个浏览器上失败。
【问题讨论】:
-
嗨丹尼尔,我有一个类似的问题。我想知道你能不能帮忙。 Selenium RC:How to launch Interactive testing with Multiple browsers
标签: ruby-on-rails ruby unit-testing selenium automated-tests