site_prism 5.0.beta → 5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -54
- data/lib/site_prism/deprecator.rb +2 -21
- data/lib/site_prism/dsl/builder.rb +22 -35
- data/lib/site_prism/dsl/locators.rb +19 -2
- data/lib/site_prism/dsl/validator.rb +9 -7
- data/lib/site_prism/element_checker.rb +2 -2
- data/lib/site_prism/error.rb +3 -0
- data/lib/site_prism/loadable.rb +13 -23
- data/lib/site_prism/logger.rb +1 -1
- data/lib/site_prism/page.rb +2 -1
- data/lib/site_prism/version.rb +1 -1
- data/lib/site_prism.rb +5 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3036f6b2266855a0a4d08a3c72b44b08d1ce6f423ca72e5dbe5b539cb90b1216
|
4
|
+
data.tar.gz: 1314d67df7aeb3c9d70478e5b884aec2cfb7b4216c58cf9841d4d6dc8b7bc9f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 057576ee2b44eb40824344eeef80243e4fbbe8b30df7ab8e6b011053f652b0257065472103b16ed6a4ce094ed3ad608cf8c72dcb8e11c0e3e4f3daa2aaa9ef38
|
7
|
+
data.tar.gz: c9ef4c0ac315e0664f0089cd13a75e8566e7be3f553e85a7f2d17ef1bce7943762074b478767790bb44497968fc6ee0919440a1e613ed6a27f0efde585e19f24
|
data/README.md
CHANGED
@@ -29,8 +29,8 @@ We have a brief set of setup docs [HERE](https://github.com/site-prism/site_pris
|
|
29
29
|
|
30
30
|
## Supported Rubies / Browsers
|
31
31
|
|
32
|
-
SitePrism is built and tested to work on Ruby 2.
|
33
|
-
If you are using SitePrism with Ruby 2.
|
32
|
+
SitePrism is built and tested to work on Ruby 2.7 - 3.2.
|
33
|
+
If you are using SitePrism with Ruby 2.7 it is highly advisable to upgrade to a more modern
|
34
34
|
Ruby (v3+), if for any other reason, to get a performance improvement!
|
35
35
|
|
36
36
|
SitePrism should run on all major browsers. The gem's integration tests are run on Chrome and Firefox.
|
@@ -66,7 +66,7 @@ class SearchResults < SitePrism::Page
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
#
|
69
|
+
# Define sections that are used on multiple pages or multiple times on one page
|
70
70
|
|
71
71
|
class Menu < SitePrism::Section
|
72
72
|
element :search, 'a.search'
|
@@ -79,7 +79,7 @@ class SearchResults < SitePrism::Section
|
|
79
79
|
element :blurb, 'span.result-description'
|
80
80
|
end
|
81
81
|
|
82
|
-
#
|
82
|
+
# Then we can write some tests
|
83
83
|
|
84
84
|
When('I navigate to the google home page') do
|
85
85
|
@home = Home.new
|
@@ -88,6 +88,7 @@ end
|
|
88
88
|
|
89
89
|
Then('the home page should contain the menu and the search form') do
|
90
90
|
@home.wait_until_menu_visible(wait: 5)
|
91
|
+
|
91
92
|
expect(@home).to have_menu
|
92
93
|
expect(@home).to have_search_field
|
93
94
|
expect(@home).to have_search_button
|
@@ -100,11 +101,13 @@ end
|
|
100
101
|
|
101
102
|
Then('the search results page is displayed') do
|
102
103
|
@results_page = SearchResults.new
|
104
|
+
|
103
105
|
expect(@results_page).to be_displayed
|
104
106
|
end
|
105
107
|
|
106
108
|
Then('the search results page contains 10 individual search results') do
|
107
109
|
@results_page.wait_until_search_results_visible(wait: 5)
|
110
|
+
|
108
111
|
expect(@results_page).to have_search_results(count: 10)
|
109
112
|
end
|
110
113
|
|
@@ -113,8 +116,6 @@ Then('the search results contain a link to the wikipedia sausages page') do
|
|
113
116
|
end
|
114
117
|
```
|
115
118
|
|
116
|
-
Now for the details...
|
117
|
-
|
118
119
|
## Setup
|
119
120
|
|
120
121
|
### Installation
|
@@ -166,19 +167,15 @@ And again, as above, a sample driver is no different to a normal driver instanti
|
|
166
167
|
|
167
168
|
## Introduction to the Page Object Model
|
168
169
|
|
169
|
-
The Page Object Model is a test automation pattern that aims to create
|
170
|
-
|
171
|
-
|
172
|
-
to then use instances of those classes in your tests.
|
170
|
+
The Page Object Model is a test automation pattern that aims to create an abstraction of your sites user
|
171
|
+
interface that can be used in tests. The most common way to do this is to model each page as a class and
|
172
|
+
then to use instances of those classes in your tests.
|
173
173
|
|
174
|
-
If a class represents a page then each element of the page is
|
175
|
-
|
176
|
-
element that can then be acted upon (clicked, type in some text), or
|
177
|
-
queried (is it enabled? / visible?).
|
174
|
+
If a class represents a page then each element of the page is represented by a method that, when called, returns a
|
175
|
+
reference to that element that can then be acted upon (clicked, type in some text), or queried (is it enabled? / visible?).
|
178
176
|
|
179
|
-
SitePrism is based around this concept, but goes further as you'll see
|
180
|
-
|
181
|
-
multiple pages, or many times on a page using the concept of sections.
|
177
|
+
SitePrism is based around this concept, but goes further as you'll see below by also allowing modelling of
|
178
|
+
repeated sections that appear on multiple pages, or many times on a page using the concept of sections.
|
182
179
|
|
183
180
|
## Pages
|
184
181
|
|
@@ -216,9 +213,8 @@ class Home < SitePrism::Page
|
|
216
213
|
end
|
217
214
|
```
|
218
215
|
|
219
|
-
Note that setting a URL is **optional** - you only need to set a url if you want to be able to
|
220
|
-
|
221
|
-
home page or a login page, but probably not a search results page.
|
216
|
+
Note that setting a URL is **optional** - you only need to set a url if you want to be able to navigate directly to that page.
|
217
|
+
It makes sense to set the URL for a page model of a home page or a login page, but probably not a search results page.
|
222
218
|
|
223
219
|
#### Parametrized URLs
|
224
220
|
|
@@ -281,10 +277,9 @@ navigate to the URL set against that page's class.
|
|
281
277
|
|
282
278
|
### Verifying that a particular page is displayed
|
283
279
|
|
284
|
-
Automated tests often need to verify that a particular page is
|
285
|
-
|
286
|
-
|
287
|
-
currently viewed page. For example, with the following URL template:
|
280
|
+
Automated tests often need to verify that a particular page is displayed. SitePrism can automatically parse
|
281
|
+
your templated URL and verify that whatever components your template specifies match the currently viewed page.
|
282
|
+
For example, with the following URL template:
|
288
283
|
|
289
284
|
```ruby
|
290
285
|
class Account < SitePrism::Page
|
@@ -302,10 +297,9 @@ expect(@account_page.current_url).to end_with('/accounts/22?token=ca2786616a4285
|
|
302
297
|
expect(@account_page).to be_displayed
|
303
298
|
```
|
304
299
|
|
305
|
-
Calling `#displayed?` will return true if the browser's current URL
|
306
|
-
|
307
|
-
|
308
|
-
wait time in seconds as the first argument like this:
|
300
|
+
Calling `#displayed?` will return true if the browser's current URL matches the page's template and false if
|
301
|
+
it doesn't. It will wait for `Capybara.default_max_wait_time` seconds or you can pass an explicit wait time in
|
302
|
+
seconds as the first argument like this:
|
309
303
|
|
310
304
|
```ruby
|
311
305
|
@account_page.displayed?(10) # wait up to 10 seconds for display
|
@@ -346,9 +340,8 @@ expect(@account_page.url_matches.dig('query', 'token')).to eq('ca2786616a4285bc'
|
|
346
340
|
|
347
341
|
#### Falling back to basic regexp matchers
|
348
342
|
|
349
|
-
If SitePrism's built-in URL matching is not sufficient for your needs
|
350
|
-
|
351
|
-
URL matchers by it by calling `set_url_matcher`:
|
343
|
+
If SitePrism's built-in URL matching is not sufficient for your needs you can override and use SitePrism's
|
344
|
+
support for regular expression-based URL matchers by it by calling `set_url_matcher`:
|
352
345
|
|
353
346
|
```ruby
|
354
347
|
class Account < SitePrism::Page
|
@@ -377,6 +370,7 @@ end
|
|
377
370
|
|
378
371
|
@account = Account.new
|
379
372
|
@account.current_url #=> "http://www.example.com/account/123"
|
373
|
+
|
380
374
|
expect(@account.current_url).to include('example.com/account/')
|
381
375
|
```
|
382
376
|
|
@@ -394,10 +388,9 @@ end
|
|
394
388
|
|
395
389
|
### HTTP vs. HTTPS
|
396
390
|
|
397
|
-
You can easily tell if the page is secure or not by checking to see if
|
398
|
-
the current
|
399
|
-
|
400
|
-
'https' and false if it doesn't. For example:
|
391
|
+
You can easily tell if the page is secure or not by checking to see if the current URL begins with 'https' or not.
|
392
|
+
SitePrism provides the `#secure?` method that will return true if the current url begins with 'https' and false if it doesn't.
|
393
|
+
For example:
|
401
394
|
|
402
395
|
```ruby
|
403
396
|
class Account < SitePrism::Page
|
@@ -405,16 +398,15 @@ end
|
|
405
398
|
|
406
399
|
@account = Account.new
|
407
400
|
@account.secure? #=> true/false
|
401
|
+
|
408
402
|
expect(@account).to be_secure
|
409
403
|
```
|
410
404
|
|
411
405
|
## Elements
|
412
406
|
|
413
|
-
Pages are made up of elements (text fields, buttons, combo boxes, etc),
|
414
|
-
|
415
|
-
|
416
|
-
element collections would be items in any sort of list, eg: menu items,
|
417
|
-
images in a carousel, etc.
|
407
|
+
Pages are made up of elements (text fields, buttons, combo boxes, etc), either individual elements or groups of
|
408
|
+
them. Examples of individual elements would be a search field or a company logo image; examples of element collections would
|
409
|
+
be items in any sort of list, eg: menu items,images in a carousel, etc.
|
418
410
|
|
419
411
|
### Individual Elements
|
420
412
|
|
@@ -508,18 +500,16 @@ Using the above example:
|
|
508
500
|
|
509
501
|
```ruby
|
510
502
|
Then('the search field exists')do
|
511
|
-
expect(@home).to have_no_search_field #NB: NOT => expect(@home).not_to have_search_field
|
503
|
+
expect(@home).to have_no_search_field #NB: NOT THE SAME AS => expect(@home).not_to have_search_field
|
512
504
|
end
|
513
505
|
```
|
514
506
|
|
515
507
|
#### Waiting for an element to become visible
|
516
508
|
|
517
|
-
A method that gets added by calling `element` is the
|
518
|
-
`wait_until_<element_name>_visible` method.
|
509
|
+
A method that gets added by calling `element` is the `wait_until_<element_name>_visible` method.
|
519
510
|
This method delegates to [Capybara::Node::Matchers#has_selector?](https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Matchers#has_selector%3F-instance_method).
|
520
|
-
Calling this method will cause the test to wait for Capybara's default wait time for the element
|
521
|
-
|
522
|
-
of seconds to wait in-line or configuring the default wait time.
|
511
|
+
Calling this method will cause the test to wait for Capybara's default wait time for the element to become visible. You can customise
|
512
|
+
the wait time by supplying a number of seconds to wait in-line or configuring the default wait time.
|
523
513
|
|
524
514
|
```ruby
|
525
515
|
@home.wait_until_search_field_visible # using the default wait time set
|
@@ -529,12 +519,10 @@ of seconds to wait in-line or configuring the default wait time.
|
|
529
519
|
|
530
520
|
#### Waiting for an element to become invisible
|
531
521
|
|
532
|
-
Another method added by calling `element` is the
|
533
|
-
`wait_until_<element_name>_invisible` method.
|
522
|
+
Another method added by calling `element` is the `wait_until_<element_name>_invisible` method.
|
534
523
|
This method delegates to [Capybara::Node::Matchers#has_no_selector?](https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Matchers#has_no_selector%3F-instance_method).
|
535
|
-
Calling this method will cause the test to wait for Capybara's default
|
536
|
-
|
537
|
-
waiter, customise the wait time in the same way.
|
524
|
+
Calling this method will cause the test to wait for Capybara's default wait time for the element to become invisible.
|
525
|
+
You can (as with the visibility waiter), customise the wait time in the same way.
|
538
526
|
|
539
527
|
```ruby
|
540
528
|
@home.wait_until_search_field_invisible # using the default wait time set
|
@@ -544,9 +532,8 @@ waiter, customise the wait time in the same way.
|
|
544
532
|
|
545
533
|
#### CSS Selectors vs. XPath Expressions
|
546
534
|
|
547
|
-
While the above examples all use CSS selectors to find elements, it is
|
548
|
-
|
549
|
-
can use a CSS selector, you can use an XPath expression.
|
535
|
+
While the above examples all use CSS selectors to find elements, it is possible to use XPath expressions too.
|
536
|
+
In SitePrism, everywhere that you can use a CSS selector, you can use an XPath expression (Standard Capybara logic).
|
550
537
|
|
551
538
|
An example:
|
552
539
|
|
@@ -1686,6 +1673,25 @@ When('I log in') do
|
|
1686
1673
|
end
|
1687
1674
|
```
|
1688
1675
|
|
1676
|
+
## Shadow Root
|
1677
|
+
|
1678
|
+
SitePrism allows you to interact with Shadow Roots too.
|
1679
|
+
|
1680
|
+
### Creating an Shadow Root
|
1681
|
+
|
1682
|
+
You can use the `section` methods and provide the arguments. Specify the reference name for the Shadow Root,
|
1683
|
+
the CSS selector to locate it, and add the `:shadow_root` option. For example:
|
1684
|
+
|
1685
|
+
```ruby
|
1686
|
+
class Home < SitePrism::Page
|
1687
|
+
section :foo, '.foo', shadow_root: true do
|
1688
|
+
element :bar, '.bar'
|
1689
|
+
end
|
1690
|
+
end
|
1691
|
+
```
|
1692
|
+
|
1693
|
+
NB: By default `shadow_root` will be set to false
|
1694
|
+
|
1689
1695
|
## SitePrism Configuration
|
1690
1696
|
|
1691
1697
|
SitePrism can be configured to change its behaviour.
|
@@ -4,7 +4,7 @@ module SitePrism
|
|
4
4
|
# [SitePrism::Deprecator]
|
5
5
|
class Deprecator
|
6
6
|
class << self
|
7
|
-
# @return SitePrism.logger.warn(msg)
|
7
|
+
# @return [SitePrism.logger.warn(msg)]
|
8
8
|
#
|
9
9
|
# Tells the user that they are using old functionality, which needs removing in the
|
10
10
|
# next major version
|
@@ -15,22 +15,7 @@ module SitePrism
|
|
15
15
|
warn("#{old} is being deprecated and should no longer be used.")
|
16
16
|
end
|
17
17
|
|
18
|
-
warn("#{old} will be removed in SitePrism
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return SitePrism.logger.debug(msg)
|
22
|
-
#
|
23
|
-
# Tells the user that they are using functionality which is non-optimal
|
24
|
-
# The functionality should usually provide a reason for it being poor, as well as an
|
25
|
-
# optional way of upgrading to something different
|
26
|
-
#
|
27
|
-
# NB: As this is bubbled up at debug level, often users will not see this. So it will
|
28
|
-
# never be a candidate for removal directly
|
29
|
-
def soft_deprecate(old, reason, new = nil)
|
30
|
-
debug("The #{old} method is changing, as is SitePrism, and is now advised to be changed.")
|
31
|
-
debug("REASON: #{reason}.")
|
32
|
-
debug('Moving forwards into SitePrism v5, the default behaviour will change.')
|
33
|
-
debug("We advise you change to using #{new}") if new
|
18
|
+
warn("#{old} will be removed in SitePrism v6. You have been warned!")
|
34
19
|
end
|
35
20
|
|
36
21
|
private
|
@@ -38,10 +23,6 @@ module SitePrism
|
|
38
23
|
def warn(msg)
|
39
24
|
SitePrism.logger.warn(msg)
|
40
25
|
end
|
41
|
-
|
42
|
-
def debug(msg)
|
43
|
-
SitePrism.logger.debug(msg)
|
44
|
-
end
|
45
26
|
end
|
46
27
|
end
|
47
28
|
end
|
@@ -15,35 +15,37 @@ module SitePrism
|
|
15
15
|
#
|
16
16
|
module Builder
|
17
17
|
# Return a list of all mapped items on a SitePrism class instance (Page or Section)
|
18
|
-
#
|
19
|
-
#
|
20
|
-
def mapped_items
|
21
|
-
return legacy_mapped_items if legacy
|
22
|
-
|
18
|
+
#
|
19
|
+
# @return [Hash]
|
20
|
+
def mapped_items
|
23
21
|
@mapped_items ||= { element: [], elements: [], section: [], sections: [], iframe: [] }
|
24
22
|
end
|
25
23
|
|
26
24
|
private
|
27
25
|
|
28
26
|
def build(type, name, *find_args)
|
29
|
-
|
27
|
+
invalid_element_name if invalid_element_name?(name)
|
28
|
+
blank_element(name) if find_args.empty?
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
map_item(type, name)
|
35
|
-
yield
|
36
|
-
end
|
30
|
+
mapped_items[type] << name.to_sym
|
31
|
+
yield
|
37
32
|
add_helper_methods(name, type, *find_args)
|
38
33
|
end
|
39
34
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
def invalid_element_name
|
36
|
+
raise InvalidDSLNameError, dsl_name_error
|
37
|
+
end
|
38
|
+
|
39
|
+
def invalid_element_name?(name)
|
40
|
+
!dsl_validation_disabled? && name_invalid?(name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def dsl_validation_disabled?
|
44
|
+
SitePrism.dsl_validation_disabled || ENV.key?('SITEPRISM_DSL_VALIDATION_DISABLED')
|
45
|
+
end
|
46
|
+
|
47
|
+
def blank_element(name)
|
48
|
+
raise SitePrism::InvalidElementError, "#{name} has come from an item with no locators."
|
47
49
|
end
|
48
50
|
|
49
51
|
def add_helper_methods(name, _type, *find_args)
|
@@ -99,26 +101,11 @@ module SitePrism
|
|
99
101
|
end
|
100
102
|
|
101
103
|
def create_helper_method(proposed_method_name, *find_args)
|
102
|
-
return
|
104
|
+
return blank_element(proposed_method_name) if find_args.empty?
|
103
105
|
|
104
106
|
yield
|
105
107
|
end
|
106
108
|
|
107
|
-
def legacy_mapped_items
|
108
|
-
@legacy_mapped_items ||= begin
|
109
|
-
SitePrism::Deprecator.deprecate(
|
110
|
-
'.mapped_items structure (internally), on a class',
|
111
|
-
'the new .mapped_items structure'
|
112
|
-
)
|
113
|
-
[]
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def map_item(type, name)
|
118
|
-
mapped_items(legacy: true) << { type => name }
|
119
|
-
mapped_items[type] << name.to_sym
|
120
|
-
end
|
121
|
-
|
122
109
|
def extract_section_options(args, &block)
|
123
110
|
if args.first.is_a?(Class)
|
124
111
|
klass = args.shift
|
@@ -13,21 +13,31 @@ module SitePrism
|
|
13
13
|
|
14
14
|
def _find(*find_args)
|
15
15
|
kwargs = find_args.pop
|
16
|
-
|
16
|
+
shadow_root = kwargs.delete(:shadow_root) { false }
|
17
|
+
check_capybara_version_if_creating_shadow_root if shadow_root
|
18
|
+
to_capybara_node.find(*find_args, **kwargs).tap do |element|
|
19
|
+
break element.shadow_root if shadow_root
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def _all(*find_args)
|
20
24
|
kwargs = find_args.pop
|
21
|
-
|
25
|
+
shadow_root = kwargs.delete(:shadow_root) { false }
|
26
|
+
check_capybara_version_if_creating_shadow_root if shadow_root
|
27
|
+
to_capybara_node.all(*find_args, **kwargs).tap do |element|
|
28
|
+
break element.map(&:shadow_root) if shadow_root
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
def element_exists?(*find_args)
|
25
33
|
kwargs = find_args.pop
|
34
|
+
kwargs.delete(:shadow_root)
|
26
35
|
to_capybara_node.has_selector?(*find_args, **kwargs)
|
27
36
|
end
|
28
37
|
|
29
38
|
def element_does_not_exist?(*find_args)
|
30
39
|
kwargs = find_args.pop
|
40
|
+
kwargs.delete(:shadow_root)
|
31
41
|
to_capybara_node.has_no_selector?(*find_args, **kwargs)
|
32
42
|
end
|
33
43
|
|
@@ -63,6 +73,13 @@ module SitePrism
|
|
63
73
|
options.merge!(runtime_args.pop) if runtime_args.last.is_a? Hash
|
64
74
|
options[:wait] = Capybara.default_max_wait_time unless options.key?(:wait)
|
65
75
|
end
|
76
|
+
|
77
|
+
def check_capybara_version_if_creating_shadow_root
|
78
|
+
minimum_version = '3.37.0'
|
79
|
+
raise SitePrism::UnsupportedGemVersionError unless Capybara::VERSION >= minimum_version
|
80
|
+
|
81
|
+
SitePrism.logger.error("Shadow root support requires Capybara version >= #{minimum_version}. You are using #{Capybara::VERSION}.")
|
82
|
+
end
|
66
83
|
end
|
67
84
|
end
|
68
85
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module SitePrism
|
4
4
|
module DSL
|
5
|
-
# [SitePrism::DSL::
|
5
|
+
# [SitePrism::DSL::Validator]
|
6
6
|
#
|
7
7
|
# This is the new validator module which will check all DSL items against a whitelist
|
8
8
|
# for any entries which break specific rules
|
@@ -10,7 +10,9 @@ module SitePrism
|
|
10
10
|
# @api private
|
11
11
|
#
|
12
12
|
module Validator
|
13
|
-
|
13
|
+
attr_accessor :dsl_name_error
|
14
|
+
|
15
|
+
def name_invalid?(name)
|
14
16
|
prefix_invalid?(name) ||
|
15
17
|
suffix_invalid?(name) ||
|
16
18
|
characters_invalid?(name) ||
|
@@ -20,25 +22,25 @@ module SitePrism
|
|
20
22
|
private
|
21
23
|
|
22
24
|
def prefix_invalid?(name)
|
23
|
-
return unless prefix_blacklist.any? { |prefix| name.start_with?(prefix) }
|
25
|
+
return false unless prefix_blacklist.any? { |prefix| name.start_with?(prefix) }
|
24
26
|
|
25
27
|
log_failure(name, 'prefix')
|
26
28
|
end
|
27
29
|
|
28
30
|
def suffix_invalid?(name)
|
29
|
-
return unless suffix_blacklist.any? { |prefix| name.end_with?(prefix) }
|
31
|
+
return false unless suffix_blacklist.any? { |prefix| name.end_with?(prefix) }
|
30
32
|
|
31
33
|
log_failure(name, 'suffix')
|
32
34
|
end
|
33
35
|
|
34
36
|
def characters_invalid?(name)
|
35
|
-
return if name.match?(regex_permission)
|
37
|
+
return false if name.match?(regex_permission)
|
36
38
|
|
37
39
|
log_failure(name, 'character(s)')
|
38
40
|
end
|
39
41
|
|
40
42
|
def blacklisted?(name)
|
41
|
-
return unless blacklisted_names.include?(name)
|
43
|
+
return false unless blacklisted_names.include?(name)
|
42
44
|
|
43
45
|
log_failure(name, 'name (blacklisted entry)')
|
44
46
|
end
|
@@ -76,7 +78,7 @@ module SitePrism
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def log_failure(name, type)
|
79
|
-
|
81
|
+
self.dsl_name_error = "DSL item: #{name} has an invalid #{type}"
|
80
82
|
SitePrism.logger.debug(debug_error(type))
|
81
83
|
end
|
82
84
|
|
@@ -13,7 +13,7 @@ module SitePrism
|
|
13
13
|
# for how the definition of "every item" is derived.
|
14
14
|
#
|
15
15
|
# Example
|
16
|
-
#
|
16
|
+
# `@my_page.class.mapped_items`
|
17
17
|
# {
|
18
18
|
# element => [:button_one, :button_two],
|
19
19
|
# elements => [:button_collection_one, :button_collection_two],
|
@@ -21,7 +21,7 @@ module SitePrism
|
|
21
21
|
# sections => [:search_result],
|
22
22
|
# iframe => []
|
23
23
|
# }
|
24
|
-
#
|
24
|
+
# `@my_page.all_there?`
|
25
25
|
# => true - If the items above are all present
|
26
26
|
#
|
27
27
|
# Note that #elements_to_check will check the hash of mapped_items
|
data/lib/site_prism/error.rb
CHANGED
@@ -50,4 +50,7 @@ module SitePrism
|
|
50
50
|
|
51
51
|
# DSL items are not permitted to be named in certain ways
|
52
52
|
class InvalidDSLNameError < AttributeValidationError; end
|
53
|
+
|
54
|
+
# The version of the target gem is unsupported, so using that feature is not possible
|
55
|
+
class UnsupportedGemVersionError < SitePrismError; end
|
53
56
|
end
|
data/lib/site_prism/loadable.rb
CHANGED
@@ -13,10 +13,8 @@ module SitePrism
|
|
13
13
|
base.extend(ClassMethods)
|
14
14
|
end
|
15
15
|
|
16
|
-
# In certain circumstances, we cache that the page has already
|
17
|
-
#
|
18
|
-
# call `loaded?` a second time do not need to perform
|
19
|
-
# the load_validation queries against the page a second time.
|
16
|
+
# In certain circumstances, we cache that the page or section has already been "loaded" so that actions which
|
17
|
+
# call `loaded?` a second time do not need to perform the load_validation queries against the page a second time.
|
20
18
|
attr_accessor :loaded, :load_error
|
21
19
|
|
22
20
|
# Executes the given block after the page is loaded.
|
@@ -27,8 +25,7 @@ module SitePrism
|
|
27
25
|
# inside another when_loaded block.
|
28
26
|
previously_loaded = loaded
|
29
27
|
|
30
|
-
# Within the block, check (and cache) loaded?, to see whether the
|
31
|
-
# page has indeed loaded according to the rules defined by the user.
|
28
|
+
# Within the block, check (and cache) loaded?, to see whether the page has indeed loaded according to the rules defined by the user.
|
32
29
|
self.loaded = loaded?
|
33
30
|
|
34
31
|
# If the page hasn't loaded. Then crash and return the error message.
|
@@ -68,13 +65,12 @@ module SitePrism
|
|
68
65
|
end
|
69
66
|
|
70
67
|
# [SitePrism::Loadable::ClassMethods]
|
71
|
-
# This exposes all of the DSL definitions users will use when generating "
|
68
|
+
# This exposes all of the DSL definitions users will use when generating "Loadables"
|
72
69
|
#
|
73
|
-
# A "Loadable" is a definition whereby the page object once loaded must pass a boolean check
|
74
|
-
# These
|
70
|
+
# A "Loadable" is a definition whereby the page/section object once loaded must pass a boolean check
|
71
|
+
# These Loadables are typically provided using the method `load_validation`
|
75
72
|
module ClassMethods
|
76
|
-
# The list of load_validations.
|
77
|
-
# They will be executed in the order they are defined.
|
73
|
+
# The list of load_validations. They are executed in the order they are defined.
|
78
74
|
#
|
79
75
|
# @return [Array]
|
80
76
|
def load_validations
|
@@ -85,21 +81,15 @@ module SitePrism
|
|
85
81
|
end
|
86
82
|
end
|
87
83
|
|
88
|
-
# Appends a load validation block to the page class.
|
84
|
+
# Appends a load validation block to the page/section class.
|
89
85
|
#
|
90
|
-
# When `loaded?` is called, these blocks are instance_eval'd
|
91
|
-
#
|
92
|
-
# This allows users to wait for specific events to occur on
|
93
|
-
# the page or certain elements to be loaded before performing
|
94
|
-
# any actions on the page.
|
86
|
+
# When `loaded?` is called, these blocks are instance_eval'd against the current page instance. This allows users to wait for
|
87
|
+
# specific events to occur on the page or certain elements to be loaded before performing any actions on the page.
|
95
88
|
#
|
96
|
-
# @param block [&block] A block which returns true if the page
|
97
|
-
#
|
98
|
-
# This block can contain up to 2 elements in an array
|
99
|
-
# The first is the physical validation test to be truthily evaluated.
|
89
|
+
# @param block [&block] A block which returns true if the page loaded successfully, or false if it did not.
|
90
|
+
# This block can contain up to 2 elements in an array -> The first is the physical validation test to be truthily evaluated.
|
100
91
|
#
|
101
|
-
# If this does not pass, then the 2nd item (if defined), is output
|
102
|
-
# as an error message to the +FailedLoadValidationError+ that is thrown
|
92
|
+
# If this does not pass, then the 2nd item (if defined), is output as an error message on the +FailedLoadValidationError+
|
103
93
|
#
|
104
94
|
# @return [Proc]
|
105
95
|
def load_validation(&block)
|
data/lib/site_prism/logger.rb
CHANGED
@@ -10,7 +10,7 @@ module SitePrism
|
|
10
10
|
def create(output = $stdout)
|
11
11
|
logger = ::Logger.new(output)
|
12
12
|
logger.progname = 'SitePrism'
|
13
|
-
logger.level = :
|
13
|
+
logger.level = :WARN
|
14
14
|
logger.formatter = proc do |severity, time, progname, msg|
|
15
15
|
"#{time.strftime('%F %T')} - #{severity} - #{progname} - #{msg}\n"
|
16
16
|
end
|
data/lib/site_prism/page.rb
CHANGED
@@ -36,7 +36,7 @@ module SitePrism
|
|
36
36
|
# The specific url matcher that is used to validate the page is loaded.
|
37
37
|
# When one hasn't been previously set, use the url that was set as a direct Regexp exact matcher
|
38
38
|
#
|
39
|
-
# @return [Regexp]
|
39
|
+
# @return [Regexp || String]
|
40
40
|
def url_matcher
|
41
41
|
@url_matcher ||= url
|
42
42
|
end
|
@@ -170,6 +170,7 @@ module SitePrism
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def load_html_string(string)
|
173
|
+
SitePrism::Deprecator.deprecate('Using an input fragment (Loading partials using html strings).')
|
173
174
|
@page = Capybara.string(string)
|
174
175
|
yield to_capybara_node if block_given?
|
175
176
|
end
|
data/lib/site_prism/version.rb
CHANGED
data/lib/site_prism.rb
CHANGED
@@ -22,6 +22,11 @@ require 'site_prism/waiter'
|
|
22
22
|
# [SitePrism]
|
23
23
|
module SitePrism
|
24
24
|
class << self
|
25
|
+
# SitePrism will enforce strict validation on all generated DSL items i.e. `element`
|
26
|
+
# The validations are found inside the SitePrism::DSL::Validator module
|
27
|
+
# NB: To ensure no unwanted validation issues, this must be disabled BEFORE any page / section code is autoloaded
|
28
|
+
attr_accessor :dsl_validation_disabled
|
29
|
+
|
25
30
|
def configure
|
26
31
|
yield self
|
27
32
|
end
|
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: 5.0
|
4
|
+
version: '5.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Hill
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -49,22 +49,22 @@ dependencies:
|
|
49
49
|
name: site_prism-all_there
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2'
|
55
55
|
- - "<"
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
57
|
+
version: '5'
|
58
58
|
type: :runtime
|
59
59
|
prerelease: false
|
60
60
|
version_requirements: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- - "
|
62
|
+
- - ">"
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '2'
|
65
65
|
- - "<"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '5'
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: automation_helpers
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,14 +119,14 @@ dependencies:
|
|
119
119
|
requirements:
|
120
120
|
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: 1.
|
122
|
+
version: 1.57.1
|
123
123
|
type: :development
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - "~>"
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 1.
|
129
|
+
version: 1.57.1
|
130
130
|
- !ruby/object:Gem::Dependency
|
131
131
|
name: rubocop-performance
|
132
132
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,14 +147,14 @@ dependencies:
|
|
147
147
|
requirements:
|
148
148
|
- - "~>"
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: 2.
|
150
|
+
version: 2.25.0
|
151
151
|
type: :development
|
152
152
|
prerelease: false
|
153
153
|
version_requirements: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - "~>"
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version: 2.
|
157
|
+
version: 2.25.0
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: selenium-webdriver
|
160
160
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,9 +230,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: '2.7'
|
231
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
232
|
requirements:
|
233
|
-
- - "
|
233
|
+
- - ">="
|
234
234
|
- !ruby/object:Gem::Version
|
235
|
-
version:
|
235
|
+
version: '0'
|
236
236
|
requirements: []
|
237
237
|
rubygems_version: 3.2.3
|
238
238
|
signing_key:
|