site_prism 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +91 -7
- data/lib/site_prism/element_container.rb +48 -0
- data/lib/site_prism/exceptions.rb +2 -0
- data/lib/site_prism/section.rb +4 -4
- data/lib/site_prism/version.rb +1 -1
- metadata +52 -61
data/README.md
CHANGED
@@ -318,7 +318,7 @@ end
|
|
318
318
|
... the following shows how to get hold of the search field:
|
319
319
|
|
320
320
|
```ruby
|
321
|
-
@
|
321
|
+
@home = Home.new
|
322
322
|
@home.load
|
323
323
|
|
324
324
|
@home.search_field #=> will return the capybara element found using the selector
|
@@ -342,7 +342,7 @@ end
|
|
342
342
|
... you can test for the existence of the element on the page like this:
|
343
343
|
|
344
344
|
```ruby
|
345
|
-
@
|
345
|
+
@home = Home.new
|
346
346
|
@home.load
|
347
347
|
@home.has_search_field? #=> returns true if it exists, false if it doesn't
|
348
348
|
```
|
@@ -355,9 +355,9 @@ Then /^the search field exists$/ do
|
|
355
355
|
end
|
356
356
|
```
|
357
357
|
|
358
|
-
#### Waiting for an element to
|
358
|
+
#### Waiting for an element to exist on a page
|
359
359
|
|
360
|
-
|
360
|
+
Another method added by calling `element` is the `wait_for_<element_name>` method.
|
361
361
|
Calling the method will cause the test to wait for the Capybara's
|
362
362
|
default wait time for the element to exist. It is also possible to use a
|
363
363
|
custom amount of time to wait. Using the same example as above:
|
@@ -373,13 +373,42 @@ end
|
|
373
373
|
... you can wait for the search field to exist like this:
|
374
374
|
|
375
375
|
```ruby
|
376
|
-
@
|
376
|
+
@home = Home.new
|
377
377
|
@home.load
|
378
378
|
@home.wait_for_search_field
|
379
379
|
# or...
|
380
380
|
@home.wait_for_search_field(10) #will wait for 10 seconds for the search field to appear
|
381
381
|
```
|
382
382
|
|
383
|
+
#### Waiting for an element to become visible
|
384
|
+
|
385
|
+
Another method added by calling `element` is the
|
386
|
+
`wait_until_<element_name>_visible` method. Calling this method will
|
387
|
+
cause the test to wait for Capybara's default wait time for the element
|
388
|
+
to become visible (*not* the same as existence!). You can customise the
|
389
|
+
wait time be supplying a number of seconds to wait. Using the above
|
390
|
+
example:
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
@home.wait_until_search_field_visible
|
394
|
+
# or...
|
395
|
+
@home.wait_until_search_field_visible(10)
|
396
|
+
```
|
397
|
+
|
398
|
+
#### Waiting for an element to become invisible
|
399
|
+
|
400
|
+
Another method added by calling `element` is the
|
401
|
+
`wait_until_<element_name>_invisible` method. Calling this method will
|
402
|
+
cause the test to wait for Capybara's default wait time for the element
|
403
|
+
to become invisible. You can customise the wait time be supplying a number
|
404
|
+
of seconds to wait. Using the above example:
|
405
|
+
|
406
|
+
```ruby
|
407
|
+
@home.wait_until_search_field_invisible
|
408
|
+
# or...
|
409
|
+
@home.wait_until_search_field_invisible(10)
|
410
|
+
```
|
411
|
+
|
383
412
|
#### Summary of what the element method provides:
|
384
413
|
|
385
414
|
Given:
|
@@ -397,6 +426,11 @@ end
|
|
397
426
|
@home.has_search_field?
|
398
427
|
@home.wait_for_search_field
|
399
428
|
@home.wait_for_search_field(10)
|
429
|
+
@home.wait_until_search_field_visible
|
430
|
+
@home.wait_until_search_field_visible(10)
|
431
|
+
@home.wait_until_search_field_invisible
|
432
|
+
@home.wait_until_search_field_invisible(10)
|
433
|
+
|
400
434
|
```
|
401
435
|
|
402
436
|
### Element Collections
|
@@ -445,6 +479,7 @@ arrays:
|
|
445
479
|
@friends_page.names.each {|name| puts name.text}
|
446
480
|
@friends_page.names.map {|name| name.text}.should == ["Alice", "Bob", "Fred"]
|
447
481
|
@friends_page.names.size.should == 3
|
482
|
+
@friends_page.should have(3).names
|
448
483
|
```
|
449
484
|
|
450
485
|
#### Testing for the existence of the element collection
|
@@ -503,6 +538,29 @@ to wait for:
|
|
503
538
|
@friends_page.wait_for_names(10)
|
504
539
|
```
|
505
540
|
|
541
|
+
#### Waiting for the elements to be visible or invisible
|
542
|
+
|
543
|
+
Like the individual elements, calling the `elements` method will create
|
544
|
+
two methods: `wait_until_<elements_name>_visible` and
|
545
|
+
`wait_until_<elements_name>_invisible`. Calling these methods will cause
|
546
|
+
your test to wait for the elements to become visible or invisibe. Using
|
547
|
+
the above example:
|
548
|
+
|
549
|
+
```ruby
|
550
|
+
@friends_page.wait_until_names_visible
|
551
|
+
# and...
|
552
|
+
@friends_page.wait_until_names_invisible
|
553
|
+
```
|
554
|
+
|
555
|
+
It is possible to wait for a specific amount of time instead of using
|
556
|
+
the default Capybara wait time:
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
@friends_page.wait_until_names_visible(5)
|
560
|
+
# and...
|
561
|
+
@friends_page.wait_until_names_invisible(7)
|
562
|
+
```
|
563
|
+
|
506
564
|
### Checking that all mapped elements are present on the page
|
507
565
|
|
508
566
|
Throughout my time in test automation I keep getting asked to provide the
|
@@ -711,9 +769,9 @@ Again, this allows pretty test code:
|
|
711
769
|
@home.should_not have_menu
|
712
770
|
```
|
713
771
|
|
714
|
-
#### Waiting for a section to
|
772
|
+
#### Waiting for a section to exist
|
715
773
|
|
716
|
-
|
774
|
+
Another method added to the page or section by the `section` method is
|
717
775
|
`wait_for_<section name>`. Similar to what `element` does, this method
|
718
776
|
waits for the section to appear - the test will wait up to capybara's
|
719
777
|
default wait time until the root node of the element exists on the
|
@@ -738,6 +796,32 @@ end
|
|
738
796
|
@home.wait_for_menu(10) # waits for 10 seconds instead of capybara's default timeout
|
739
797
|
```
|
740
798
|
|
799
|
+
#### Waiting for a section to become visible or invisible
|
800
|
+
|
801
|
+
Like an element, it is possible to wait for a section to become visible
|
802
|
+
or invisible. Calling the `section` method creates two methods on the
|
803
|
+
relevant page or section:
|
804
|
+
`wait_until_<section_name>_visible` and
|
805
|
+
`wait_until_<section_name>_invisible`. Using the above example, here's
|
806
|
+
how they're used:
|
807
|
+
|
808
|
+
```ruby
|
809
|
+
@home = Home.new
|
810
|
+
@home.wait_for_menu_visible
|
811
|
+
# and...
|
812
|
+
@home.wait_for_menu_invisible
|
813
|
+
```
|
814
|
+
|
815
|
+
Again, as for an element, it is possible to give a specific amount of
|
816
|
+
time to wait for visibility/invisibility of a section. Here's how:
|
817
|
+
|
818
|
+
```ruby
|
819
|
+
@home = Home.new
|
820
|
+
@home.wait_for_menu_visible(5)
|
821
|
+
# and...
|
822
|
+
@home.wait_for_menu_invisible(3)
|
823
|
+
```
|
824
|
+
|
741
825
|
#### Sections within sections
|
742
826
|
|
743
827
|
You are not limited to adding sections only to pages; you can nest
|
@@ -11,6 +11,8 @@ module SitePrism::ElementContainer
|
|
11
11
|
end
|
12
12
|
create_existence_checker element_name, element_locator
|
13
13
|
create_waiter element_name, element_locator
|
14
|
+
create_visibility_waiter element_name, element_locator
|
15
|
+
create_invisibility_waiter element_name, element_locator
|
14
16
|
end
|
15
17
|
|
16
18
|
def elements collection_name, collection_locator = nil
|
@@ -24,6 +26,8 @@ module SitePrism::ElementContainer
|
|
24
26
|
end
|
25
27
|
create_existence_checker collection_name, collection_locator
|
26
28
|
create_waiter collection_name, collection_locator
|
29
|
+
create_visibility_waiter collection_name, collection_locator
|
30
|
+
create_invisibility_waiter collection_name, collection_locator
|
27
31
|
end
|
28
32
|
alias :collection :elements
|
29
33
|
|
@@ -31,6 +35,8 @@ module SitePrism::ElementContainer
|
|
31
35
|
add_element_name section_name
|
32
36
|
create_existence_checker section_name, section_locator
|
33
37
|
create_waiter section_name, section_locator
|
38
|
+
create_visibility_waiter section_name, section_locator
|
39
|
+
create_invisibility_waiter section_name, section_locator
|
34
40
|
define_method section_name do
|
35
41
|
section_class.new find_one section_locator
|
36
42
|
end
|
@@ -40,6 +46,8 @@ module SitePrism::ElementContainer
|
|
40
46
|
add_element_name section_collection_name
|
41
47
|
create_existence_checker section_collection_name, section_collection_locator
|
42
48
|
create_waiter section_collection_name, section_collection_locator
|
49
|
+
create_visibility_waiter section_collection_name, section_collection_locator
|
50
|
+
create_invisibility_waiter section_collection_name, section_collection_locator
|
43
51
|
define_method section_collection_name do
|
44
52
|
find_all(section_collection_locator).collect do |element|
|
45
53
|
section_class.new element
|
@@ -96,6 +104,46 @@ module SitePrism::ElementContainer
|
|
96
104
|
end
|
97
105
|
end
|
98
106
|
|
107
|
+
def create_visibility_waiter element_name, element_locator
|
108
|
+
method_name = "wait_until_#{element_name.to_s}_visible"
|
109
|
+
if element_locator.nil?
|
110
|
+
create_no_locator element_name, method_name
|
111
|
+
else
|
112
|
+
define_method method_name do |*args|
|
113
|
+
timeout = args.shift || Capybara.default_wait_time
|
114
|
+
Capybara.using_wait_time timeout do
|
115
|
+
element_waiter element_locator
|
116
|
+
end
|
117
|
+
begin
|
118
|
+
Timeout.timeout(timeout) do
|
119
|
+
sleep 0.1 until find_one(element_locator).visible?
|
120
|
+
end
|
121
|
+
rescue Timeout::Error
|
122
|
+
raise SitePrism::TimeOutWaitingForElementVisibility.new("#{element_name} did not become visible")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_invisibility_waiter element_name, element_locator
|
129
|
+
method_name = "wait_until_#{element_name.to_s}_invisible"
|
130
|
+
if element_locator.nil?
|
131
|
+
create_no_locator element_name, method_name
|
132
|
+
else
|
133
|
+
define_method method_name do |*args|
|
134
|
+
timeout = args.shift || Capybara.default_wait_time
|
135
|
+
begin
|
136
|
+
Timeout.timeout(timeout) do
|
137
|
+
sleep 0.1 while element_exists?(element_locator) && find_one(element_locator).visible?
|
138
|
+
end
|
139
|
+
rescue Timeout::Error
|
140
|
+
raise SitePrism::TimeOutWaitingForElementInvisibility.new("#{element_name} did not become invisible")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
99
147
|
def create_no_locator element_name, method_name = nil
|
100
148
|
no_locator_method_name = method_name.nil? ? element_name : method_name
|
101
149
|
define_method no_locator_method_name do
|
@@ -2,5 +2,7 @@ module SitePrism
|
|
2
2
|
class NoUrlForPage < StandardError; end
|
3
3
|
class NoUrlMatcherForPage < StandardError; end
|
4
4
|
class NoLocatorForElement < StandardError; end
|
5
|
+
class TimeOutWaitingForElementVisibility < StandardError; end
|
6
|
+
class TimeOutWaitingForElementInvisibility < StandardError; end
|
5
7
|
end
|
6
8
|
|
data/lib/site_prism/section.rb
CHANGED
@@ -11,7 +11,7 @@ module SitePrism
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def visible?
|
14
|
-
|
14
|
+
root_element.visible?
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute_script input
|
@@ -25,15 +25,15 @@ module SitePrism
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def find_one locator
|
28
|
-
|
28
|
+
root_element.find locator
|
29
29
|
end
|
30
30
|
|
31
31
|
def find_all locator
|
32
|
-
|
32
|
+
root_element.all locator
|
33
33
|
end
|
34
34
|
|
35
35
|
def element_exists? locator
|
36
|
-
|
36
|
+
root_element.has_selector? locator
|
37
37
|
end
|
38
38
|
|
39
39
|
def element_waiter locator
|
data/lib/site_prism/version.rb
CHANGED
metadata
CHANGED
@@ -1,59 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_prism
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 2
|
8
|
-
version: "1.2"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.3'
|
5
|
+
prerelease:
|
9
6
|
platform: ruby
|
10
|
-
authors:
|
7
|
+
authors:
|
11
8
|
- Nat Ritmeyer
|
12
9
|
autorequire:
|
13
10
|
bindir: bin
|
14
11
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
dependencies:
|
19
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
20
15
|
name: capybara
|
21
|
-
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
segments:
|
27
|
-
- 1
|
28
|
-
- 1
|
29
|
-
- 1
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
30
21
|
version: 1.1.1
|
31
22
|
type: :runtime
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rspec
|
35
23
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
44
37
|
version: 2.0.0
|
45
38
|
type: :runtime
|
46
|
-
|
47
|
-
|
48
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.0
|
46
|
+
description: SitePrism gives you a simple, clean and semantic DSL for describing your
|
47
|
+
site using the Page Object Model pattern, for use with Capybara
|
48
|
+
email:
|
49
49
|
- nat@natontesting.com
|
50
50
|
executables: []
|
51
|
-
|
52
51
|
extensions: []
|
53
|
-
|
54
52
|
extra_rdoc_files: []
|
55
|
-
|
56
|
-
files:
|
53
|
+
files:
|
57
54
|
- lib/site_prism/element_checker.rb
|
58
55
|
- lib/site_prism/element_container.rb
|
59
56
|
- lib/site_prism/exceptions.rb
|
@@ -63,35 +60,29 @@ files:
|
|
63
60
|
- lib/site_prism.rb
|
64
61
|
- LICENSE
|
65
62
|
- README.md
|
66
|
-
has_rdoc: true
|
67
63
|
homepage: http://github.com/natritmeyer/site_prism
|
68
64
|
licenses: []
|
69
|
-
|
70
65
|
post_install_message:
|
71
66
|
rdoc_options: []
|
72
|
-
|
73
|
-
require_paths:
|
67
|
+
require_paths:
|
74
68
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
- 0
|
88
|
-
version: "0"
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
89
81
|
requirements: []
|
90
|
-
|
91
82
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.8.24
|
93
84
|
signing_key:
|
94
85
|
specification_version: 3
|
95
86
|
summary: A Page Object Model DSL for Capybara
|
96
87
|
test_files: []
|
97
|
-
|
88
|
+
has_rdoc:
|