0

我正在尝试使用水豚和使用黄瓜的硒网络驱动程序启动网页。浏览器已启动,但无法加载 url。下面是我的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
4

2 回答 2

2

编辑: server_boot_timeout已在 Capybara 2 中删除。

对于 Capybara 2
您可以尝试放置 await.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声明之后。

于 2013-01-08T09:53:52.077 回答
1

如果您使用app_host=“ https://mobilebanking.icici.com

Capybara.app_host = app_host

然后你必须设置Capybara.run_serverfalse. 这是因为如果Capybara.run_server是,true那么它将在您机器上的默认 ROR 服务器上托管应用程序,然后从浏览器中点击 localhost 以打开 Web 应用程序。

因此,设置Capybara.run_server = false应该env.rb可以解决问题。

于 2013-03-10T17:44:42.757 回答