0

Cucumber を実行すると、次のエラーが表示されます。

undefined method `visit' for "default":String (NoMethodError)
C:/Users/user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/session.rb:157:in `visit'
C:/Users/user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in `visit'
D:/Andrey/project/features/support/env.rb:33:in `basicAuth'
D:/Andrey/project/features/support/env.rb:54:in `addHost'
D:/Andrey/project/features/support/env.rb:95:in `Before'

呼び出し時Capybara.visit("http://www.google.com")

undefined method `browser' for "default":String (NoMethodError)
D:/Andrey/project/features/support/env.rb:105:in `After'

呼び出すときpage.driver.browser.save_screenshot("screenshot.png")

および多くの同様のエラー。どこでもカピバラのメソッドにアクセスできないようです。

しかし、実行すると、訪問を含む出力Capybara.methods.sortが得られます。

なぜそれが起こるのですか?

更新: 問題は env.rb にありました。次のコードが含まれていました。

Capybara.register_driver :selenium do |app|
    profile = Selenium::WebDriver::Firefox::Profile.new
    Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
  end
end

それを次のように変更すると:

Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(app, :browser => :firefox)
  end
end

その後、動作します。

前のコードの何が問題になっていますか?

4

1 に答える 1

0

これを試してください:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.http'] = 'localhost'
profile['network.proxy.http_port'] = 9090

Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)

うまくいかない場合は、これを試してください:

visit("http://www.google.com") #remove "Capybara" before
于 2012-08-03T16:18:05.540 に答える