Reputation: 529
I'm trying to launch a webpage using capybara & selenium webdriver using cucumber. A browser is launched but it's not able to load the url. Below is my env.rb
file
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
The error i get is below
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 [email protected] 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 [email protected] 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
Upvotes: 0
Views: 5315
Reputation: 11
If you are using app_host
= "https://mobilebanking.icici.com"
Capybara.app_host = app_host
Then you have to set Capybara.run_server
to false
. This is because if Capybara.run_server
is true
then it will host the app on default ROR server on your machine and then hit localhost from browser to open the web app.
So, setting Capybara.run_server = false
in env.rb
should resolve the issue.
Upvotes: 1
Reputation: 3827
EDIT : server_boot_timeout
has been removed in Capybara 2.
For Capybara 2
You could try putting a wait.until
and see if it helps. You will need to require 'selenium-webdriver'
at the top of the file.
Change the following line:
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
to this:
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" }
If this does not work you could also try using plain old ruby sleep.
sleep(5.minutes)
For Capybara < 2
Try increasing the Capybara.server_boot_timeout
value. Use the following (add the line if it does not exist) in your env.rb
file.
Capybara.server_boot_timeout = 300 # 5 mins
Do not mistake this with Capybara.default_wait_time
which is actually used when running the tests. Also both these properties take values in seconds
.
Update these values before calling the actual web driver. Probably just after all the require
statements.
Upvotes: 2