-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.2.2_locate_using_element_method.rb
37 lines (29 loc) · 1.17 KB
/
2.2.2_locate_using_element_method.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
# frozen_string_literal: true
class GreeterPage2_2_2 < WatirPump::Page
uri '/greeter.html'
# `element` macro acts similarly as macros specific to certain Watir methods
# It does validate that the returned value is a generic Element,
# while the former validate the exact element type
element :name, -> { root.text_field(id: 'name') }
element :set, ->(id) { root.button(id: id) }
element :greeting, -> { root.div(id: 'greeting') }
element :greeted_name, -> { greeting.span }
# If lambda returns invalid value (here a String instead of an Element)
# an exception will be raised
element :not_an_element, -> { greeting.span.text }
end
RSpec.describe GreeterPage2_2_2 do
it 'displays greeting' do
GreeterPage2_2_2.open do
expect(name).to be_a(Watir::TextField)
name.set 'Bogdan'
expect(set('set_name')).to be_a(Watir::Button)
set('set_name').click
expect(greeting).to be_a(Watir::Div)
expect(greeting.text).to eq 'Hello Bogdan!'
expect(greeted_name).to be_a(Watir::Span)
expect(greeted_name.text).to eq 'Bogdan'
expect { not_an_element }.to raise_error(WatirPump::Errors::ElementMismatch)
end
end
end