| 21 | |
| 22 | module Selenium |
| 23 | module WebDriver |
| 24 | describe Wait do |
| 25 | def wait(*args) |
| 26 | Wait.new(*args) |
| 27 | end |
| 28 | |
| 29 | it 'waits until the returned value is true' do |
| 30 | returned = true |
| 31 | expect(wait.until { returned = !returned }).to be true |
| 32 | end |
| 33 | |
| 34 | it 'raises a TimeoutError if the the timer runs out' do |
| 35 | expect { |
| 36 | wait(timeout: 0.1).until { false } |
| 37 | }.to raise_error(Error::TimeoutError) |
| 38 | end |
| 39 | |
| 40 | it 'silentlies capture NoSuchElementErrors' do |
| 41 | called = false |
| 42 | block = lambda do |
| 43 | if called |
| 44 | true |
| 45 | else |
| 46 | called = true |
| 47 | raise Error::NoSuchElementError |
| 48 | end |
| 49 | end |
| 50 | |
| 51 | expect(wait.until(&block)).to be true |
| 52 | end |
| 53 | |
| 54 | it 'uses the message from any NoSuchElementError raised while waiting' do |
| 55 | block = -> { raise Error::NoSuchElementError, 'foo' } |
| 56 | |
| 57 | expect { |
| 58 | wait(timeout: 0.5).until(&block) |
| 59 | }.to raise_error(Error::TimeoutError, /foo/) |
| 60 | end |
| 61 | |
| 62 | it 'lets users configure what exceptions to ignore' do |
| 63 | expect { |
| 64 | wait(ignore: NoMethodError, timeout: 0.5).until { raise NoMethodError } |
| 65 | }.to raise_error(Error::TimeoutError, /NoMethodError/) |
| 66 | end |
| 67 | end |
| 68 | end # WebDriver |
| 69 | end # Selenium |