2

I have a rails project, which I'm testing with rspec/capybara/poltergeist/phantomjs. I know I can increase the general poltergeist timeout with the general settings

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, timeout: 2.minutes)
end

But is there a way to increase the timeout for a specific request?

I have a page with a button (id=submit) which kicks off a longish (90-120 seconds) running process, before returning. I'm working on optimizing the back end to shorten the request time, but in the meanwhile, I want to increase the timeout for that specific request when testing, so something along the lines of

click_button 'submit', wait: 180
sirlark
  • 2,187
  • 2
  • 18
  • 28
  • It seems you can do this by [switching drivers out](http://stackoverflow.com/questions/31383385/capybara-increase-max-allowed-page-load-time) – sirlark Feb 16 '16 at 10:07

2 Answers2

6

You can do

Capybara.using_wait_time(180) do
   click_button 'submit'
end

Another thing you can do is

 # capybara.rb

 Capybara.register_driver :poltergeist do |app|
     Capybara::Poltergeist::Driver.new(app, timeout: 30)
 end

 Capybara.register_driver :poltergeist_long do |app|
     Capybara::Poltergeist::Driver.new(app, timeout: 180)
 end


 # wherever.rb

 session = Capybara::Session.new(:poltergeist_long)
 session.visit("http://thatlongwaittime.com")
gmaliar
  • 5,294
  • 1
  • 28
  • 36
  • Doesn't this affect Capybara's wait_time, which is the amount of time Capybara will wait for javascript and other non-intrinsic page assets to load, and execute, rather than Poltergeist's read timeout? – sirlark Feb 16 '16 at 09:59
1

Timeuouts for specific requests can be increased by increasing the value of default wait time which is generally configured in you env.rb file. To understand this well lets take below mention code:

Cucumber file:

When Joe is on abc page
Then Joe clicks submit button

Step definition for clicking submit button:

Then(/^Then Joe clicks submit button$/) do
  Capybara.default_wait_time = 120  // increasing the default wait time to 180 seconds
  click_button('submit')  // performing the action
  Capybara.default_wait_time = DEFAULT_WAIT_TIME  // reset the wait time to its default value after clicking submit button.
end

Note: The value of DEFAULT_WAIT_TIME can be configured in env.rb file

Hope this helps :)

Sarabjit Singh
  • 786
  • 4
  • 4