我试图使用capybara& amp;使用黄瓜的硒webdriver。浏览器已启动,但无法加载网址。以下是我的env.rb
文件
begin require 'rspec/expectations';
rescue LoadError;
require 'spec/expectations';
end
require 'capybara'
require 'capybara/dsl'
require 'capybara/cucumber'
require 'capybara/session'
require 'selenium-webdriver'
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1 # manual proxy config
profile["network.proxy.http"] = "proxybank.icici.net"
profile["network.proxy.http_port"] = 8080
profile.native_events = true
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
app_host = "https://mobilebanking.icici.com"
Capybara.app_host = app_host
Capybara.run_server = true
Capybara.default_driver = :selenium
我得到的错误低于
D:\cucumberproject>cucumber
In Steps.rb file
Feature: My first feature
Scenario: launch google page # features\google.feature:4
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed
in app-global
*** LOG addons.xpi: New add-on {20a82645-c095-46ed-80e3-08825760534b} installed
in winreg-app-global
*** LOG addons.xpi: New add-on jqs@sun.com installed in winreg-app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
Given I launch the browser # features/step_definitions/google_steps.rb:5
Timeout::Error (Timeout::Error)
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill'
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:2211:in `read_status_line'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:2200:in `read_new'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1183:in `transport_request'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1169:in `request'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1162:in `block in request'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1160:in `request'
./features/step_definitions/google_steps.rb:9:in `/^I launch the browser$/
'
features\google.feature:5:in `Given I launch the browser'
Failing Scenarios:
cucumber features\google.feature:4 # Scenario: launch google page
1 scenario (1 failed)
1 step (1 failed)
1m14.891s
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown
答案 0 :(得分:2)
编辑: server_boot_timeout
已在Capybara 2中删除。
对于Capybara 2
您可以尝试添加wait.until
并查看是否有帮助。您需要在文件顶部require 'selenium-webdriver'
。
更改以下行:
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
到此:
capybara_driver = Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
driver = capybara_driver.browser
wait = Selenium::WebDriver::Wait.new(:timeout => 300)
wait.until { driver.title.downcase.start_with? "my page title" }
如果这不起作用,你也可以尝试使用普通的老红宝石睡眠。
sleep(5.minutes)
对于Capybara< 2 强>
尝试增加Capybara.server_boot_timeout
值。在env.rb
文件中使用以下内容(如果该行不存在,请添加该行)。
Capybara.server_boot_timeout = 300 # 5 mins
不要将此错误与运行测试时实际使用的Capybara.default_wait_time
相提并论。此外,这两个属性都采用seconds
中的值。
在调用实际的Web驱动程序之前更新这些值。可能就在所有require
陈述之后。
答案 1 :(得分:1)
如果您使用app_host
=“https://mobilebanking.icici.com”
Capybara.app_host = app_host
然后您必须将Capybara.run_server
设置为false
。这是因为如果Capybara.run_server
为true
,那么它将在您计算机上的默认ROR服务器上托管应用程序,然后从浏览器访问localhost以打开Web应用程序。
因此,在Capybara.run_server = false
中设置env.rb
可以解决问题。