watirsome 0.1.6 → 0.1.7
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 +4 -4
- data/.rubocop.yml +19 -0
- data/.travis.yml +6 -3
- data/CHANGELOG.md +5 -0
- data/LICENSE.md +1 -1
- data/README.md +3 -3
- data/Rakefile +7 -5
- data/doctest_helper.rb +16 -0
- data/lib/watirsome.rb +89 -49
- data/lib/watirsome/accessors.rb +22 -45
- data/lib/watirsome/errors.rb +1 -5
- data/lib/watirsome/initializers.rb +43 -15
- data/lib/watirsome/version.rb +1 -1
- data/support/doctest.html +16 -0
- data/watirsome.gemspec +4 -7
- metadata +12 -59
- data/.coveralls.yml +0 -1
- data/spec/lib/watirsome/accessors_spec.rb +0 -20
- data/spec/lib/watirsome/errors_spec.rb +0 -5
- data/spec/lib/watirsome/initializers_spec.rb +0 -38
- data/spec/lib/watirsome_spec.rb +0 -109
- data/spec/spec_helper.rb +0 -31
- data/spec/support/page.rb +0 -52
- data/spec/support/shared_examples/click_accessor.rb +0 -53
- data/spec/support/shared_examples/element_accessor.rb +0 -48
- data/spec/support/shared_examples/read_accessor.rb +0 -68
- data/spec/support/shared_examples/select_accessor.rb +0 -47
- data/spec/support/shared_examples/set_accessor.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe636cb3b0cae995c534f29c111f641c893c231b
|
4
|
+
data.tar.gz: 7de7589b70e4a487f50fed9e1a6928c308faa896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc9bab5a99c4db9460d4c3e34fa084adf1f4c3db3b56776be0d0e5c5b5492430f7df0a2c754cafbb63443fe15698647dc15764f8612b052154c627f8284293e
|
7
|
+
data.tar.gz: 0f853e10baafc6ef04c69c2210a5ccad5d4c4f4bfc225a333134a0ce11dd85be36371b5ab8216228b64c43d362c4681efbf3969b815f4d8bcf23a3fbc5ac341f
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Metrics/AbcSize:
|
2
|
+
Max: 17
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 100
|
6
|
+
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Max: 20
|
9
|
+
|
10
|
+
Metrics/ModuleLength:
|
11
|
+
Max: 110
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/PercentLiteralDelimiters:
|
17
|
+
PreferredDelimiters:
|
18
|
+
'%i': '[]'
|
19
|
+
'%w': '[]'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## watirsome [](http://badge.fury.io/rb/watirsome) [](http://travis-ci.org/p0deje/watirsome) [](https://coveralls.io/r/p0deje/watirsome)
|
2
2
|
|
3
3
|
Pure dynamic Watir-based page object DSL.
|
4
4
|
|
@@ -73,7 +73,7 @@ class Page
|
|
73
73
|
end
|
74
74
|
|
75
75
|
page = Page.new(@browser)
|
76
|
-
page.
|
76
|
+
page.body_body # equals to @browser.body
|
77
77
|
page.one_section # equals to @browser.section(id: 'section_one')
|
78
78
|
page.svg_element # equals to @browser.element(tag_name: 'svg')
|
79
79
|
page.login_button # equals to @browser.button(class: 'submit', index: 1)
|
@@ -323,4 +323,4 @@ Regions are being cached, so, once initialized, they won't be executed if you ca
|
|
323
323
|
|
324
324
|
### Copyright
|
325
325
|
|
326
|
-
Copyright (c)
|
326
|
+
Copyright (c) 2016 Alex Rodionov. See LICENSE.md for details.
|
data/Rakefile
CHANGED
@@ -3,10 +3,12 @@ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
|
3
3
|
require 'bundler'
|
4
4
|
Bundler::GemHelper.install_tasks
|
5
5
|
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
6
|
+
require 'yard-doctest'
|
7
|
+
YARD::Doctest::RakeTask.new do |task|
|
8
|
+
task.doctest_opts = %w[-v]
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
require 'rubocop/rake_task'
|
12
|
+
RuboCop::RakeTask.new
|
13
|
+
|
14
|
+
task default: %w[rubocop yard:doctest]
|
data/doctest_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'watirsome'
|
2
|
+
|
3
|
+
def browser
|
4
|
+
@browser ||= begin
|
5
|
+
browser = Watir::Browser.new(:phantomjs)
|
6
|
+
browser.goto "data:text/html,#{File.read('support/doctest.html')}"
|
7
|
+
|
8
|
+
browser
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
YARD::Doctest.configure do |doctest|
|
13
|
+
doctest.after do
|
14
|
+
@browser.quit if @browser
|
15
|
+
end
|
16
|
+
end
|
data/lib/watirsome.rb
CHANGED
@@ -1,24 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# General module which holds all appropriate Watirsome API.
|
3
|
+
# Includers can use accessors and initializers API.
|
4
|
+
#
|
5
|
+
# @example Element Accessors
|
6
|
+
# class Page
|
7
|
+
# include Watirsome
|
8
|
+
#
|
9
|
+
# element :body, tag_name: 'body'
|
10
|
+
# div :container, class: 'container'
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# page = Page.new(browser)
|
14
|
+
# page.body_element #=> browser.element(tag_name: 'body')
|
15
|
+
# page.container_div #=> browser.div(class: 'container')
|
16
|
+
#
|
17
|
+
# @example Read Accessors
|
18
|
+
# class Page
|
19
|
+
# include Watirsome
|
20
|
+
#
|
21
|
+
# div :container, class: 'container'
|
22
|
+
# radio :sex_male, value: "Male"
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# page = Page.new(browser)
|
26
|
+
# page.container #=> "Container"
|
27
|
+
# page.sex_male_radio.set
|
28
|
+
# page.sex_male #=> true
|
29
|
+
#
|
30
|
+
# @example Click Accessors
|
31
|
+
# class Page
|
32
|
+
# include Watirsome
|
33
|
+
#
|
34
|
+
# a :open_google, text: 'Open Google'
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# page = Page.new(browser)
|
38
|
+
# page.open_google
|
39
|
+
# browser.title #=> "Google"
|
40
|
+
#
|
41
|
+
# @example Set Accessors
|
42
|
+
# class Page
|
43
|
+
# include Watirsome
|
44
|
+
#
|
45
|
+
# text_field :name, placeholder: "Enter your name"
|
46
|
+
# select_list :country, name: "Country"
|
47
|
+
# checkbox :agree, name: "I Agree"
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# page = Page.new(browser)
|
51
|
+
# page.name = 'My name'
|
52
|
+
# page.name #=> "My name"
|
53
|
+
# page.country = "Russia"
|
54
|
+
# page.country #=> "Russia"
|
55
|
+
# page.agree = true
|
56
|
+
# page.agree #=> true
|
57
|
+
#
|
1
58
|
module Watirsome
|
2
59
|
class << self
|
3
|
-
|
4
|
-
# @attr [Array<Symbol>] readable
|
5
|
-
attr_accessor :readable
|
6
|
-
|
7
|
-
# @attr [Array<Symbol>] clickable
|
8
|
-
attr_accessor :clickable
|
9
|
-
|
10
|
-
# @attr [Array<Symbol>] settable
|
11
|
-
attr_accessor :settable
|
12
|
-
|
13
|
-
# @attr [Array<Symbol>] selectable
|
14
|
-
attr_accessor :selectable
|
15
|
-
|
16
60
|
#
|
17
61
|
# Returns array of readable elements.
|
18
62
|
# @return [Array<Symbol>]
|
19
63
|
#
|
20
64
|
def readable
|
21
|
-
@readable ||= [
|
65
|
+
@readable ||= %i[div span p h1 h2 h3 h4 h5 h6 select_list text_field textarea checkbox radio]
|
22
66
|
end
|
23
67
|
|
24
68
|
#
|
@@ -26,7 +70,7 @@ module Watirsome
|
|
26
70
|
# @return [Array<Symbol>]
|
27
71
|
#
|
28
72
|
def clickable
|
29
|
-
@clickable ||= [
|
73
|
+
@clickable ||= %i[a link button]
|
30
74
|
end
|
31
75
|
|
32
76
|
#
|
@@ -34,21 +78,17 @@ module Watirsome
|
|
34
78
|
# @return [Array<Symbol>]
|
35
79
|
#
|
36
80
|
def settable
|
37
|
-
@settable ||= [
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Returns array of selectable elements.
|
42
|
-
# @return [Array<Symbol>]
|
43
|
-
#
|
44
|
-
def selectable
|
45
|
-
@selectable ||= [:select_list]
|
81
|
+
@settable ||= %i[text_field file_field textarea checkbox select_list]
|
46
82
|
end
|
47
83
|
|
48
84
|
#
|
49
85
|
# Returns true if tag can have click accessor.
|
50
86
|
#
|
51
|
-
# @
|
87
|
+
# @example
|
88
|
+
# Watirsome.clickable?(:button) #=> true
|
89
|
+
# Watirsome.clickable?(:div) #=> false
|
90
|
+
#
|
91
|
+
# @param [Symbol, String] tag
|
52
92
|
# @return [Boolean]
|
53
93
|
#
|
54
94
|
def clickable?(tag)
|
@@ -58,27 +98,25 @@ module Watirsome
|
|
58
98
|
#
|
59
99
|
# Returns true if tag can have set accessor.
|
60
100
|
#
|
61
|
-
# @
|
101
|
+
# @example
|
102
|
+
# Watirsome.settable?(:text_field) #=> true
|
103
|
+
# Watirsome.settable?(:button) #=> false
|
104
|
+
#
|
105
|
+
# @param [Symbol, String] tag
|
62
106
|
# @return [Boolean]
|
63
107
|
#
|
64
108
|
def settable?(tag)
|
65
109
|
settable.include? tag.to_sym
|
66
110
|
end
|
67
111
|
|
68
|
-
#
|
69
|
-
# Returns true if tag can have select accessor.
|
70
|
-
#
|
71
|
-
# @param [Symbol, String] method
|
72
|
-
# @return [Boolean]
|
73
|
-
#
|
74
|
-
def selectable?(tag)
|
75
|
-
selectable.include? tag.to_sym
|
76
|
-
end
|
77
|
-
|
78
112
|
#
|
79
113
|
# Returns true if tag can have text accessor.
|
80
114
|
#
|
81
|
-
# @
|
115
|
+
# @example
|
116
|
+
# Watirsome.readable?(:div) #=> true
|
117
|
+
# Watirsome.readable?(:body) #=> false
|
118
|
+
#
|
119
|
+
# @param [Symbol, String] tag
|
82
120
|
# @return [Boolean]
|
83
121
|
#
|
84
122
|
def readable?(tag)
|
@@ -101,6 +139,10 @@ module Watirsome
|
|
101
139
|
#
|
102
140
|
# Return true if method can be proxied to Watir, false otherwise.
|
103
141
|
#
|
142
|
+
# @example
|
143
|
+
# Watirsome.watirsome?(:div) #=> true
|
144
|
+
# Watirsome.watirsome?(:to_a) #=> false
|
145
|
+
#
|
104
146
|
# @param [Symbol] method
|
105
147
|
# @return [Boolean]
|
106
148
|
#
|
@@ -112,8 +154,8 @@ module Watirsome
|
|
112
154
|
# Returns true if method is element accessor in plural form.
|
113
155
|
#
|
114
156
|
# @example
|
115
|
-
# Watirsome.plural?
|
116
|
-
# Watirsome.plural?
|
157
|
+
# Watirsome.plural?(:divs) #=> true
|
158
|
+
# Watirsome.plural?(:div) #=> false
|
117
159
|
#
|
118
160
|
# @param [Symbol, String] method
|
119
161
|
# @return [Boolean]
|
@@ -124,15 +166,17 @@ module Watirsome
|
|
124
166
|
plr = str.to_sym
|
125
167
|
sgl = str.sub(/e?s$/, '').to_sym
|
126
168
|
|
127
|
-
/s$/
|
169
|
+
!str.match(/s$/).nil? &&
|
170
|
+
Watirsome.watir_methods.include?(plr) &&
|
171
|
+
Watirsome.watir_methods.include?(sgl)
|
128
172
|
end
|
129
173
|
|
130
174
|
#
|
131
175
|
# Pluralizes element.
|
132
176
|
#
|
133
177
|
# @example
|
134
|
-
# Watirsome.pluralize
|
135
|
-
# Watirsome.pluralize
|
178
|
+
# Watirsome.pluralize(:div) #=> :divs
|
179
|
+
# Watirsome.pluralize(:checkbox) #=> :checkboxes
|
136
180
|
#
|
137
181
|
# @param [Symbol, String] method
|
138
182
|
# @return [Symbol]
|
@@ -151,19 +195,15 @@ module Watirsome
|
|
151
195
|
raise Errors::CannotPluralizeError, "Can't find plural form for #{str}!"
|
152
196
|
end
|
153
197
|
end
|
154
|
-
|
155
198
|
end # self
|
156
199
|
|
157
|
-
|
158
200
|
def self.included(kls)
|
159
|
-
kls.extend
|
160
|
-
kls.
|
161
|
-
kls.
|
201
|
+
kls.extend Watirsome::Accessors::ClassMethods
|
202
|
+
kls.__send__ :include, Watirsome::Accessors::InstanceMethods
|
203
|
+
kls.__send__ :include, Watirsome::Initializers
|
162
204
|
end
|
163
|
-
|
164
205
|
end # Watirsome
|
165
206
|
|
166
|
-
|
167
207
|
require 'watir-webdriver'
|
168
208
|
require 'watirsome/accessors'
|
169
209
|
require 'watirsome/initializers'
|
data/lib/watirsome/accessors.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Watirsome
|
2
2
|
module Accessors
|
3
3
|
module ClassMethods
|
4
|
-
|
5
4
|
#
|
6
|
-
# Iterate
|
5
|
+
# Iterate through Watir continer methods and define all necessary
|
7
6
|
# class methods of element accessors.
|
8
7
|
#
|
9
8
|
Watirsome.watir_methods.each do |method|
|
@@ -11,10 +10,9 @@ module Watirsome
|
|
11
10
|
name, args = parse_args(args)
|
12
11
|
block = proc_from_args(args, &blk)
|
13
12
|
define_element_accessor(name, method, args, &block)
|
14
|
-
define_click_accessor(name, method, args, &block)
|
15
|
-
define_read_accessor(name, method, args, &block)
|
16
|
-
define_set_accessor(name, method, args, &block)
|
17
|
-
define_select_accessor(name, method, args, &block) if Watirsome.selectable?(method)
|
13
|
+
define_click_accessor(name, method, args, &block) if Watirsome.clickable?(method)
|
14
|
+
define_read_accessor(name, method, args, &block) if Watirsome.readable?(method)
|
15
|
+
define_set_accessor(name, method, args, &block) if Watirsome.settable?(method)
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
@@ -25,11 +23,11 @@ module Watirsome
|
|
25
23
|
# @api private
|
26
24
|
#
|
27
25
|
def parse_args(args)
|
28
|
-
|
26
|
+
[args.shift, args.shift]
|
29
27
|
end
|
30
28
|
|
31
29
|
#
|
32
|
-
# Returns block
|
30
|
+
# Returns block retrieved from locators.
|
33
31
|
# @api private
|
34
32
|
#
|
35
33
|
def proc_from_args(*args, &blk)
|
@@ -53,7 +51,7 @@ module Watirsome
|
|
53
51
|
#
|
54
52
|
def define_element_accessor(name, method, *args, &block)
|
55
53
|
watir_args, custom_args = extract_custom_args(method, args)
|
56
|
-
define_method
|
54
|
+
define_method "#{name}_#{method}" do |*opts|
|
57
55
|
if block_given?
|
58
56
|
instance_exec(*opts, &block)
|
59
57
|
else
|
@@ -110,6 +108,8 @@ module Watirsome
|
|
110
108
|
element.value
|
111
109
|
when :select_list
|
112
110
|
element.options.detect(&:selected?).text
|
111
|
+
when :checkbox, :radio
|
112
|
+
element.set?
|
113
113
|
else
|
114
114
|
element.text
|
115
115
|
end
|
@@ -130,13 +130,15 @@ module Watirsome
|
|
130
130
|
#
|
131
131
|
def define_set_accessor(name, method, *args, &block)
|
132
132
|
watir_args, custom_args = extract_custom_args(method, args)
|
133
|
-
define_method
|
133
|
+
define_method "#{name}=" do |*opts|
|
134
134
|
element = if block_given?
|
135
135
|
instance_exec(&block)
|
136
136
|
else
|
137
137
|
grab_elements(method, watir_args, custom_args)
|
138
138
|
end
|
139
|
-
if element.
|
139
|
+
if element.is_a?(Watir::Select)
|
140
|
+
element.select(*opts)
|
141
|
+
elsif element.respond_to?(:set)
|
140
142
|
element.set(*opts)
|
141
143
|
else
|
142
144
|
element.send_keys(*opts)
|
@@ -144,29 +146,6 @@ module Watirsome
|
|
144
146
|
end
|
145
147
|
end
|
146
148
|
|
147
|
-
#
|
148
|
-
# Defines accessor which selects option Watir element instance.
|
149
|
-
# Method name is element name + "=".
|
150
|
-
#
|
151
|
-
# Note that custom block arguments are not used here.
|
152
|
-
#
|
153
|
-
# @param [Symbol] name Element name
|
154
|
-
# @param [Symbol] method Watir method
|
155
|
-
# @param [Array] args Splat of locators
|
156
|
-
# @param [Proc] block Block as element retriever
|
157
|
-
# @api private
|
158
|
-
#
|
159
|
-
def define_select_accessor(name, method, *args, &block)
|
160
|
-
watir_args, custom_args = extract_custom_args(method, args)
|
161
|
-
define_method :"#{name}=" do |*opts|
|
162
|
-
if block_given?
|
163
|
-
instance_exec(&block).select(*opts)
|
164
|
-
else
|
165
|
-
grab_elements(method, watir_args, custom_args).select(*opts)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
149
|
#
|
171
150
|
# Extracts custom arguments which Watirsome gracefully handles from
|
172
151
|
# mixed array with Watir locators.
|
@@ -178,9 +157,11 @@ module Watirsome
|
|
178
157
|
#
|
179
158
|
def extract_custom_args(method, *args)
|
180
159
|
identifier = args.shift
|
181
|
-
watir_args
|
160
|
+
watir_args = []
|
161
|
+
custom_args = []
|
182
162
|
identifier.each_with_index do |hashes, index|
|
183
|
-
watir_arg
|
163
|
+
watir_arg = {}
|
164
|
+
custom_arg = {}
|
184
165
|
if hashes && !hashes.is_a?(Proc)
|
185
166
|
hashes.each do |k, v|
|
186
167
|
if Watir.element_class_for(method).instance_methods.include? :"#{k}?"
|
@@ -194,14 +175,11 @@ module Watirsome
|
|
194
175
|
custom_args << custom_arg unless custom_arg.empty?
|
195
176
|
end
|
196
177
|
|
197
|
-
|
178
|
+
[watir_args, custom_args]
|
198
179
|
end
|
199
|
-
|
200
180
|
end # ClassMethods
|
201
181
|
|
202
|
-
|
203
182
|
module InstanceMethods
|
204
|
-
|
205
183
|
private
|
206
184
|
|
207
185
|
#
|
@@ -214,24 +192,23 @@ module Watirsome
|
|
214
192
|
#
|
215
193
|
def grab_elements(method, watir_args, custom_args)
|
216
194
|
if custom_args.empty?
|
217
|
-
@browser.
|
195
|
+
@browser.__send__(method, *watir_args)
|
218
196
|
else
|
219
197
|
plural = Watirsome.plural?(method)
|
220
198
|
method = Watirsome.pluralize(method) unless plural
|
221
|
-
elements = @browser.
|
199
|
+
elements = @browser.__send__(method, *watir_args)
|
222
200
|
custom_args.first.each do |k, v|
|
223
201
|
elements.to_a.select! do |e|
|
224
202
|
if e.public_method(:"#{k}?").arity == 0
|
225
|
-
e.
|
203
|
+
e.__send__(:"#{k}?") == v
|
226
204
|
else
|
227
|
-
e.
|
205
|
+
e.__send__(:"#{k}?", v)
|
228
206
|
end
|
229
207
|
end
|
230
208
|
end
|
231
209
|
plural ? elements : elements.first
|
232
210
|
end
|
233
211
|
end
|
234
|
-
|
235
212
|
end # InstanceMethods
|
236
213
|
end # Accessors
|
237
214
|
end # Watirsome
|