Search code examples
rubycucumbergopro

Set capybara default_wait_time to a function


I made a function called wait_for_page load, and I am trying to set the default_wait_time to this function.

I get an undefined variable error:

undefined local variable or method `page' for main:Object (NameError)

I also included the file into the main environment file:

require File.expand_path('../../support/file_name.rb', FILE)


Solution

  • default_wait_time is an accessor in Capybara module. So you'll need to call it on the Capybara object itself, like:

    Capybara.default_wait_time = some_value
    

    And Capybara object should be available wherever you have defined this method.

    In some newer versions accessor is default_max_wait_time, you can notice this because of a DEPRECATION warning So you need to do this:

    Capybara.default_max_wait_time = 5
    

    The default is 2 seconds