これが私の問題です:
私は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
通常、カピバラは Selenium を実行してサイトを閲覧し、すべてが適切に見えることを確認するため、テストが混乱していることは理解できます。しかし、ここでは Selenium がコードの一部として単独で実行されています...
実行中の Selenium をアプリケーションとして使用するように rack-test に指示するにはどうすればよいですか?
Capybara は、このコードをテストするための適切なソリューションでもありますか?
ご協力いただきありがとうございます!