|
22 | 22 | module Selenium
|
23 | 23 | module WebDriver
|
24 | 24 | describe Timeouts do
|
25 |
| - context 'implicit waits' do |
26 |
| - before do |
27 |
| - driver.manage.timeouts.implicit_wait = 0 |
28 |
| - driver.navigate.to url_for('dynamic.html') |
29 |
| - end |
| 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 |
30 | 31 |
|
31 |
| - after { driver.manage.timeouts.implicit_wait = 0 } |
| 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 |
32 | 37 |
|
33 |
| - it 'should implicitly wait for a single element' do |
34 |
| - driver.manage.timeouts.implicit_wait = 6 |
| 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 |
35 | 43 |
|
| 44 | + context 'implicit waits' do |
| 45 | + it 'should implicitly wait for a single element' do |
36 | 46 | driver.find_element(id: 'adder').click
|
37 | 47 | expect { driver.find_element(id: 'box0') }.not_to raise_error
|
38 | 48 | end
|
39 | 49 |
|
40 | 50 | it 'should still fail to find an element with implicit waits enabled' do
|
41 |
| - driver.manage.timeouts.implicit_wait = 0.5 |
| 51 | + driver.manage.timeouts.implicit_wait = 0.1 |
42 | 52 | expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)
|
43 | 53 | end
|
44 | 54 |
|
45 | 55 | it 'should return after first attempt to find one after disabling implicit waits' do
|
46 |
| - driver.manage.timeouts.implicit_wait = 3 |
47 | 56 | driver.manage.timeouts.implicit_wait = 0
|
48 |
| - |
49 | 57 | expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)
|
50 | 58 | end
|
51 | 59 |
|
52 | 60 | it 'should implicitly wait until at least one element is found when searching for many' do
|
53 | 61 | add = driver.find_element(id: 'adder')
|
54 | 62 |
|
55 |
| - driver.manage.timeouts.implicit_wait = 6 |
56 | 63 | add.click
|
57 | 64 | add.click
|
58 | 65 |
|
59 | 66 | expect(driver.find_elements(class_name: 'redbox')).not_to be_empty
|
60 | 67 | end
|
61 | 68 |
|
62 | 69 | it 'should still fail to find elements when implicit waits are enabled' do
|
63 |
| - driver.manage.timeouts.implicit_wait = 0.5 |
| 70 | + driver.manage.timeouts.implicit_wait = 0.1 |
64 | 71 | expect(driver.find_elements(class_name: 'redbox')).to be_empty
|
65 | 72 | end
|
66 | 73 |
|
67 | 74 | it 'should return after first attempt to find many after disabling implicit waits' do
|
68 | 75 | add = driver.find_element(id: 'adder')
|
69 | 76 |
|
70 |
| - driver.manage.timeouts.implicit_wait = 3 |
71 | 77 | driver.manage.timeouts.implicit_wait = 0
|
72 | 78 | add.click
|
73 | 79 |
|
74 | 80 | expect(driver.find_elements(class_name: 'redbox')).to be_empty
|
75 | 81 | end
|
76 | 82 | end
|
77 | 83 |
|
78 |
| - context 'page loads' do |
79 |
| - before { driver.manage.timeouts.page_load = 2 } |
80 |
| - |
81 |
| - after { driver.manage.timeouts.page_load = 300 } |
82 |
| - |
| 84 | + context 'page load' do |
83 | 85 | it 'should timeout if page takes too long to load' do
|
84 | 86 | expect { driver.navigate.to url_for('sleep?time=3') }.to raise_error(WebDriver::Error::TimeoutError)
|
85 | 87 | end
|
|
0 commit comments