Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/integration/selenium/webdriver/timeout_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 Timeouts, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do
25
before do
26
driver.manage.timeouts.implicit_wait = 6
27
driver.manage.timeouts.page_load = 2
28
driver.manage.timeouts.script = 1.5
29
driver.navigate.to url_for('dynamic.html')
30
end
31
32
after do
33
driver.manage.timeouts.implicit_wait = 0
34
driver.manage.timeouts.page_load = 300
35
driver.manage.timeouts.script = 30
36
end
37
38
it 'gets all the timeouts' do
39
expect(driver.manage.timeouts.implicit_wait).to eq(6)
40
expect(driver.manage.timeouts.page_load).to eq(2)
41
expect(driver.manage.timeouts.script).to eq(1.5)
42
end
43
44
describe 'implicit waits' do
45
it 'implicitlies wait for a single element' do
46
driver.find_element(id: 'adder').click
47
expect { driver.find_element(id: 'box0') }.not_to raise_error
48
end
49
50
it 'stills fail to find an element with implicit waits enabled' do
51
driver.manage.timeouts.implicit_wait = 0.1
52
expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)
53
end
54
55
it 'returns after first attempt to find one after disabling implicit waits' do
56
driver.manage.timeouts.implicit_wait = 0
57
expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)
58
end
59
60
it 'implicitlies wait until at least one element is found when searching for many' do
61
add = driver.find_element(id: 'adder')
62
63
add.click
64
add.click
65
66
expect(driver.find_elements(class_name: 'redbox')).not_to be_empty
67
end
68
69
it 'stills fail to find elements when implicit waits are enabled' do
70
driver.manage.timeouts.implicit_wait = 0.1
71
expect(driver.find_elements(class_name: 'redbox')).to be_empty
72
end
73
74
it 'returns after first attempt to find many after disabling implicit waits' do
75
add = driver.find_element(id: 'adder')
76
77
driver.manage.timeouts.implicit_wait = 0
78
add.click
79
80
expect(driver.find_elements(class_name: 'redbox')).to be_empty
81
end
82
end
83
84
describe 'page load' do
85
it 'times out if page takes too long to load' do
86
expect { driver.navigate.to url_for('sleep?time=3') }.to raise_error(WebDriver::Error::TimeoutError)
87
end
88
89
it 'times out if page takes too long to load after click', except: {browser: %i[safari safari_preview]} do
90
driver.navigate.to url_for('page_with_link_to_slow_loading_page.html')
91
92
expect {
93
driver.find_element(id: 'link-to-slow-loading-page').click
94
}.to raise_error(WebDriver::Error::TimeoutError)
95
end
96
end
97
end
98
end # WebDriver
99
end # Selenium
100
101