site_prism 3.0.3 → 3.1
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/README.md +24 -17
- data/lib/site_prism.rb +41 -4
- data/lib/site_prism/dsl.rb +33 -35
- data/lib/site_prism/loadable.rb +4 -3
- data/lib/site_prism/logger.rb +4 -18
- data/lib/site_prism/section.rb +6 -3
- data/lib/site_prism/version.rb +1 -1
- metadata +7 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ccf39fa12f16a3de0a020f5cc51bd0e8809424392120c490b5735c7bddf8eb8
|
4
|
+
data.tar.gz: bd6daa8edb638af906e6582388aca9fb2185af9b71ac1bd27cddf8a7b0f1a78c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c84412248c810e5539053376619abe431912f33cdc903ed8455444d2b866b6287cdec771f8045d365660c28a5f9eaac4222059172b0f4b8e42424ab0c9f884a
|
7
|
+
data.tar.gz: a385856b1c97a688d42a58e6ef36c4ca7e9f71a004065e505b58e0797f47c54b7ecb41a8721353b6f9625274f266768ba1492265665f4ecbd12230eff09ceae7
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# SitePrism
|
2
|
+
[](https://badge.fury.io/rb/site_prism)
|
3
|
+
[](https://travis-ci.org/natritmeyer/site_prism)
|
4
|
+
|
2
5
|
_A Page Object Model DSL for Capybara_
|
3
6
|
|
4
|
-
SitePrism gives you a simple, clean and semantic DSL for describing your site using the Page Object Model pattern,
|
7
|
+
SitePrism gives you a simple, clean and semantic DSL for describing your site using the Page Object Model pattern,
|
8
|
+
for use with Capybara in automated acceptance testing.
|
5
9
|
|
6
10
|
Find the pretty documentation here: http://rdoc.info/gems/site_prism/frames
|
7
11
|
|
8
|
-
[](https://travis-ci.org/natritmeyer/site_prism)
|
9
|
-
|
10
12
|
Make sure to add your project/company to https://github.com/natritmeyer/site_prism/wiki/Who-is-using-SitePrism
|
11
13
|
|
12
14
|
## Developing / Contributing to SitePrism
|
@@ -17,11 +19,14 @@ We have a brief set of setup docs [HERE](https://github.com/natritmeyer/site_pri
|
|
17
19
|
|
18
20
|
## Supported Rubies / Browsers
|
19
21
|
|
20
|
-
SitePrism is built and tested to work on Ruby 2.
|
22
|
+
SitePrism is built and tested to work on Ruby 2.4 - 2.6. Ruby 2.3 (Now EOL), is supported but not tested against.
|
23
|
+
If you are using SitePrism with Ruby 2.3 it is highly advisable to upgrade to a more modern Ruby
|
24
|
+
such as 2.5 or 2.6, if for any other reason, to get a noticeable speed boost!
|
21
25
|
|
22
26
|
SitePrism should run on all major browsers. The gem's integration tests are ran on Chrome and Firefox.
|
23
27
|
|
24
|
-
If you find
|
28
|
+
If you find you cannot integrate nicely with SitePrism, please open an
|
29
|
+
[issue request](https://github.com/natritmeyer/site_prism/issues/new)
|
25
30
|
|
26
31
|
## Synopsis
|
27
32
|
|
@@ -419,7 +424,7 @@ end
|
|
419
424
|
@home.load
|
420
425
|
|
421
426
|
@home.search_field #=> will return the capybara element found using the selector
|
422
|
-
@home.search_field.set 'the search string' #=>
|
427
|
+
@home.search_field.set 'the search string' #=> `search_field` returns a capybara element, so use the capybara API to deal with it
|
423
428
|
@home.search_field.text #=> standard method on a capybara element; returns a string
|
424
429
|
```
|
425
430
|
|
@@ -609,7 +614,7 @@ end
|
|
609
614
|
Then the following method is available:
|
610
615
|
|
611
616
|
```ruby
|
612
|
-
@friends_page.has_names? #=> returns true if at least one element is found
|
617
|
+
@friends_page.has_names? #=> returns true if at least one `name` element is found
|
613
618
|
```
|
614
619
|
|
615
620
|
This in turn allows the following nice test code
|
@@ -732,7 +737,8 @@ The way to add a section to a page (or another section - which is possible) is t
|
|
732
737
|
call the `section` method. It takes 3 arguments: the first is the name of the section as
|
733
738
|
referred to on the page (sections that appear on multiple pages can be named differently).
|
734
739
|
The second argument is the class of which an instance will be created to represent
|
735
|
-
the page section, and the following arguments are
|
740
|
+
the page section, and the following arguments are
|
741
|
+
[Capybara::Node::Finders](https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders).
|
736
742
|
These identify the root node of the section on this page (note that the css selector
|
737
743
|
can be different for different pages as the whole point of sections is that they can
|
738
744
|
appear in different places / ways on different pages).
|
@@ -754,9 +760,9 @@ class HomePage < SitePrism::Page
|
|
754
760
|
end
|
755
761
|
```
|
756
762
|
|
757
|
-
The 3rd argument (Locators), can be omitted if you are re-using the same
|
758
|
-
references to the section Class. In order to do this,
|
759
|
-
you want to use
|
763
|
+
The 3rd argument (Locators), can be omitted if you are re-using the same
|
764
|
+
locator for all references to the section Class. In order to do this,
|
765
|
+
simply tell SitePrism that you want to use default search arguments.
|
760
766
|
|
761
767
|
```ruby
|
762
768
|
class People < SitePrism::Section
|
@@ -1321,7 +1327,7 @@ class SomePage < SitePrism::Page
|
|
1321
1327
|
end
|
1322
1328
|
```
|
1323
1329
|
|
1324
|
-
The block may be defined as a two-element array which includes the boolean check
|
1330
|
+
The block *may* be defined as a two-element array which includes the boolean check
|
1325
1331
|
as the first element and an error message as the second element.
|
1326
1332
|
It is highly recommended to supply an error message, as they are
|
1327
1333
|
extremely useful in debugging validation errors.
|
@@ -1579,9 +1585,9 @@ end
|
|
1579
1585
|
|
1580
1586
|
SitePrism can be configured to change its behaviour.
|
1581
1587
|
|
1582
|
-
For each of the following configuration options, either add it in the
|
1583
|
-
if you are running SitePrism as a Unit Test framework,
|
1584
|
-
a Cucumber based framework
|
1588
|
+
For each of the following configuration options, either add it in the
|
1589
|
+
`spec_helper.rb` file if you are running SitePrism as a Unit Test framework,
|
1590
|
+
or in your `env.rb` if you are running a Cucumber based framework.
|
1585
1591
|
|
1586
1592
|
### Using Capybara Implicit Waits
|
1587
1593
|
|
@@ -1695,7 +1701,8 @@ end
|
|
1695
1701
|
The only thing that needs instantiating is the `App` class - from then on
|
1696
1702
|
pages don't need to be initialized, they are now returned by methods on `@app`.
|
1697
1703
|
|
1698
|
-
It is possible to further optimise this, by using Cucumber/RSpec hooks,
|
1699
|
-
the investigation and optimisation of this
|
1704
|
+
It is possible to further optimise this, by using Cucumber/RSpec hooks, amongst
|
1705
|
+
other things. However the investigation and optimisation of this (and other
|
1706
|
+
aspects of SitePrism), is left as an exercise to the Reader.
|
1700
1707
|
|
1701
1708
|
Happy testing from all of the SitePrism team!
|
data/lib/site_prism.rb
CHANGED
@@ -13,18 +13,55 @@ module SitePrism
|
|
13
13
|
autoload :Waiter, 'site_prism/waiter'
|
14
14
|
|
15
15
|
class << self
|
16
|
-
attr_writer :enable_logging
|
17
|
-
|
18
16
|
def configure
|
19
17
|
yield self
|
20
18
|
end
|
21
19
|
|
20
|
+
# The SitePrism logger object - This is called automatically in several
|
21
|
+
# locations and will log messages according to the normal Ruby protocol
|
22
|
+
# To alter (or check), the log level; call .log_level= or .log_level
|
23
|
+
#
|
24
|
+
# This logger object can also be used to manually log messages
|
25
|
+
#
|
26
|
+
# To Manually log a message
|
27
|
+
# SitePrism.logger.info('Information')
|
28
|
+
# SitePrism.logger.debug('Input debug message')
|
29
|
+
#
|
30
|
+
# By default the logger will output all messages to $stdout, but can be
|
31
|
+
# altered to log to a file or another IO location by calling `.log_path=`
|
22
32
|
def logger
|
23
33
|
@logger ||= SitePrism::Logger.new.create
|
24
34
|
end
|
25
35
|
|
26
|
-
|
27
|
-
|
36
|
+
# `Logger#reopen` was added in Ruby 2.3 - Which is now the minimum version
|
37
|
+
# for the site_prism gem
|
38
|
+
#
|
39
|
+
# This writer method allows you to configure where you want the output of
|
40
|
+
# the site_prism logs to go (Default is $stdout)
|
41
|
+
#
|
42
|
+
# example: SitePrism.log_path = 'site_prism.log' would save all
|
43
|
+
# log messages to `./site_prism.log`
|
44
|
+
def log_path=(logdev)
|
45
|
+
logger.reopen(logdev)
|
46
|
+
end
|
47
|
+
|
48
|
+
# To enable full logging (This uses the Ruby API, so can accept any of a
|
49
|
+
# Symbol / String / Integer as an input
|
50
|
+
# SitePrism.log_level = :DEBUG
|
51
|
+
# SitePrism.log_level = 'DEBUG'
|
52
|
+
# SitePrism.log_level = 0
|
53
|
+
#
|
54
|
+
# To disable all logging (Done by default)
|
55
|
+
# SitePrism.log_level = :UNKNOWN
|
56
|
+
def log_level=(value)
|
57
|
+
logger.level = value
|
58
|
+
end
|
59
|
+
|
60
|
+
# To query what level is being logged
|
61
|
+
# SitePrism.log_level
|
62
|
+
# => :UNKNOWN # By default
|
63
|
+
def log_level
|
64
|
+
%i[DEBUG INFO WARN ERROR FATAL UNKNOWN][logger.level]
|
28
65
|
end
|
29
66
|
end
|
30
67
|
end
|
data/lib/site_prism/dsl.rb
CHANGED
@@ -66,14 +66,12 @@ module SitePrism
|
|
66
66
|
options[:wait] = wait_time unless wait_key_present?(options)
|
67
67
|
end
|
68
68
|
|
69
|
-
#
|
70
|
-
#
|
69
|
+
# Detect if the +wait+ key is present in the options hash.
|
71
70
|
# Note that setting it to to false or 0, still will return true here.
|
72
71
|
def wait_key_present?(options)
|
73
72
|
options.key?(:wait)
|
74
73
|
end
|
75
74
|
|
76
|
-
# rubocop:disable Metrics/ModuleLength
|
77
75
|
module ClassMethods
|
78
76
|
attr_reader :expected_items
|
79
77
|
|
@@ -124,13 +122,14 @@ module SitePrism
|
|
124
122
|
def iframe(name, klass, *args)
|
125
123
|
element_find_args = deduce_iframe_element_find_args(args)
|
126
124
|
scope_find_args = deduce_iframe_scope_find_args(args)
|
127
|
-
map_item!(:iframe, name)
|
128
|
-
add_iframe_helper_methods(name, *element_find_args)
|
129
|
-
define_method(name) do |&block|
|
130
|
-
raise MissingBlockError unless block
|
131
125
|
|
132
|
-
|
133
|
-
|
126
|
+
build(:iframe, name, *element_find_args) do
|
127
|
+
define_method(name) do |&block|
|
128
|
+
raise MissingBlockError unless block
|
129
|
+
|
130
|
+
within_frame(*scope_find_args) do
|
131
|
+
block.call(klass.new)
|
132
|
+
end
|
134
133
|
end
|
135
134
|
end
|
136
135
|
end
|
@@ -145,14 +144,14 @@ module SitePrism
|
|
145
144
|
if find_args.empty?
|
146
145
|
create_error_method(name)
|
147
146
|
else
|
148
|
-
map_item
|
147
|
+
map_item(type, name)
|
149
148
|
yield
|
150
149
|
end
|
151
150
|
add_helper_methods(name, *find_args)
|
152
151
|
end
|
153
152
|
|
154
|
-
def map_item
|
155
|
-
mapped_items << { type => name }
|
153
|
+
def map_item(type, name)
|
154
|
+
mapped_items << { type => name.to_sym }
|
156
155
|
end
|
157
156
|
|
158
157
|
def add_helper_methods(name, *find_args)
|
@@ -162,11 +161,6 @@ module SitePrism
|
|
162
161
|
create_invisibility_waiter(name, *find_args)
|
163
162
|
end
|
164
163
|
|
165
|
-
def add_iframe_helper_methods(name, *find_args)
|
166
|
-
create_existence_checker(name, *find_args)
|
167
|
-
create_nonexistence_checker(name, *find_args)
|
168
|
-
end
|
169
|
-
|
170
164
|
def create_helper_method(proposed_method_name, *find_args)
|
171
165
|
if find_args.empty?
|
172
166
|
create_error_method(proposed_method_name)
|
@@ -228,27 +222,35 @@ module SitePrism
|
|
228
222
|
end
|
229
223
|
|
230
224
|
def deduce_iframe_scope_find_args(args)
|
225
|
+
warn_on_invalid_selector_input(args)
|
231
226
|
case args[0]
|
232
|
-
when Integer
|
233
|
-
|
234
|
-
|
235
|
-
[:css, args[0]]
|
236
|
-
else
|
237
|
-
args
|
227
|
+
when Integer then [args[0]]
|
228
|
+
when String then [:css, args[0]]
|
229
|
+
else args
|
238
230
|
end
|
239
231
|
end
|
240
232
|
|
241
233
|
def deduce_iframe_element_find_args(args)
|
234
|
+
warn_on_invalid_selector_input(args)
|
242
235
|
case args[0]
|
243
|
-
when Integer
|
244
|
-
|
245
|
-
|
246
|
-
[:css, args[0]]
|
247
|
-
else
|
248
|
-
args
|
236
|
+
when Integer then "iframe:nth-of-type(#{args[0] + 1})"
|
237
|
+
when String then [:css, args[0]]
|
238
|
+
else args
|
249
239
|
end
|
250
240
|
end
|
251
241
|
|
242
|
+
def warn_on_invalid_selector_input(args)
|
243
|
+
return unless looks_like_xpath?(args[0])
|
244
|
+
|
245
|
+
msg = 'The arguments passed in look like xpath. Check your locators.'
|
246
|
+
SitePrism.logger.warn(msg)
|
247
|
+
SitePrism.logger.debug("Default locator: #{Capybara.default_selector}")
|
248
|
+
end
|
249
|
+
|
250
|
+
def looks_like_xpath?(arg)
|
251
|
+
arg.is_a?(String) && arg.start_with?('/', './')
|
252
|
+
end
|
253
|
+
|
252
254
|
def extract_section_options(args, &block)
|
253
255
|
if args.first.is_a?(Class)
|
254
256
|
klass = args.shift
|
@@ -262,14 +264,11 @@ module SitePrism
|
|
262
264
|
|
263
265
|
def deduce_section_class(base_class, &block)
|
264
266
|
klass = base_class
|
265
|
-
|
266
267
|
klass = Class.new(klass || SitePrism::Section, &block) if block_given?
|
268
|
+
return klass if klass
|
267
269
|
|
268
|
-
|
269
|
-
raise ArgumentError, "You should provide descendant of \
|
270
|
+
raise ArgumentError, "You should provide descendant of \
|
270
271
|
SitePrism::Section class or/and a block as the second argument."
|
271
|
-
end
|
272
|
-
klass
|
273
272
|
end
|
274
273
|
|
275
274
|
def deduce_search_arguments(section_class, args)
|
@@ -283,6 +282,5 @@ in section creation or set_default_search_arguments within section class")
|
|
283
282
|
args if args && !args.empty?
|
284
283
|
end
|
285
284
|
end
|
286
|
-
# rubocop:enable Metrics/ModuleLength
|
287
285
|
end
|
288
286
|
end
|
data/lib/site_prism/loadable.rb
CHANGED
@@ -26,9 +26,10 @@ module SitePrism
|
|
26
26
|
# @param block [&block] A block which returns true if the page
|
27
27
|
# loaded successfully, or false if it did not.
|
28
28
|
# This block can contain up to 2 elements in an array
|
29
|
-
# The first is the physical validation test to be truthily evaluated
|
30
|
-
#
|
31
|
-
#
|
29
|
+
# The first is the physical validation test to be truthily evaluated.
|
30
|
+
#
|
31
|
+
# If this does not pass, then the 2nd item (if defined), is output
|
32
|
+
# as an error message to the +FailedLoadValidationError+ that is thrown
|
32
33
|
def load_validation(&block)
|
33
34
|
_load_validations << block
|
34
35
|
end
|
data/lib/site_prism/logger.rb
CHANGED
@@ -1,35 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
5
|
module SitePrism
|
4
|
-
# To enable full logging
|
5
|
-
# SitePrism.enable_logging = true
|
6
6
|
#
|
7
|
-
#
|
8
|
-
# SitePrism.enable_logging = false
|
7
|
+
# @api private
|
9
8
|
#
|
10
|
-
# To Manually log a message
|
11
|
-
# SitePrism.logger.info('Information')
|
12
|
-
# SitePrism.logger.debug('Input debug message')
|
13
9
|
class Logger
|
14
10
|
def create(output = $stdout)
|
15
11
|
logger = ::Logger.new(output)
|
16
12
|
logger.progname = 'SitePrism'
|
17
|
-
logger.level =
|
13
|
+
logger.level = :UNKNOWN
|
18
14
|
logger.formatter = proc do |severity, time, progname, msg|
|
19
15
|
"#{time.strftime('%F %T')} - #{severity} - #{progname} - #{msg}\n"
|
20
16
|
end
|
21
17
|
|
22
18
|
logger
|
23
19
|
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def log_level
|
28
|
-
if SitePrism.enable_logging
|
29
|
-
0 # This is equivalent to debug standard logging
|
30
|
-
else
|
31
|
-
5 # This is equivalent to unknown (or no), logging
|
32
|
-
end
|
33
|
-
end
|
34
20
|
end
|
35
21
|
end
|
data/lib/site_prism/section.rb
CHANGED
@@ -36,7 +36,10 @@ module SitePrism
|
|
36
36
|
# occurs and calls within a section (For example section.find(element))
|
37
37
|
# correctly scope to look within the section only
|
38
38
|
def page
|
39
|
-
root_element
|
39
|
+
return root_element if root_element
|
40
|
+
|
41
|
+
SitePrism.logger.warn('Root Element not found; Falling back to `super`')
|
42
|
+
super
|
40
43
|
end
|
41
44
|
|
42
45
|
def visible?
|
@@ -73,11 +76,11 @@ module SitePrism
|
|
73
76
|
end
|
74
77
|
|
75
78
|
def element_exists?(*find_args)
|
76
|
-
page
|
79
|
+
page.has_selector?(*find_args)
|
77
80
|
end
|
78
81
|
|
79
82
|
def element_does_not_exist?(*find_args)
|
80
|
-
page
|
83
|
+
page.has_no_selector?(*find_args)
|
81
84
|
end
|
82
85
|
end
|
83
86
|
end
|
data/lib/site_prism/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_prism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: '3.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nat Ritmeyer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -29,22 +29,16 @@ dependencies:
|
|
29
29
|
name: capybara
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '2.18'
|
35
|
-
- - "<"
|
32
|
+
- - "~>"
|
36
33
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
34
|
+
version: '3.2'
|
38
35
|
type: :runtime
|
39
36
|
prerelease: false
|
40
37
|
version_requirements: !ruby/object:Gem::Requirement
|
41
38
|
requirements:
|
42
|
-
- - "
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '2.18'
|
45
|
-
- - "<"
|
39
|
+
- - "~>"
|
46
40
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
41
|
+
version: '3.2'
|
48
42
|
- !ruby/object:Gem::Dependency
|
49
43
|
name: cucumber
|
50
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
175
|
requirements:
|
182
176
|
- - ">="
|
183
177
|
- !ruby/object:Gem::Version
|
184
|
-
version: '2.
|
178
|
+
version: '2.3'
|
185
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
180
|
requirements:
|
187
181
|
- - ">="
|