sirlark
sirlark

Reputation: 2207

Increase poltergeist timeout for a specific capybara click_button call

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

Upvotes: 2

Views: 2315

Answers (2)

Sarabjit Singh
Sarabjit Singh

Reputation: 790

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 :)

Upvotes: 1

gmaliar
gmaliar

Reputation: 5489

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")

Upvotes: 6

Related Questions