site_prism 2.15.1 → 2.16
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 +5 -5
- data/README.md +75 -66
- data/lib/site_prism.rb +4 -1
- data/lib/site_prism/element_container.rb +28 -20
- data/lib/site_prism/error.rb +5 -4
- data/lib/site_prism/loadable.rb +26 -1
- data/lib/site_prism/page.rb +12 -16
- data/lib/site_prism/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91f1632193e711e5407036c5674c839746dc6411bd9d4b851f5872aff13f67dc
|
4
|
+
data.tar.gz: 0847ba2fe40e538940888176910aad356357f6fad87e2d7bff87af20a2b03f67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc11978a37f85598d22081d96ede596181866c9533357bf42e5fe17530c4082780c9272186e3b579eff61d89d5d1ef6afa6e5a009eba26f655d6eefa70d41ca4
|
7
|
+
data.tar.gz: c609309f64ba914756fffcb9038345741e14c73f07d508fe246a96e5b7697e7e8486011e4d95d7a6dd8145d58113e07fab533ce503b4eee3ec54240f230e9db6
|
data/README.md
CHANGED
@@ -17,9 +17,9 @@ We have a brief set of setup docs [HERE](https://github.com/natritmeyer/site_pri
|
|
17
17
|
|
18
18
|
## Supported Rubies / Browsers
|
19
19
|
|
20
|
-
SitePrism is built and tested to work on Ruby 2.
|
20
|
+
SitePrism is built and tested to work on Ruby 2.3 - 2.5. There is also some limited support for the Ruby 2.2 series.
|
21
21
|
|
22
|
-
SitePrism should run on all major browsers. The gem's integration tests are ran on
|
22
|
+
SitePrism should run on all major browsers. The gem's integration tests are ran on Chrome and Firefox.
|
23
23
|
|
24
24
|
If you find your browser doesn't integrate nicely with SitePrism, please open an [issue request](https://github.com/natritmeyer/site_prism/issues/new)
|
25
25
|
|
@@ -142,7 +142,7 @@ to then use instances of those classes in your tests.
|
|
142
142
|
If a class represents a page then each element of the page is
|
143
143
|
represented by a method that, when called, returns a reference to that
|
144
144
|
element that can then be acted upon (clicked, set text value), or
|
145
|
-
queried (is it enabled? visible?).
|
145
|
+
queried (is it enabled? / visible?).
|
146
146
|
|
147
147
|
SitePrism is based around this concept, but goes further as you'll see
|
148
148
|
below by also allowing modelling of repeated sections that appear on
|
@@ -184,14 +184,14 @@ class Home < SitePrism::Page
|
|
184
184
|
end
|
185
185
|
```
|
186
186
|
|
187
|
-
Note that setting a URL is optional - you only need to set a url if you want to be able to
|
188
|
-
directly to that page. It makes sense to set the URL for a page model of a
|
189
|
-
page or a login page, but probably not a search results page.
|
187
|
+
Note that setting a URL is optional - you only need to set a url if you want to be able to
|
188
|
+
navigate directly to that page. It makes sense to set the URL for a page model of a
|
189
|
+
home page or a login page, but probably not a search results page.
|
190
190
|
|
191
191
|
#### Parametrized URLs
|
192
192
|
|
193
|
-
SitePrism uses the
|
194
|
-
a simple example:
|
193
|
+
SitePrism uses the `addressable` gem and therefore allows for parameterization of URLs.
|
194
|
+
Here is a simple example:
|
195
195
|
|
196
196
|
```ruby
|
197
197
|
class UserProfile < SitePrism::Page
|
@@ -255,7 +255,7 @@ See https://github.com/sporkmonger/addressable for more details on parameterized
|
|
255
255
|
Automated tests often need to verify that a particular page is
|
256
256
|
displayed. SitePrism can automatically parse your URL template
|
257
257
|
and verify that whatever components your template specifies match the
|
258
|
-
currently viewed page.
|
258
|
+
currently viewed page. For example, with the following URL template:
|
259
259
|
|
260
260
|
```ruby
|
261
261
|
class Account < SitePrism::Page
|
@@ -289,9 +289,8 @@ account number 22, you could assert the following:
|
|
289
289
|
expect(@account_page).to be_displayed(id: 22)
|
290
290
|
```
|
291
291
|
|
292
|
-
You can even use regular expressions.
|
293
|
-
|
294
|
-
say:
|
292
|
+
You can even use regular expressions. If for example, you wanted to ensure that the
|
293
|
+
browser was displaying an account with an id ending with 2, you could do:
|
295
294
|
|
296
295
|
```ruby
|
297
296
|
expect(@account_page).to be_displayed(id: /2\z/)
|
@@ -314,7 +313,7 @@ expect(@account_page.url_matches['query']['token']).to eq('ca2786616a4285bc')
|
|
314
313
|
#### Falling back to basic regexp matchers
|
315
314
|
|
316
315
|
If SitePrism's built-in URL matching is not sufficient for your needs
|
317
|
-
|
316
|
+
you can override and use SitePrism's previous support for regular expression-based
|
318
317
|
URL matchers by it by calling `set_url_matcher`:
|
319
318
|
|
320
319
|
```ruby
|
@@ -325,8 +324,7 @@ end
|
|
325
324
|
|
326
325
|
#### Testing for Page display
|
327
326
|
|
328
|
-
SitePrism's `#displayed?` predicate method allows for semantic code in
|
329
|
-
your test:
|
327
|
+
SitePrism's `#displayed?` predicate method allows for semantic code in your tests:
|
330
328
|
|
331
329
|
```ruby
|
332
330
|
Then /^the account page is displayed$/ do
|
@@ -345,7 +343,6 @@ class Account < SitePrism::Page
|
|
345
343
|
end
|
346
344
|
|
347
345
|
@account = Account.new
|
348
|
-
#...
|
349
346
|
@account.current_url #=> "http://www.example.com/account/123"
|
350
347
|
expect(@account.current_url).to include('example.com/account/')
|
351
348
|
```
|
@@ -359,7 +356,6 @@ class Account < SitePrism::Page
|
|
359
356
|
end
|
360
357
|
|
361
358
|
@account = Account.new
|
362
|
-
#...
|
363
359
|
@account.title #=> "Welcome to Your Account"
|
364
360
|
```
|
365
361
|
|
@@ -375,7 +371,6 @@ class Account < SitePrism::Page
|
|
375
371
|
end
|
376
372
|
|
377
373
|
@account = Account.new
|
378
|
-
#...
|
379
374
|
@account.secure? #=> true/false
|
380
375
|
expect(@account).to be_secure
|
381
376
|
```
|
@@ -577,13 +572,9 @@ end
|
|
577
572
|
@home.has_search_field?
|
578
573
|
@home.has_no_search_field?
|
579
574
|
@home.wait_for_search_field
|
580
|
-
@home.wait_for_search_field(10)
|
581
575
|
@home.wait_for_no_search_field
|
582
|
-
@home.wait_for_no_search_field(10)
|
583
576
|
@home.wait_until_search_field_visible
|
584
|
-
@home.wait_until_search_field_visible(10)
|
585
577
|
@home.wait_until_search_field_invisible
|
586
|
-
@home.wait_until_search_field_invisible(10)
|
587
578
|
|
588
579
|
```
|
589
580
|
|
@@ -686,7 +677,7 @@ end
|
|
686
677
|
|
687
678
|
```
|
688
679
|
|
689
|
-
|
680
|
+
You can also wait for the existence of a list of names like this:
|
690
681
|
|
691
682
|
```ruby
|
692
683
|
@friends_page.wait_for_names
|
@@ -731,12 +722,11 @@ the default Capybara wait time:
|
|
731
722
|
|
732
723
|
### Checking that all mapped elements are present on the page
|
733
724
|
|
734
|
-
Throughout my time in test automation I keep getting asked to provide the
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
present in the browser, false if they're not all there.
|
725
|
+
Throughout my time in test automation I keep getting asked to provide the ability to
|
726
|
+
check that all elements that should be on the page are on the page. Why people
|
727
|
+
would want to test this, I don't know. But if that's what you want to do, SitePrism
|
728
|
+
provides the `#all_there?` method that will return `true` if all mapped items
|
729
|
+
are present in the browser and `false` if they're not all there.
|
740
730
|
|
741
731
|
```ruby
|
742
732
|
@friends_page.all_there? #=> true/false
|
@@ -754,19 +744,19 @@ You may wish to have elements declared in a page object class that are not alway
|
|
754
744
|
class TestPage < SitePrism::Page
|
755
745
|
element :name_field, '#name'
|
756
746
|
element :address_field, '#address'
|
757
|
-
element :
|
747
|
+
element :success_message, 'span.alert-success'
|
758
748
|
|
759
749
|
expected_elements :name_field, :address_field
|
760
750
|
end
|
761
751
|
```
|
762
752
|
|
763
|
-
And if you aren't sure which elements
|
753
|
+
And if you aren't sure which elements will be present, Then ask SitePrism to tell you!
|
764
754
|
|
765
755
|
```ruby
|
766
756
|
class TestPage < SitePrism::Page
|
767
757
|
element :name_field, '#name'
|
768
758
|
element :address_field, '#address'
|
769
|
-
element :
|
759
|
+
element :success_message, 'span.alert-success'
|
770
760
|
end
|
771
761
|
|
772
762
|
# and... Only `address_field` is on the page
|
@@ -788,7 +778,6 @@ page section, the second returns an array of section instances, one for
|
|
788
778
|
each capybara element found by the supplied css selector. What follows
|
789
779
|
is an explanation of `section`.
|
790
780
|
|
791
|
-
|
792
781
|
#### Defining a Section
|
793
782
|
|
794
783
|
A section is similar to a page in that it inherits from a SitePrism
|
@@ -812,20 +801,17 @@ class Home < SitePrism::Page
|
|
812
801
|
end
|
813
802
|
```
|
814
803
|
|
815
|
-
The way to add a section to a page (or another section -
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
on this page (note that the css selector can be different for different
|
824
|
-
pages as the whole point of sections is that they can appear in
|
825
|
-
different places on different pages).
|
804
|
+
The way to add a section to a page (or another section - which is possible) is to
|
805
|
+
call the `section` method. It takes 3 arguments: the first is the name of the section as
|
806
|
+
referred to on the page (sections that appear on multiple pages can be named differently).
|
807
|
+
The second argument is the class of which an instance will be created to represent
|
808
|
+
the page section, and the following arguments are [Capybara::Node::Finders](https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders).
|
809
|
+
These identify the root node of the section on this page (note that the css selector
|
810
|
+
can be different for different pages as the whole point of sections is that they can
|
811
|
+
appear in different places / ways on different pages).
|
826
812
|
|
827
|
-
|
828
|
-
|
813
|
+
You can define a section as a class and/or an Anonymous section. This will then allow you
|
814
|
+
to have some handy constructs like the one below
|
829
815
|
|
830
816
|
```ruby
|
831
817
|
class People < SitePrism::Section
|
@@ -995,7 +981,7 @@ class MyPage < SitePrism::Page
|
|
995
981
|
end
|
996
982
|
```
|
997
983
|
|
998
|
-
|
984
|
+
Then calling `#parent` will return the following:
|
999
985
|
|
1000
986
|
```ruby
|
1001
987
|
@my_page = MyPage.new
|
@@ -1049,7 +1035,7 @@ class Home < SitePrism::Page
|
|
1049
1035
|
end
|
1050
1036
|
```
|
1051
1037
|
|
1052
|
-
|
1038
|
+
You can check whether the section is present on the page or not:
|
1053
1039
|
|
1054
1040
|
```ruby
|
1055
1041
|
@home = Home.new
|
@@ -1461,7 +1447,7 @@ class BasePage < SitePrism::Page
|
|
1461
1447
|
|
1462
1448
|
load_validation do
|
1463
1449
|
wait_for_loading_message(1)
|
1464
|
-
[
|
1450
|
+
[has_no_loading_message?(wait: 10), 'loading message was still displayed']
|
1465
1451
|
end
|
1466
1452
|
end
|
1467
1453
|
|
@@ -1529,7 +1515,7 @@ The method calls below will succeed, provided the elements appear on the page wi
|
|
1529
1515
|
# OR
|
1530
1516
|
@results_page.search_results(count: 25)
|
1531
1517
|
# OR
|
1532
|
-
@results_page.wait_for_search_results(nil, :
|
1518
|
+
@results_page.wait_for_search_results(nil, count: 25)
|
1533
1519
|
# Note that wait_for_<element_name> expects a timeout value to be passed as the first parameter or nil to use the default timeout value.
|
1534
1520
|
```
|
1535
1521
|
|
@@ -1599,7 +1585,7 @@ is embedded into. Like a section, it is possible to test for the
|
|
1599
1585
|
existence of the iframe, wait for it to exist as well as interact with
|
1600
1586
|
the page it contains.
|
1601
1587
|
|
1602
|
-
### Creating an
|
1588
|
+
### Creating an iFrame
|
1603
1589
|
|
1604
1590
|
An iframe is declared in the same way as a Page:
|
1605
1591
|
|
@@ -1701,13 +1687,16 @@ end
|
|
1701
1687
|
|
1702
1688
|
SitePrism can be configured to change its behaviour.
|
1703
1689
|
|
1690
|
+
For each of the following configuration options, either add it in the `spec_helper.rb` file
|
1691
|
+
if you are running SitePrism as a Unit Test framework, or in your `env.rb` if you are running
|
1692
|
+
a Cucumber based framework
|
1693
|
+
|
1704
1694
|
### Using Capybara Implicit Waits
|
1705
1695
|
|
1706
1696
|
By default, SitePrism element and section methods do not utilize
|
1707
1697
|
Capybara's implicit wait methodology and will return immediately if
|
1708
|
-
the element or section requested is not found on the page.
|
1709
|
-
following code to
|
1710
|
-
wait methodology to pass through:
|
1698
|
+
the element or section requested is not found on the page. Add the
|
1699
|
+
following code to enable Capybara's implicit wait methodology.
|
1711
1700
|
|
1712
1701
|
```ruby
|
1713
1702
|
SitePrism.configure do |config|
|
@@ -1721,21 +1710,22 @@ This enables you to replace this:
|
|
1721
1710
|
# wait_until methods always wait for the element to be present on the page:
|
1722
1711
|
@search_page.wait_for_search_results
|
1723
1712
|
|
1724
|
-
# Element and section methods do not
|
1713
|
+
# Element and section methods do not (But will do if you configure the above)
|
1725
1714
|
@search_page.search_results
|
1726
1715
|
```
|
1727
1716
|
|
1728
1717
|
with this:
|
1729
1718
|
|
1730
1719
|
```ruby
|
1731
|
-
# With implicit waits enabled, use of wait_until methods is no longer required.
|
1732
|
-
# wait for the element to be found on the page
|
1720
|
+
# With implicit waits enabled, use of wait_until methods is no longer required.
|
1721
|
+
# This method will wait for the element to be found on the page or
|
1722
|
+
# until the `Capybara.default_max_wait_time` timeout is reached.
|
1733
1723
|
@search_page.search_results
|
1734
1724
|
```
|
1735
1725
|
|
1736
1726
|
Note that even with implicit waits on you can temporarily modify wait times in SitePrism to help work-around special circumstances.
|
1737
1727
|
|
1738
|
-
```
|
1728
|
+
```ruby
|
1739
1729
|
# Option 1: using wait_for
|
1740
1730
|
@search_page.wait_for_search_results(30) # will wait up to 30seconds
|
1741
1731
|
|
@@ -1752,10 +1742,9 @@ an error if an element does not appear or disappear within the timeout period an
|
|
1752
1742
|
simply return `false` and allow the test to continue. This is different from
|
1753
1743
|
the other methods such as `wait_until_*_visible` which do raise errors.
|
1754
1744
|
|
1755
|
-
Add the following code
|
1756
|
-
|
1757
|
-
|
1758
|
-
waiting to not exist:
|
1745
|
+
Add the following code to enable errors to be raised immediately when a
|
1746
|
+
`wait_for_*` method does not find the element it is waiting for and when a
|
1747
|
+
`wait_for_no_*` method continues to find an element it is waiting to not exist.
|
1759
1748
|
|
1760
1749
|
```ruby
|
1761
1750
|
SitePrism.configure do |config|
|
@@ -1773,7 +1762,7 @@ raise unless @search_page.wait_for_no_search_results
|
|
1773
1762
|
|
1774
1763
|
with this:
|
1775
1764
|
|
1776
|
-
```
|
1765
|
+
```ruby
|
1777
1766
|
# With raise on wait_fors enabled, this will automatically raise
|
1778
1767
|
# if no search results are found
|
1779
1768
|
@search_page.wait_for_search_results
|
@@ -1781,6 +1770,27 @@ with this:
|
|
1781
1770
|
@search_page.wait_for_no_search_results
|
1782
1771
|
```
|
1783
1772
|
|
1773
|
+
## Configuring default load_validations
|
1774
|
+
|
1775
|
+
By default, SitePrism will add a single default load validation to all pages.
|
1776
|
+
This single load validation verifies the page URL is correct, and will run whenever you
|
1777
|
+
call `#loaded?` on an instantiated page. It uses the DSL defined `set_url` or `set_url_matcher`
|
1778
|
+
as a source of truth to compare the value of `page.current_url` when you call `#loaded?`
|
1779
|
+
|
1780
|
+
However there may be times you are unsure what your page URL will even look like, or you
|
1781
|
+
might not want this validation to run first, or even at all. In these situations it is
|
1782
|
+
sometimes desirable to remove this default validation.
|
1783
|
+
|
1784
|
+
Adding the below code and SitePrism will remove this validation from being
|
1785
|
+
set up for all your pages (And ran accordingly). Note that by default this validation
|
1786
|
+
is set to run on **all** pages.
|
1787
|
+
|
1788
|
+
```ruby
|
1789
|
+
SitePrism.configure do |config|
|
1790
|
+
config.default_load_validations = false
|
1791
|
+
end
|
1792
|
+
```
|
1793
|
+
|
1784
1794
|
## Using SitePrism with VCR
|
1785
1795
|
|
1786
1796
|
There's a SitePrism plugin called `site_prism.vcr` that lets you use
|
@@ -1862,6 +1872,5 @@ end
|
|
1862
1872
|
# etc...
|
1863
1873
|
```
|
1864
1874
|
|
1865
|
-
The only thing that needs instantiating is the App class - from then on
|
1866
|
-
|
1867
|
-
@app. Maintenance win!
|
1875
|
+
The only thing that needs instantiating is the App class - from then on pages don't
|
1876
|
+
need to be initialized, they are now returned by methods on @app. Maintenance win!
|
data/lib/site_prism.rb
CHANGED
@@ -12,13 +12,16 @@ module SitePrism
|
|
12
12
|
autoload :AddressableUrlMatcher, 'site_prism/addressable_url_matcher'
|
13
13
|
|
14
14
|
class << self
|
15
|
-
attr_accessor :use_implicit_waits,
|
15
|
+
attr_accessor :use_implicit_waits,
|
16
|
+
:raise_on_wait_fors,
|
17
|
+
:default_load_validations
|
16
18
|
|
17
19
|
def configure
|
18
20
|
yield self
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
@default_load_validations = true
|
22
25
|
@use_implicit_waits = false
|
23
26
|
@raise_on_wait_fors = false
|
24
27
|
end
|
@@ -8,10 +8,18 @@ module SitePrism
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def
|
11
|
+
def wait_time
|
12
12
|
Capybara.default_max_wait_time
|
13
13
|
end
|
14
14
|
|
15
|
+
def checker_wait_time
|
16
|
+
if SitePrism.use_implicit_waits
|
17
|
+
wait_time
|
18
|
+
else
|
19
|
+
0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
def raise_if_block(obj, name, has_block, type)
|
16
24
|
return unless has_block
|
17
25
|
warn "Type passed in: #{type}"
|
@@ -169,9 +177,9 @@ module SitePrism
|
|
169
177
|
method_name = "has_#{element_name}?"
|
170
178
|
create_helper_method(method_name, *find_args) do
|
171
179
|
define_method(method_name) do |*runtime_args|
|
172
|
-
|
173
|
-
|
174
|
-
element_exists?(*
|
180
|
+
visibility_args = { wait: checker_wait_time }
|
181
|
+
args = merge_args(find_args, runtime_args, visibility_args)
|
182
|
+
element_exists?(*args)
|
175
183
|
end
|
176
184
|
end
|
177
185
|
end
|
@@ -180,11 +188,9 @@ module SitePrism
|
|
180
188
|
method_name = "has_no_#{element_name}?"
|
181
189
|
create_helper_method(method_name, *find_args) do
|
182
190
|
define_method(method_name) do |*runtime_args|
|
183
|
-
|
184
|
-
|
185
|
-
element_does_not_exist?(
|
186
|
-
*merge_args(find_args, runtime_args, **visibility_args)
|
187
|
-
)
|
191
|
+
visibility_args = { wait: checker_wait_time }
|
192
|
+
args = merge_args(find_args, runtime_args, visibility_args)
|
193
|
+
element_does_not_exist?(*args)
|
188
194
|
end
|
189
195
|
end
|
190
196
|
end
|
@@ -192,10 +198,11 @@ module SitePrism
|
|
192
198
|
def create_waiter(element_name, *find_args)
|
193
199
|
method_name = "wait_for_#{element_name}"
|
194
200
|
create_helper_method(method_name, *find_args) do
|
195
|
-
define_method(method_name) do |timeout =
|
201
|
+
define_method(method_name) do |timeout = wait_time, *runtime_args|
|
196
202
|
visibility_args = { wait: timeout }
|
197
|
-
|
198
|
-
|
203
|
+
args = merge_args(find_args, runtime_args, visibility_args)
|
204
|
+
result = element_exists?(*args)
|
205
|
+
raise_wait_for_if_failed(self, element_name, timeout, !result)
|
199
206
|
result
|
200
207
|
end
|
201
208
|
end
|
@@ -204,11 +211,12 @@ module SitePrism
|
|
204
211
|
def create_nonexistence_waiter(element_name, *find_args)
|
205
212
|
method_name = "wait_for_no_#{element_name}"
|
206
213
|
create_helper_method(method_name, *find_args) do
|
207
|
-
define_method(method_name) do |timeout =
|
214
|
+
define_method(method_name) do |timeout = wait_time, *runtime_args|
|
208
215
|
visibility_args = { wait: timeout }
|
209
|
-
|
210
|
-
|
211
|
-
|
216
|
+
args = merge_args(find_args, runtime_args, visibility_args)
|
217
|
+
result = element_does_not_exist?(*args)
|
218
|
+
raise_wait_for_no_if_failed(self, element_name, timeout, !result)
|
219
|
+
result
|
212
220
|
end
|
213
221
|
end
|
214
222
|
end
|
@@ -216,9 +224,9 @@ module SitePrism
|
|
216
224
|
def create_visibility_waiter(element_name, *find_args)
|
217
225
|
method_name = "wait_until_#{element_name}_visible"
|
218
226
|
create_helper_method(method_name, *find_args) do
|
219
|
-
define_method(method_name) do |timeout =
|
227
|
+
define_method(method_name) do |timeout = wait_time, *runtime_args|
|
220
228
|
visibility_args = { visible: true, wait: timeout }
|
221
|
-
args = merge_args(find_args, runtime_args,
|
229
|
+
args = merge_args(find_args, runtime_args, visibility_args)
|
222
230
|
return true if element_exists?(*args)
|
223
231
|
raise SitePrism::TimeOutWaitingForElementVisibility
|
224
232
|
end
|
@@ -228,9 +236,9 @@ module SitePrism
|
|
228
236
|
def create_invisibility_waiter(element_name, *find_args)
|
229
237
|
method_name = "wait_until_#{element_name}_invisible"
|
230
238
|
create_helper_method(method_name, *find_args) do
|
231
|
-
define_method(method_name) do |timeout =
|
239
|
+
define_method(method_name) do |timeout = wait_time, *runtime_args|
|
232
240
|
visibility_args = { visible: true, wait: timeout }
|
233
|
-
args = merge_args(find_args, runtime_args,
|
241
|
+
args = merge_args(find_args, runtime_args, visibility_args)
|
234
242
|
return true if element_does_not_exist?(*args)
|
235
243
|
raise SitePrism::TimeOutWaitingForElementInvisibility
|
236
244
|
end
|
data/lib/site_prism/error.rb
CHANGED
@@ -80,10 +80,11 @@ module SitePrism
|
|
80
80
|
InvalidUrlMatcher = InvalidUrlMatcherError
|
81
81
|
NoSelectorForElement = InvalidElementError
|
82
82
|
TimeoutException = TimeoutError
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
# Below four have different inheritance for now to avoid message leaking
|
84
|
+
TimeOutWaitingForExistenceError = Class.new(StandardError)
|
85
|
+
TimeOutWaitingForNonExistenceError = Class.new(StandardError)
|
86
|
+
TimeOutWaitingForElementVisibility = Class.new(StandardError)
|
87
|
+
TimeOutWaitingForElementInvisibility = Class.new(StandardError)
|
87
88
|
UnsupportedBlock = UnsupportedBlockError
|
88
89
|
BlockMissingError = MissingBlockError
|
89
90
|
NotLoadedError = FailedLoadValidationError
|
data/lib/site_prism/loadable.rb
CHANGED
@@ -36,7 +36,32 @@ module SitePrism
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def _load_validations
|
39
|
-
@_load_validations ||=
|
39
|
+
@_load_validations ||= default_validations
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_validations
|
43
|
+
if enabled?
|
44
|
+
[displayed_validation]
|
45
|
+
else
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def enabled?
|
51
|
+
siteprism_page? && SitePrism.default_load_validations
|
52
|
+
end
|
53
|
+
|
54
|
+
def siteprism_page?
|
55
|
+
self == SitePrism::Page
|
56
|
+
end
|
57
|
+
|
58
|
+
def displayed_validation
|
59
|
+
proc do
|
60
|
+
[
|
61
|
+
displayed?,
|
62
|
+
"Expected #{current_url} to match #{url_matcher} but it did not."
|
63
|
+
]
|
64
|
+
end
|
40
65
|
end
|
41
66
|
end
|
42
67
|
|
data/lib/site_prism/page.rb
CHANGED
@@ -3,19 +3,16 @@
|
|
3
3
|
require 'site_prism/loadable'
|
4
4
|
|
5
5
|
module SitePrism
|
6
|
-
# rubocop:disable Metrics/ClassLength
|
7
6
|
class Page
|
8
7
|
include Capybara::DSL
|
9
8
|
include ElementChecker
|
10
9
|
include Loadable
|
11
10
|
include ElementContainer
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
]
|
18
|
-
end
|
12
|
+
# When instantiating the page. A default validation will be added to all
|
13
|
+
# validations you define and add to the Page Class.
|
14
|
+
# When calling #load, all of the validations that are set will be ran
|
15
|
+
# in order, with the default "displayed?" validation being ran _FIRST_
|
19
16
|
|
20
17
|
def page
|
21
18
|
@page || Capybara.current_session
|
@@ -64,14 +61,6 @@ module SitePrism
|
|
64
61
|
end
|
65
62
|
end
|
66
63
|
|
67
|
-
def regexp_backed_matches
|
68
|
-
url_matcher.match(page.current_url)
|
69
|
-
end
|
70
|
-
|
71
|
-
def template_backed_matches
|
72
|
-
matcher_template.mappings(page.current_url)
|
73
|
-
end
|
74
|
-
|
75
64
|
def self.set_url(page_url)
|
76
65
|
@url = page_url.to_s
|
77
66
|
end
|
@@ -119,6 +108,14 @@ module SitePrism
|
|
119
108
|
page.has_no_selector?(*find_args)
|
120
109
|
end
|
121
110
|
|
111
|
+
def regexp_backed_matches
|
112
|
+
url_matcher.match(page.current_url)
|
113
|
+
end
|
114
|
+
|
115
|
+
def template_backed_matches
|
116
|
+
matcher_template.mappings(page.current_url)
|
117
|
+
end
|
118
|
+
|
122
119
|
def url_matches?(expected_mappings = {})
|
123
120
|
if url_matcher.is_a?(Regexp)
|
124
121
|
url_matches_by_regexp?
|
@@ -141,5 +138,4 @@ module SitePrism
|
|
141
138
|
@matcher_template ||= AddressableUrlMatcher.new(url_matcher)
|
142
139
|
end
|
143
140
|
end
|
144
|
-
# rubocop:enable Metrics/ClassLength
|
145
141
|
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: 2.
|
4
|
+
version: '2.16'
|
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: 2018-
|
12
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -31,20 +31,20 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '2.
|
34
|
+
version: '2.15'
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '3.
|
37
|
+
version: '3.6'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '2.
|
44
|
+
version: '2.15'
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.6'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: cucumber
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,14 +121,14 @@ dependencies:
|
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '3.
|
124
|
+
version: '3.5'
|
125
125
|
type: :development
|
126
126
|
prerelease: false
|
127
127
|
version_requirements: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '3.
|
131
|
+
version: '3.5'
|
132
132
|
- !ruby/object:Gem::Dependency
|
133
133
|
name: simplecov
|
134
134
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
180
|
requirements:
|
181
181
|
- - ">="
|
182
182
|
- !ruby/object:Gem::Version
|
183
|
-
version: '2.
|
183
|
+
version: '2.2'
|
184
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
186
|
- - ">="
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
191
|
+
rubygems_version: 2.7.7
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: A Page Object Model DSL for Capybara
|