mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
rename default_wait_time to default_max_wait_time - Issue #1442
This commit is contained in:
parent
37ee1a3cc3
commit
5b6d65feae
15 changed files with 57 additions and 36 deletions
|
@ -709,7 +709,7 @@ looking for that content for a brief time. You can adjust how long this period
|
|||
is (the default is 2 seconds):
|
||||
|
||||
```ruby
|
||||
Capybara.default_wait_time = 5
|
||||
Capybara.default_max_wait_time = 5
|
||||
```
|
||||
|
||||
Be aware that because of this behaviour, the following two statements are **not**
|
||||
|
|
|
@ -21,7 +21,7 @@ module Capybara
|
|||
class << self
|
||||
attr_accessor :asset_host, :app_host, :run_server, :default_host, :always_include_port
|
||||
attr_accessor :server_port, :exact, :match, :exact_options, :visible_text_only
|
||||
attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
|
||||
attr_accessor :default_selector, :default_max_wait_time, :ignore_hidden_elements
|
||||
attr_accessor :save_and_open_page_path, :wait_on_first_by_default, :automatic_reload, :raise_server_errors, :server_errors
|
||||
attr_writer :default_driver, :current_driver, :javascript_driver, :session_name, :server_host
|
||||
attr_accessor :app
|
||||
|
@ -44,7 +44,7 @@ module Capybara
|
|||
# [raise_server_errors = Boolean] Should errors raised in the server be raised in the tests? (Default: true)
|
||||
# [server_errors = Array\<Class\>] Error classes that should be raised in the tests if they are raised in the server and Capybara.raise_server_errors is true (Default: [StandardError])
|
||||
# [default_selector = :css/:xpath] Methods which take a selector use the given type by default (Default: :css)
|
||||
# [default_wait_time = Integer] The maximumnumber of seconds to wait for asynchronous processes to finish (Default: 2)
|
||||
# [default_max_wait_time = Numeric] The maximum number of seconds to wait for asynchronous processes to finish (Default: 2)
|
||||
# [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: true)
|
||||
# [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
|
||||
# [save_and_open_page_path = String] Where to put pages saved through save_and_open_page (Default: Dir.pwd)
|
||||
|
@ -233,11 +233,11 @@ module Capybara
|
|||
# Yield a block using a specific wait time
|
||||
#
|
||||
def using_wait_time(seconds)
|
||||
previous_wait_time = Capybara.default_wait_time
|
||||
Capybara.default_wait_time = seconds
|
||||
previous_wait_time = Capybara.default_max_wait_time
|
||||
Capybara.default_max_wait_time = seconds
|
||||
yield
|
||||
ensure
|
||||
Capybara.default_wait_time = previous_wait_time
|
||||
Capybara.default_max_wait_time = previous_wait_time
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -295,6 +295,18 @@ module Capybara
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# @deprecated Use default_max_wait_time instead
|
||||
def default_wait_time
|
||||
deprecate('default_wait_time', 'default_max_wait_time')
|
||||
default_max_wait_time
|
||||
end
|
||||
|
||||
# @deprecated Use default_max_wait_time= instead
|
||||
def default_wait_time=(t)
|
||||
deprecate('default_wait_time=', 'default_max_wait_time=')
|
||||
self.default_max_wait_time = t
|
||||
end
|
||||
|
||||
def included(base)
|
||||
base.send(:include, Capybara::DSL)
|
||||
|
@ -360,7 +372,7 @@ Capybara.configure do |config|
|
|||
config.run_server = true
|
||||
config.server {|app, port| Capybara.run_default_server(app, port)}
|
||||
config.default_selector = :css
|
||||
config.default_wait_time = 2
|
||||
config.default_max_wait_time = 2
|
||||
config.ignore_hidden_elements = true
|
||||
config.default_host = "http://www.example.com"
|
||||
config.automatic_reload = true
|
||||
|
|
|
@ -61,7 +61,7 @@ module Capybara
|
|||
#
|
||||
# As long as any of these exceptions are thrown, the block is re-run,
|
||||
# until a certain amount of time passes. The amount of time defaults to
|
||||
# {Capybara.default_wait_time} and can be overridden through the `seconds`
|
||||
# {Capybara.default_max_wait_time} and can be overridden through the `seconds`
|
||||
# argument. This time is compared with the system time to see how much
|
||||
# time has passed. On rubies/platforms which don't support access to a monotonic process clock
|
||||
# if the return value of `Time.now` is stubbed out, Capybara will raise `Capybara::FrozenInTime`.
|
||||
|
@ -73,7 +73,7 @@ module Capybara
|
|||
# @return [Object] The result of the given block
|
||||
# @raise [Capybara::FrozenInTime] If the return value of `Time.now` appears stuck
|
||||
#
|
||||
def synchronize(seconds=Capybara.default_wait_time, options = {})
|
||||
def synchronize(seconds=Capybara.default_max_wait_time, options = {})
|
||||
start_time = Capybara::Helpers.monotonic_time
|
||||
|
||||
if session.synchronized
|
||||
|
|
|
@ -9,7 +9,7 @@ module Capybara
|
|||
# @param string [String] The string that title should include
|
||||
# @overload $0(regexp, options = {})
|
||||
# @param regexp [Regexp] The regexp that title should match to
|
||||
# @option options [Numeric] :wait (Capybara.default_wait_time) Time that Capybara will wait for title to eq/match given string/regexp argument
|
||||
# @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for title to eq/match given string/regexp argument
|
||||
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
|
||||
# @return [true]
|
||||
#
|
||||
|
|
|
@ -9,7 +9,7 @@ module Capybara
|
|||
#
|
||||
# If the driver is capable of executing JavaScript, +find+ will wait for a set amount of time
|
||||
# and continuously retry finding the element until either the element is found or the time
|
||||
# expires. The length of time +find+ will wait is controlled through {Capybara.default_wait_time}
|
||||
# expires. The length of time +find+ will wait is controlled through {Capybara.default_max_wait_time}
|
||||
# and defaults to 2 seconds.
|
||||
#
|
||||
# +find+ takes the same options as +all+.
|
||||
|
|
|
@ -437,14 +437,14 @@ module Capybara
|
|||
# @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur
|
||||
# @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur
|
||||
# @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs
|
||||
# @option options [Numeric] :wait (Capybara.default_wait_time) Time that Capybara will wait for text to eq/match given string/regexp argument
|
||||
# @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for text to eq/match given string/regexp argument
|
||||
# @overload $0(text, options = {})
|
||||
# @param [String, Regexp] text The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.
|
||||
# @option options [Integer] :count (nil) Number of times the text is expected to occur
|
||||
# @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur
|
||||
# @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur
|
||||
# @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs
|
||||
# @option options [Numeric] :wait (Capybara.default_wait_time) Time that Capybara will wait for text to eq/match given string/regexp argument
|
||||
# @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for text to eq/match given string/regexp argument
|
||||
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
|
||||
# @return [true]
|
||||
#
|
||||
|
|
|
@ -10,7 +10,7 @@ module Capybara
|
|||
if @options.has_key?(:wait)
|
||||
@options[:wait] || 0
|
||||
else
|
||||
Capybara.default_wait_time
|
||||
Capybara.default_max_wait_time
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ module Capybara
|
|||
# @example
|
||||
# expect(window).to become_closed(wait: 0.8)
|
||||
# @param options [Hash] optional param
|
||||
# @option options [Numeric] :wait (Capybara.default_wait_time) wait time
|
||||
# @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum wait time
|
||||
def become_closed(options = {})
|
||||
BecomeClosed.new(options)
|
||||
end
|
||||
|
|
|
@ -266,7 +266,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
# Selenium has its own built in wait (2 seconds)for a modal to show up, so this wait is really the minimum time
|
||||
# Actual wait time may be longer than specified
|
||||
wait = Selenium::WebDriver::Wait.new(
|
||||
timeout: (options[:wait] || Capybara.default_wait_time),
|
||||
timeout: (options[:wait] || Capybara.default_max_wait_time),
|
||||
ignore: Selenium::WebDriver::Error::NoAlertPresentError)
|
||||
begin
|
||||
wait.until do
|
||||
|
|
|
@ -480,7 +480,7 @@ module Capybara
|
|||
# {https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html#h_note_10 as order of windows isn't defined in some drivers}
|
||||
#
|
||||
# @param options [Hash]
|
||||
# @option options [Numeric] :wait (Capybara.default_wait_time) wait time
|
||||
# @option options [Numeric] :wait (Capybara.default_max_wait_time) maximum wait time
|
||||
# @return [Capybara::Window] the window that has been opened within a block
|
||||
# @raise [Capybara::WindowError] if block passed to window hasn't opened window
|
||||
# or opened more than one window
|
||||
|
@ -561,7 +561,7 @@ module Capybara
|
|||
else
|
||||
options[:text]=text_or_options
|
||||
end
|
||||
|
||||
|
||||
driver.accept_modal(:confirm, options, &blk)
|
||||
end
|
||||
|
||||
|
@ -577,7 +577,7 @@ module Capybara
|
|||
else
|
||||
options[:text]=text_or_options
|
||||
end
|
||||
|
||||
|
||||
driver.dismiss_modal(:confirm, options, &blk)
|
||||
end
|
||||
|
||||
|
@ -594,7 +594,7 @@ module Capybara
|
|||
else
|
||||
options[:text]=text_or_options
|
||||
end
|
||||
|
||||
|
||||
driver.accept_modal(:prompt, options, &blk)
|
||||
end
|
||||
|
||||
|
@ -610,7 +610,7 @@ module Capybara
|
|||
else
|
||||
options[:text]=text_or_options
|
||||
end
|
||||
|
||||
|
||||
driver.dismiss_modal(:prompt, options, &blk)
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
|
|||
end
|
||||
|
||||
context 'without :wait option' do
|
||||
it 'should wait if value of default_wait_time is more than timeout' do
|
||||
it 'should wait if value of default_max_wait_time is more than timeout' do
|
||||
@session.within_window @other_window do
|
||||
@session.execute_script('setTimeout(function(){ window.close(); }, 500);')
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should raise error if value of default_wait_time is less than timeout' do
|
||||
it 'should raise error if value of default_max_wait_time is less than timeout' do
|
||||
@session.within_window @other_window do
|
||||
@session.execute_script('setTimeout(function(){ window.close(); }, 900);')
|
||||
end
|
||||
|
@ -59,7 +59,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
|
|||
end
|
||||
|
||||
context 'with not_to' do
|
||||
it 'should raise error if default_wait_time is more than timeout' do
|
||||
it 'should raise error if default_max_wait_time is more than timeout' do
|
||||
@session.within_window @other_window do
|
||||
@session.execute_script('setTimeout(function(){ window.close(); }, 700);')
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should raise error if default_wait_time is more than timeout' do
|
||||
it 'should raise error if default_max_wait_time is more than timeout' do
|
||||
@session.within_window @other_window do
|
||||
@session.execute_script('setTimeout(function(){ window.close(); }, 700);')
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|||
end
|
||||
|
||||
context 'without :wait option' do
|
||||
it 'should raise error if default_wait_time is less than timeout' do
|
||||
it 'should raise error if default_max_wait_time is less than timeout' do
|
||||
Capybara.using_wait_time 0.4 do
|
||||
expect do
|
||||
@session.window_opened_by do
|
||||
|
@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should find window if default_wait_time is more than timeout' do
|
||||
it 'should find window if default_max_wait_time is more than timeout' do
|
||||
Capybara.using_wait_time 1.5 do
|
||||
window = @session.window_opened_by do
|
||||
@session.find(:css, '#openWindowWithTimeout').click
|
||||
|
|
|
@ -26,7 +26,7 @@ module Capybara
|
|||
Capybara.app = TestApp
|
||||
Capybara.app_host = nil
|
||||
Capybara.default_selector = :xpath
|
||||
Capybara.default_wait_time = 1
|
||||
Capybara.default_max_wait_time = 1
|
||||
Capybara.ignore_hidden_elements = true
|
||||
Capybara.exact = false
|
||||
Capybara.exact_options = false
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Capybara do
|
||||
describe 'default_wait_time' do
|
||||
describe 'default_max_wait_time' do
|
||||
after do
|
||||
Capybara.default_wait_time = @previous_default_time
|
||||
Capybara.default_max_wait_time = @previous_default_time
|
||||
end
|
||||
|
||||
it "should be changeable" do
|
||||
@previous_default_time = Capybara.default_wait_time
|
||||
@previous_default_time = Capybara.default_max_wait_time
|
||||
Capybara.default_max_wait_time = 5
|
||||
expect(Capybara.default_max_wait_time).to eq(5)
|
||||
end
|
||||
|
||||
it "should be accesible as the deprecated default_wait_time" do
|
||||
expect_any_instance_of(Kernel).to receive(:warn).once.with('DEPRECATED: #default_wait_time= is deprecated, please use #default_max_wait_time= instead')
|
||||
expect_any_instance_of(Kernel).to receive(:warn).once.with('DEPRECATED: #default_wait_time is deprecated, please use #default_max_wait_time instead')
|
||||
@previous_default_time = Capybara.default_max_wait_time
|
||||
Capybara.default_wait_time = 5
|
||||
expect(Capybara.default_wait_time).to eq(5)
|
||||
expect(Capybara.default_max_wait_time).to eq(5)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -116,20 +116,20 @@ RSpec.describe Capybara::DSL do
|
|||
|
||||
describe '#using_wait_time' do
|
||||
before do
|
||||
@previous_wait_time = Capybara.default_wait_time
|
||||
@previous_wait_time = Capybara.default_max_wait_time
|
||||
end
|
||||
|
||||
after do
|
||||
Capybara.default_wait_time = @previous_wait_time
|
||||
Capybara.default_max_wait_time = @previous_wait_time
|
||||
end
|
||||
|
||||
it "should switch the wait time and switch it back" do
|
||||
in_block = nil
|
||||
Capybara.using_wait_time 6 do
|
||||
in_block = Capybara.default_wait_time
|
||||
in_block = Capybara.default_max_wait_time
|
||||
end
|
||||
expect(in_block).to eq(6)
|
||||
expect(Capybara.default_wait_time).to eq(@previous_wait_time)
|
||||
expect(Capybara.default_max_wait_time).to eq(@previous_wait_time)
|
||||
end
|
||||
|
||||
it "should ensure wait time is reset" do
|
||||
|
@ -138,7 +138,7 @@ RSpec.describe Capybara::DSL do
|
|||
raise "hell"
|
||||
end
|
||||
end.to raise_error
|
||||
expect(Capybara.default_wait_time).to eq(@previous_wait_time)
|
||||
expect(Capybara.default_max_wait_time).to eq(@previous_wait_time)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue