Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/wait_spec.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require_relative 'spec_helper'
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
70
71