这是我的问题:
我正在编写一个使用 selenium-webdriver 连接到站点的应用程序,单击/填充一堆东西。
显然,我想测试我的代码......这就是它变得困难的地方!我该怎么做呢?
这是我的测试:
require 'spec_helper'
require 'capybara/rspec'
module MyModule
Capybara.run_server = false
describe "the method", :type => :request do
it "should open a browser and go to the site" do
MyClass.open_site("http://google.com")
page.has_content? "Google"
end
end
end
这是代码:
require 'selenium-webdriver'
module MyModule
class MyClass
def self.open_site(url)
@driver = Selenium::WebDriver.for :firefox
@driver.navigate.to url
end
end
end
这是我得到的错误:
Failures:
1) the method should open a browser and go to the site
Failure/Error: page.has_content? "Google"
ArgumentError:
rack-test requires a rack application, but none was given
# (eval):2:in `has_content?'
# ./spec/integration/myclass_spec.rb:10
我可以理解测试很混乱,因为通常 Capybara 运行 Selenium 来访问一个站点并检查一切是否正常。但是这里 Selenium 作为代码的一部分独立运行......
我怎么能告诉 rack-test 使用正在运行的 Selenium 作为它的应用程序?
Capybara 甚至是测试此代码的正确解决方案吗?
谢谢你的帮助!