当我运行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
时,我得到的output包括访问。
为什么会这样?
更新 问题发生在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
然后它有效。
以前的代码出了什么问题?
答案 0 :(得分: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