我的主rakefile有一些停止和启动selenuim的任务,如下所示:
require 'selenium/rake/tasks'
Selenium::Rake::RemoteControlStartTask.new do |rc|
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
rc.background = false
rc.wait_until_up_and_running = true
rc.additional_args << "-singleWindow"
end
Selenium::Rake::RemoteControlStopTask.new do |rc|
rc.host = "localhost"
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
end
这迫使要求安装selenuim gem以使用rake而不管它是什么 铁路环境。我在哪里可以放置这个代码,只有在rails环境设置为test?
时才会加载它Rails 2.3
干杯
答案 0 :(得分:4)
您使用的是Rails 3还是Rails 2?
Rails 3添加一个像这样的块:
if Rails.env.test?
require 'selenium/rake/tasks'
Selenium::Rake::RemoteControlStartTask.new do |rc|
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
rc.background = false
rc.wait_until_up_and_running = true
rc.additional_args << "-singleWindow"
end
Selenium::Rake::RemoteControlStopTask.new do |rc|
rc.host = "localhost"
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
end
end
在Rails 2中(或3,但它已被弃用),如下所示:
if RAILS_ENV == "test"
require 'selenium/rake/tasks'
Selenium::Rake::RemoteControlStartTask.new do |rc|
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
rc.background = false
rc.wait_until_up_and_running = true
rc.additional_args << "-singleWindow"
end
Selenium::Rake::RemoteControlStopTask.new do |rc|
rc.host = "localhost"
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
end
end