site_prism 2.1 → 2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +56 -0
- data/lib/site_prism/element_container.rb +9 -7
- data/lib/site_prism/section.rb +14 -4
- data/lib/site_prism/version.rb +1 -1
- metadata +4 -5
data/README.md
CHANGED
@@ -5,6 +5,8 @@ SitePrism gives you a simple, clean and semantic DSL for describing your site us
|
|
5
5
|
|
6
6
|
Find the pretty documentation here: http://rdoc.info/gems/site_prism/frames
|
7
7
|
|
8
|
+
[![Build Status](https://travis-ci.org/natritmeyer/site_prism.png)](https://travis-ci.org/natritmeyer/site_prism)
|
9
|
+
|
8
10
|
## Synopsis
|
9
11
|
|
10
12
|
Here's an overview of how SitePrism is designed to be used:
|
@@ -751,6 +753,60 @@ Then /^the home page menu contains a link to the various search functions$/ do
|
|
751
753
|
end
|
752
754
|
```
|
753
755
|
|
756
|
+
#### Getting a section's parent
|
757
|
+
|
758
|
+
It is possible to ask a section for its parent (page, or section if this
|
759
|
+
section is a subsection). For example, given the following setup:
|
760
|
+
|
761
|
+
```ruby
|
762
|
+
class MySubSection < SitePrism::Section
|
763
|
+
element :some_element, "abc"
|
764
|
+
end
|
765
|
+
|
766
|
+
class MySection < SitePrism::Section
|
767
|
+
section :my_subsection, MySubSection, "def"
|
768
|
+
end
|
769
|
+
|
770
|
+
class MyPage < SitePrism::Page
|
771
|
+
section :my_section, MySection, "ghi"
|
772
|
+
end
|
773
|
+
```
|
774
|
+
|
775
|
+
...then calling `#parent` will return the following:
|
776
|
+
|
777
|
+
```ruby
|
778
|
+
@my_page = MyPage.new
|
779
|
+
@my_page.load
|
780
|
+
|
781
|
+
@my_page.my_section.parent #=> returns @my_page
|
782
|
+
@my_page.my_section.my_subsection.parent #=> returns @my_section
|
783
|
+
```
|
784
|
+
|
785
|
+
#### Getting a section's parent page
|
786
|
+
|
787
|
+
It is possible to ask a section for the page that it belongs to. For example,
|
788
|
+
given the following setup:
|
789
|
+
|
790
|
+
```ruby
|
791
|
+
class MenuSection < SitePrism::Section
|
792
|
+
element :search, "a.search"
|
793
|
+
element :images, "a.image-search"
|
794
|
+
element :maps, "a.map-search"
|
795
|
+
end
|
796
|
+
|
797
|
+
class Home < SitePrism::Page
|
798
|
+
section :menu, MenuSection, "#gbx3"
|
799
|
+
end
|
800
|
+
```
|
801
|
+
|
802
|
+
...you can get the section's parent page:
|
803
|
+
|
804
|
+
```ruby
|
805
|
+
@home = Home.new
|
806
|
+
@home.load
|
807
|
+
@home.menu.parent_page #=> returns @home
|
808
|
+
```
|
809
|
+
|
754
810
|
#### Testing for the existence of a section
|
755
811
|
|
756
812
|
Just like elements, it is possible to test for the existence of a
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SitePrism::ElementContainer
|
2
2
|
|
3
|
-
def element element_name, *find_args
|
3
|
+
def element element_name, *find_args
|
4
4
|
build element_name, *find_args do
|
5
5
|
define_method element_name.to_s do
|
6
6
|
find_first *find_args
|
@@ -20,7 +20,7 @@ module SitePrism::ElementContainer
|
|
20
20
|
def section section_name, section_class, *find_args
|
21
21
|
build section_name, *find_args do
|
22
22
|
define_method section_name do
|
23
|
-
section_class.new find_first
|
23
|
+
section_class.new self, find_first(*find_args)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -29,7 +29,7 @@ module SitePrism::ElementContainer
|
|
29
29
|
build section_collection_name, *find_args do
|
30
30
|
define_method section_collection_name do
|
31
31
|
find_all(*find_args).collect do |element|
|
32
|
-
section_class.new element
|
32
|
+
section_class.new self, element
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -56,7 +56,7 @@ module SitePrism::ElementContainer
|
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
59
|
-
|
59
|
+
|
60
60
|
def build name, *find_args
|
61
61
|
if find_args.empty?
|
62
62
|
create_no_selector name
|
@@ -66,14 +66,14 @@ module SitePrism::ElementContainer
|
|
66
66
|
end
|
67
67
|
add_checkers_and_waiters name, *find_args
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def add_checkers_and_waiters name, *find_args
|
71
71
|
create_existence_checker name, *find_args
|
72
72
|
create_waiter name, *find_args
|
73
73
|
create_visibility_waiter name, *find_args
|
74
74
|
create_invisibility_waiter name, *find_args
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def build_checker_or_waiter element_name, proposed_method_name, *find_args
|
78
78
|
if find_args.empty?
|
79
79
|
create_no_selector element_name, proposed_method_name
|
@@ -123,7 +123,9 @@ module SitePrism::ElementContainer
|
|
123
123
|
build_checker_or_waiter element_name, method_name, *find_args do
|
124
124
|
define_method method_name do |timeout = Capybara.default_wait_time|
|
125
125
|
Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementInvisibility do
|
126
|
-
|
126
|
+
Capybara.using_wait_time 0 do
|
127
|
+
sleep 0.05 while element_exists?(*find_args) && find_first(*find_args).visible?
|
128
|
+
end
|
127
129
|
end
|
128
130
|
end
|
129
131
|
end
|
data/lib/site_prism/section.rb
CHANGED
@@ -4,10 +4,10 @@ module SitePrism
|
|
4
4
|
include ElementChecker
|
5
5
|
extend ElementContainer
|
6
6
|
|
7
|
-
attr_reader :root_element
|
7
|
+
attr_reader :root_element, :parent
|
8
8
|
|
9
|
-
def initialize root_element
|
10
|
-
@root_element = root_element
|
9
|
+
def initialize parent, root_element
|
10
|
+
@parent, @root_element = parent, root_element
|
11
11
|
end
|
12
12
|
|
13
13
|
def visible?
|
@@ -22,6 +22,14 @@ module SitePrism
|
|
22
22
|
Capybara.current_session.evaluate_script input
|
23
23
|
end
|
24
24
|
|
25
|
+
def parent_page
|
26
|
+
candidate_page = self.parent
|
27
|
+
until candidate_page.is_a?(SitePrism::Page)
|
28
|
+
candidate_page = candidate_page.parent
|
29
|
+
end
|
30
|
+
candidate_page
|
31
|
+
end
|
32
|
+
|
25
33
|
private
|
26
34
|
|
27
35
|
def find_first *find_args
|
@@ -33,7 +41,9 @@ module SitePrism
|
|
33
41
|
end
|
34
42
|
|
35
43
|
def element_exists? *find_args
|
36
|
-
root_element.
|
44
|
+
unless root_element.nil?
|
45
|
+
root_element.has_selector? *find_args
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
39
49
|
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.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|
@@ -51,8 +51,7 @@ dependencies:
|
|
51
51
|
version: '2.0'
|
52
52
|
description: SitePrism gives you a simple, clean and semantic DSL for describing your
|
53
53
|
site using the Page Object Model pattern, for use with Capybara
|
54
|
-
email:
|
55
|
-
- nat@natontesting.com
|
54
|
+
email: nat@natontesting.com
|
56
55
|
executables: []
|
57
56
|
extensions: []
|
58
57
|
extra_rdoc_files: []
|
@@ -77,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
76
|
requirements:
|
78
77
|
- - ! '>='
|
79
78
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
79
|
+
version: 1.9.3
|
81
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
81
|
none: false
|
83
82
|
requirements:
|