watir_pump 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ffaf36b627fe9a96a2e049a78722425468ab4c0
|
4
|
+
data.tar.gz: 22d9a1bab82fb13eb3b5b7e7a469c9fb10798da7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0ba097dc075aeb94799110920f644fc890fc712c101997eb53e209b647fa74ea4a95e93277d3ae6156553e270b8c157f8baa4e4e1d7729c5d9b897d1fca5461
|
7
|
+
data.tar.gz: e80ed1f00a227ef55b67137788e2782a25192f24b3c85915d7897dcff5ba063b2befac8c69160ac59c82870acec82c8a0d0b68b20cb7a832b8cb29cbb4ac68ee
|
data/lib/watir_pump/component.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
require 'forwardable'
|
5
|
+
|
3
6
|
require_relative 'component_collection'
|
4
7
|
require_relative 'decorated_element'
|
5
8
|
require_relative 'constants'
|
6
|
-
|
9
|
+
require_relative 'components/radio_group'
|
10
|
+
require_relative 'components/checkbox_group'
|
11
|
+
require_relative 'components/dropdown_list'
|
7
12
|
|
8
13
|
module WatirPump
|
9
|
-
class Component
|
14
|
+
class Component # rubocop:disable Metrics/ClassLength
|
10
15
|
extend Forwardable
|
11
16
|
|
12
17
|
include Constants
|
@@ -20,39 +25,73 @@ module WatirPump
|
|
20
25
|
# Proxy methods for HTML tags
|
21
26
|
Watir::Container.instance_methods(false).each do |watir_method|
|
22
27
|
define_method watir_method do |name, *args|
|
28
|
+
return if public_methods.include? name
|
23
29
|
define_method(name) do |*loc_args|
|
24
|
-
|
25
|
-
instance_exec(*loc_args, &args.first)
|
26
|
-
else
|
27
|
-
root.send(watir_method, *args)
|
28
|
-
end
|
30
|
+
find_element(watir_method, args, loc_args)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
include Components::RadioGroup
|
36
|
+
include Components::CheckboxGroup
|
37
|
+
include Components::DropdownList
|
38
|
+
|
39
|
+
def self.define_reader(watir_method)
|
38
40
|
define_method "#{watir_method}_reader" do |name, *args|
|
39
41
|
send(watir_method, "#{name}_element", *args)
|
40
42
|
define_method(name) do
|
41
|
-
|
43
|
+
@form_fields << name
|
44
|
+
el = send("#{name}_element")
|
45
|
+
%w[input textarea].include?(el.tag_name) ? el.value : el.text
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
|
47
|
-
Constants::WRITABLES.each do |watir_method|
|
50
|
+
def self.define_writer(watir_method)
|
48
51
|
define_method "#{watir_method}_writer" do |name, *args|
|
49
52
|
send(watir_method, "#{name}_element", *args)
|
50
53
|
define_method("#{name}=") do |value|
|
54
|
+
@form_fields << name
|
51
55
|
send("#{name}_element").set value
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
def self.define_accessor(watir_method)
|
61
|
+
define_method "#{watir_method}_accessor" do |name, *args|
|
62
|
+
send(watir_method, "#{name}_element", *args)
|
63
|
+
# reader, TODO: DRY it up
|
64
|
+
define_method(name) do
|
65
|
+
@form_fields << name
|
66
|
+
el = send("#{name}_element")
|
67
|
+
%w[input textarea].include?(el.tag_name) ? el.value : el.text
|
68
|
+
end
|
69
|
+
# writer, TODO: DRY it up
|
70
|
+
define_method("#{name}=") do |value|
|
71
|
+
@form_fields << name
|
72
|
+
send("#{name}_element").set value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Methods for element content readers
|
78
|
+
# span_reader, :title, id: asd
|
79
|
+
# will create methods :title and :title_element
|
80
|
+
# where :title is a shortcut for :title_element.text
|
81
|
+
Constants::READABLES.each do |watir_method|
|
82
|
+
define_reader(watir_method)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Methods for element content writers
|
86
|
+
Constants::WRITABLES.each do |watir_method|
|
87
|
+
define_writer(watir_method)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Methods for element content accessors
|
91
|
+
(Constants::WRITABLES & Constants::READABLES).each do |watir_method|
|
92
|
+
define_accessor(watir_method)
|
93
|
+
end
|
94
|
+
|
56
95
|
# Methods for element clickers
|
57
96
|
Constants::CLICKABLES.each do |watir_method|
|
58
97
|
define_method "#{watir_method}_clicker" do |name, *args|
|
@@ -68,6 +107,8 @@ module WatirPump
|
|
68
107
|
instance_exec(*args, &p)
|
69
108
|
end
|
70
109
|
end
|
110
|
+
alias element query
|
111
|
+
alias elements query
|
71
112
|
|
72
113
|
def region(name, loc_method = nil, *loc_args, &blk)
|
73
114
|
klass = Class.new(Component) { instance_exec(&blk) }
|
@@ -76,22 +117,20 @@ module WatirPump
|
|
76
117
|
|
77
118
|
def component(name, klass, loc_method = nil, *loc_args)
|
78
119
|
define_method(name) do |*args|
|
79
|
-
node =
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
120
|
+
node = find_element_raw(watir_method: loc_method,
|
121
|
+
watir_method_args: loc_args,
|
122
|
+
code: loc_method,
|
123
|
+
code_args: args)
|
84
124
|
klass.new(browser, self, node)
|
85
125
|
end
|
86
126
|
end
|
87
127
|
|
88
128
|
def components(name, klass, loc_method = nil, *loc_args)
|
89
129
|
define_method(name) do |*args|
|
90
|
-
nodes =
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
130
|
+
nodes = find_element_raw(watir_method: loc_method,
|
131
|
+
watir_method_args: loc_args,
|
132
|
+
code: loc_method,
|
133
|
+
code_args: args)
|
95
134
|
ComponentCollection.new(nodes.map { |n| klass.new(browser, self, n) })
|
96
135
|
end
|
97
136
|
end
|
@@ -111,6 +150,7 @@ module WatirPump
|
|
111
150
|
@browser = browser
|
112
151
|
@parent = parent
|
113
152
|
@root_node = root_node
|
153
|
+
@form_fields = Set.new
|
114
154
|
end
|
115
155
|
|
116
156
|
def root
|
@@ -121,6 +161,33 @@ module WatirPump
|
|
121
161
|
end
|
122
162
|
alias node root
|
123
163
|
|
164
|
+
def fill_form(data)
|
165
|
+
data.to_h.each_pair do |k, v|
|
166
|
+
send("#{k}=", v)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def form_data
|
171
|
+
{}.tap do |h|
|
172
|
+
@form_fields.map { |field| h[field] = send(field) }
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def find_element(watir_method, args, loc_args = nil)
|
177
|
+
find_element_raw(watir_method: watir_method,
|
178
|
+
watir_method_args: args,
|
179
|
+
code: args.first,
|
180
|
+
code_args: loc_args)
|
181
|
+
end
|
182
|
+
|
183
|
+
def find_element_raw(watir_method: nil, watir_method_args: nil, code: nil, code_args: nil) # rubocop:disable Metrics/LineLength
|
184
|
+
if code.is_a? Proc
|
185
|
+
instance_exec(*code_args, &code)
|
186
|
+
elsif watir_method
|
187
|
+
root.send(watir_method, *watir_method_args)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
124
191
|
def method_missing(name, *args)
|
125
192
|
# delegate missing methods to current RSpec example if set
|
126
193
|
example = WatirPump.config.current_example
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WatirPump
|
4
|
+
module Components
|
5
|
+
module CheckboxGroup
|
6
|
+
def checkbox_writer(name, *args) # rubocop:disable Metrics/AbcSize
|
7
|
+
define_method "#{name}=" do |values|
|
8
|
+
@form_fields << name
|
9
|
+
values = Array(values)
|
10
|
+
# <label>value<input /></label>
|
11
|
+
list = find_element(:checkboxes, args)
|
12
|
+
values.each do |value|
|
13
|
+
if list.first.parent.tag_name == 'label'
|
14
|
+
list.find { |el| el.parent.text == value }.set
|
15
|
+
else
|
16
|
+
# <label for='a'>value</label><input id='a' />
|
17
|
+
list.find { |el| el.id == root.label(text: value).for }.set
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def checkbox_reader(name, *args) # rubocop:disable Metrics/AbcSize
|
24
|
+
define_method name do
|
25
|
+
@form_fields << name
|
26
|
+
selected = find_element(:checkboxes, args).select(&:set?)
|
27
|
+
return [] unless selected
|
28
|
+
if selected.first&.parent&.tag_name == 'label'
|
29
|
+
return selected.map { |el| el.parent.text }
|
30
|
+
end
|
31
|
+
selected.map { |el| root.label(for: el.id).text }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def checkbox_accessor(name, *args)
|
36
|
+
checkbox_reader(name, *args)
|
37
|
+
checkbox_writer(name, *args)
|
38
|
+
end
|
39
|
+
alias checkbox_group checkbox_accessor
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WatirPump
|
4
|
+
module Components
|
5
|
+
module DropdownList
|
6
|
+
def select_reader(name, *args)
|
7
|
+
define_method(name) do
|
8
|
+
@form_fields << name
|
9
|
+
select = find_element(:select, args)
|
10
|
+
selected = select.selected_options
|
11
|
+
return select.multiple? ? selected.map(&:text) : selected.first.text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def select_writer(name, *args)
|
16
|
+
define_method("#{name}=") do |values|
|
17
|
+
@form_fields << name
|
18
|
+
select = find_element(:select, args)
|
19
|
+
return select.select(*values)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def select_accessor(name, *args)
|
24
|
+
select_reader(name, *args)
|
25
|
+
select_writer(name, *args)
|
26
|
+
end
|
27
|
+
alias dropdown_list select_accessor
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WatirPump
|
4
|
+
module Components
|
5
|
+
module RadioGroup
|
6
|
+
def radio_reader(name, *args)
|
7
|
+
define_method name do |*loc_args|
|
8
|
+
@form_fields << name
|
9
|
+
list = find_element(:radios, args, loc_args)
|
10
|
+
selected = list.find(&:set?)
|
11
|
+
if selected
|
12
|
+
return selected.parent.text if selected&.parent&.tag_name == 'label'
|
13
|
+
return root.label(for: selected.id).text
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def radio_writer(name, *args) # rubocop:disable Metrics/AbcSize
|
19
|
+
define_method "#{name}=" do |value|
|
20
|
+
@form_fields << name
|
21
|
+
list = find_element(:radios, args)
|
22
|
+
# <label>value<input /></label>
|
23
|
+
if list.first.parent.tag_name == 'label'
|
24
|
+
list.find { |el| el.parent.text == value }.set
|
25
|
+
else
|
26
|
+
# <label for='a'>value</label><input id='a' />
|
27
|
+
list.find { |el| el.id == root.label(text: value).for }.set
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def radio_accessor(name, *args)
|
33
|
+
radio_reader(name, *args)
|
34
|
+
radio_writer(name, *args)
|
35
|
+
end
|
36
|
+
alias radio_group radio_accessor
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/watir_pump/constants.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir_pump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartek Wilczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -131,6 +131,9 @@ files:
|
|
131
131
|
- lib/watir_pump.rb
|
132
132
|
- lib/watir_pump/component.rb
|
133
133
|
- lib/watir_pump/component_collection.rb
|
134
|
+
- lib/watir_pump/components/checkbox_group.rb
|
135
|
+
- lib/watir_pump/components/dropdown_list.rb
|
136
|
+
- lib/watir_pump/components/radio_group.rb
|
134
137
|
- lib/watir_pump/constants.rb
|
135
138
|
- lib/watir_pump/decorated_element.rb
|
136
139
|
- lib/watir_pump/page.rb
|