Cucumber Selenium webdriver无法在基于capybara的框架中打开网页
我正在尝试使用capybara和SeleniumWebDriver(使用cucumber)启动一个网页。浏览器已启动,但无法加载url。下面是我的Cucumber Selenium webdriver无法在基于capybara的框架中打开网页,cucumber,capybara,selenium-webdriver,Cucumber,Capybara,Selenium Webdriver,我正在尝试使用capybara和SeleniumWebDriver(使用cucumber)启动一个网页。浏览器已启动,但无法加载url。下面是我的env.rb文件 begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end require 'capybara' require 'capybara/dsl' require 'capybara/cucumber' require
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
编辑:
已删除Capybara 2中的服务器启动超时
水豚2号的
您可以尝试放置一个等待,直到,看看是否有帮助。您需要在文件顶部要求“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" }
如果这不起作用,您也可以尝试使用普通的旧ruby睡眠
sleep(5.minutes)
水豚<2
尝试增加Capybara.server\u boot\u timeout
值。在env.rb
文件中使用以下命令(如果该行不存在,则添加该行)
Capybara.server_boot_timeout = 300 # 5 mins
不要将此错误与运行测试时实际使用的Capybara.default\u wait\u time
相混淆。此外,这两个属性都以秒为单位取值
在调用实际的web驱动程序之前更新这些值。可能就在所有require
语句之后。编辑:服务器启动超时已在Capybara 2中删除
水豚2号的
您可以尝试放置一个等待,直到,看看是否有帮助。您需要在文件顶部要求“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" }
如果这不起作用,您也可以尝试使用普通的旧ruby睡眠
sleep(5.minutes)
水豚<2
尝试增加Capybara.server\u boot\u timeout
值。在env.rb
文件中使用以下命令(如果该行不存在,则添加该行)
Capybara.server_boot_timeout = 300 # 5 mins
不要将此错误与运行测试时实际使用的Capybara.default\u wait\u time
相混淆。此外,这两个属性都以秒为单位取值
在调用实际的web驱动程序之前更新这些值。可能就在所有需要语句之后。如果您使用的是app\u host
=“”
Capybara.app\u host=app\u host
然后您必须将Capybara.run\u server
设置为false
。这是因为如果Capybara.run\u server
为true
,则它将在您机器上的默认ROR服务器上托管应用程序,然后从浏览器点击localhost以打开web应用程序
因此,在env.rb
中设置Capybara.run\u server=false应该可以解决这个问题。如果您使用的是app\u host
=“”
Capybara.app\u host=app\u host
然后您必须将Capybara.run\u server
设置为false
。这是因为如果Capybara.run\u server
为true
,则它将在您机器上的默认ROR服务器上托管应用程序,然后从浏览器点击localhost以打开web应用程序
因此,在env.rb
中设置Capybara.run\u server=false应该可以解决问题。在等待浏览器启动后,selenium似乎已经超时。您应该尝试增加浏览器启动的webdriver等待时间。如果使用“Capybara.default\u wait\u time=10”增加默认等待时间,则不太可能。我认为问题与代理有关,因为我在浏览器中使用代理,我观察到webdriver启动的浏览器没有代理设置,而我的实际浏览器启用了代理设置。似乎selenium在等待浏览器启动后超时。您应该尝试增加浏览器启动的webdriver等待时间。如果使用“Capybara.default\u wait\u time=10”增加默认等待时间,则不太可能。我认为问题与代理有关,因为我在浏览器中使用代理,我观察到webdriver启动的浏览器没有代理设置,而我的实际浏览器启用了代理设置。在我的env.rb文件中添加了“Capybara.server\u boot\u timeout=300”,然后运行我的脚本。它在我的env.rb文件中添加了“Capybara.server\u boot\u timeout=300”,然后运行我的脚本。它说“未定义的方法‘server_boot_timeout=’for Capybara:Module”这比使用Tanzeel的selenium工作得很好,而且比使用Tanzeel的selenium干净得多。