-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.3_custom_loaded_condition_spec.rb
43 lines (35 loc) · 1.39 KB
/
1.3_custom_loaded_condition_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true
class IndexPage1_3 < WatirPump::Page
uri '/index.html'
link :slow_greeter_link, href: 'greeter.html?random_delay=1'
end
# This greeter page shows its content after a random delay.
# `header` will not be displayed at once, although the HTML is loaded.
# One can consider that `header` is loaded using another request (XHR).
class SlowGreeterPage < WatirPump::Page
uri '/greeter.html?random_delay=1'
h1 :header
end
# This greeter page overwrites default mechanism for declaring page's "readiness".
# Method `loaded?` returns true after `header` has been loaded and is visible.
class FixedSlowGreeterPage < WatirPump::Page
uri '/greeter.html?random_delay=1'
h1 :header
def loaded?
header.present?
end
end
RSpec.describe 'Navigation with links' do
it 'finds empty header on an incomplete page' do
IndexPage1_3.open { slow_greeter_link.click }
# Default implementation of `loaded?` is used below.
# Reports page as loaded before all XHR calls are processed.
SlowGreeterPage.use { expect(header.text).to be_empty }
end
it 'finds proper header on a complete page' do
IndexPage1_3.open { slow_greeter_link.click }
# Custom implementation of `loaded?` is used below.
# Reports page as loaded when criteria explicity stated in `loaded?` method are met.
FixedSlowGreeterPage.use { expect(header.text).to include 'Greeter' }
end
end