site_prism 0.9.3 → 0.9.4
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.
- data/LICENSE +2 -1
- data/lib/site_prism.rb +4 -2
- data/lib/site_prism/element_checker.rb +6 -0
- data/lib/site_prism/element_container.rb +19 -14
- data/lib/site_prism/exceptions.rb +2 -1
- data/lib/site_prism/page.rb +27 -16
- data/lib/site_prism/section.rb +16 -5
- metadata +3 -2
data/LICENSE
CHANGED
@@ -25,4 +25,5 @@ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
25
25
|
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
26
26
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
27
27
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
28
|
-
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
data/lib/site_prism.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Contains methods applicable to both {SitePrism::Page}s and {SitePrism::Section}s. Note that they are mixed into the {SitePrism::Page}
|
2
2
|
# and {SitePrism::Section} classes so the methods below are used as class methods.
|
3
3
|
module SitePrism::ElementContainer
|
4
|
-
|
4
|
+
|
5
5
|
# Creates two methods; the first method has the same name as the element_name parameter and returns the capybara element
|
6
6
|
# located by the element_locator parameter when the method is called. The second method generated has a name with a format
|
7
7
|
# of: 'has_#\{element_name}?' which returns true if the element as located by the element_locator parameter exists, false
|
@@ -13,22 +13,23 @@ module SitePrism::ElementContainer
|
|
13
13
|
# element :search_link, 'div.search > a'
|
14
14
|
# end
|
15
15
|
# home = HomePage.new
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# #the element method created 2 methods...
|
18
18
|
# home.search_link #=> returns the capybara element located by the element_locator parameter
|
19
19
|
# home.has_search_link? #=> returns true if the capybara element as located by the element_locator exists, false if it doesn't
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# #The has_search_link? method allows use of magic matchers in rspec/cucumber:
|
22
22
|
# home.should have_search_link
|
23
23
|
# home.should_not have_search_link
|
24
24
|
def element element_name, element_locator
|
25
|
+
add_element_name element_name
|
25
26
|
create_existence_checker element_name, element_locator
|
26
27
|
create_waiter element_name, element_locator
|
27
28
|
define_method element_name.to_s do
|
28
29
|
find_one element_locator
|
29
30
|
end
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
# Works in the same way as {SitePrism::Page.element} in that it will generate two methods; one to check existence of
|
33
34
|
# the element (in the format 'has_#\{element_name}?'), and another to return not a single element, but an array of elements
|
34
35
|
# found by the css locator
|
@@ -39,11 +40,12 @@ module SitePrism::ElementContainer
|
|
39
40
|
# elements :app_links, '.title-links > a'
|
40
41
|
# end
|
41
42
|
# home = HomePage.new
|
42
|
-
#
|
43
|
+
#
|
43
44
|
# home.should have_app_links
|
44
45
|
# home.app_links #=> [#<Capybara::Element tag="a">, #<Capybara::Element tag="a">, #<Capybara::Element tag="a">]
|
45
46
|
# home.app_links.map {|link| link.text}.should == ['Finance', 'Maps', 'Blogs']
|
46
47
|
def elements collection_name, collection_locator
|
48
|
+
add_element_name collection_name
|
47
49
|
create_existence_checker collection_name, collection_locator
|
48
50
|
create_waiter collection_name, collection_locator
|
49
51
|
define_method collection_name.to_s do
|
@@ -61,32 +63,34 @@ module SitePrism::ElementContainer
|
|
61
63
|
# element :search_field, '.q'
|
62
64
|
# element :search_button, '.btnK'
|
63
65
|
# end
|
64
|
-
#
|
66
|
+
#
|
65
67
|
# ...then that section could be added to any page as follows:
|
66
|
-
#
|
68
|
+
#
|
67
69
|
# class SearchPage < SitePrism::Page
|
68
70
|
# section :search_area, SearchArea, '.tsf-p'
|
69
71
|
# end
|
70
|
-
#
|
72
|
+
#
|
71
73
|
# class SearchResultsPage < SitePrism::Page
|
72
74
|
# section :search_again, SearchArea, '.tsf-p table'
|
73
75
|
# end
|
74
|
-
#
|
76
|
+
#
|
75
77
|
# The SearchArea section appears on both pages, but can be invoked by methods specific to the page (eg: 'search_area' and 'search_again')
|
76
78
|
# and the root element for the section can be different on the page (eg: '.tsf-p' and '.tsf-p table').
|
77
79
|
# @param [Symbol] the method name to be called against this page or section to return an instance of the {SitePrism::Section} class
|
78
80
|
# @param [Class] the class that models this area of the page
|
79
81
|
# @param [String] the CSS locator for the root element of the section on this page/section
|
80
82
|
def section section_name, section_class, section_locator
|
83
|
+
add_element_name section_name
|
81
84
|
create_existence_checker section_name, section_locator
|
82
85
|
create_waiter section_name, section_locator
|
83
86
|
define_method section_name do
|
84
87
|
section_class.new find_one section_locator
|
85
88
|
end
|
86
89
|
end
|
87
|
-
|
90
|
+
|
88
91
|
# Works in the same way as {SitePrism::Page.section} but instead of it returning one section, it returns an array of them.
|
89
92
|
def sections section_collection_name, section_class, section_collection_locator
|
93
|
+
add_element_name section_collection_name
|
90
94
|
create_existence_checker section_collection_name, section_collection_locator
|
91
95
|
create_waiter section_collection_name, section_collection_locator
|
92
96
|
define_method section_collection_name do
|
@@ -95,9 +99,9 @@ module SitePrism::ElementContainer
|
|
95
99
|
end
|
96
100
|
end
|
97
101
|
end
|
98
|
-
|
102
|
+
|
99
103
|
private
|
100
|
-
|
104
|
+
|
101
105
|
# Creates a method used to check for the existence of the element whose details are passed to it
|
102
106
|
# @param
|
103
107
|
def create_existence_checker element_name, element_locator
|
@@ -105,11 +109,12 @@ module SitePrism::ElementContainer
|
|
105
109
|
element_exists? element_locator
|
106
110
|
end
|
107
111
|
end
|
108
|
-
|
112
|
+
|
109
113
|
# Creates a method used to wait for an element to appear - uses the default capybara wait time
|
110
114
|
def create_waiter element_name, element_locator
|
111
115
|
define_method "wait_for_#{element_name.to_s}" do
|
112
116
|
element_waiter element_locator
|
113
117
|
end
|
114
118
|
end
|
115
|
-
end
|
119
|
+
end
|
120
|
+
|
data/lib/site_prism/page.rb
CHANGED
@@ -2,7 +2,7 @@ module SitePrism
|
|
2
2
|
# Subclasses of {SitePrism::Page} represent pages in your app.
|
3
3
|
# class Home < SitePrism::Page
|
4
4
|
# end
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# The above is an example of how to make a class representing the home page. There are a number of properties that can be
|
7
7
|
# set on a page - here is an example of a more fully spec'ed out page:
|
8
8
|
# class Home < SitePrism::Page
|
@@ -11,15 +11,16 @@ module SitePrism
|
|
11
11
|
# end
|
12
12
|
class Page
|
13
13
|
include Capybara::DSL
|
14
|
+
include ElementChecker
|
14
15
|
extend ElementContainer
|
15
|
-
|
16
|
+
|
16
17
|
# Visits the url associated with this page
|
17
18
|
# @raise [SitePrism::NoUrlForPage] To load a page the url must be set using {.set_url}
|
18
19
|
def load
|
19
20
|
raise SitePrism::NoUrlForPage if url.nil?
|
20
21
|
visit url
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
# Checks to see if we're on this page or not
|
24
25
|
# @return true if the browser's current url matches the {.url_matcher} that has been set, false if it doesn't
|
25
26
|
# @raise [SitePrism::NoUrlMatcherForPage] To check whether we're on this page or not the url matcher must be set using {.set_url_matcher}
|
@@ -35,7 +36,7 @@ module SitePrism
|
|
35
36
|
raise SitePrism::NoUrlMatcherForPage if url_matcher.nil?
|
36
37
|
!(page.current_url =~ url_matcher).nil?
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
# Set the url associated with this page
|
40
41
|
# @param [String] page_url the portion of the url that identifies this page when appended onto Capybara's app_host. Calling {SitePrism::Page#load} causes Capybara to visit this page.
|
41
42
|
# @example
|
@@ -45,7 +46,7 @@ module SitePrism
|
|
45
46
|
def self.set_url page_url
|
46
47
|
@url = page_url
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
# Set the url matcher associated with this page
|
50
51
|
# @param [Regexp] page_url_matcher a regular expression that when compared to the current browser url will match if we're on this page or not match if we're not on this page
|
51
52
|
# @example
|
@@ -55,60 +56,70 @@ module SitePrism
|
|
55
56
|
def self.set_url_matcher page_url_matcher
|
56
57
|
@url_matcher = page_url_matcher
|
57
58
|
end
|
58
|
-
|
59
|
+
|
59
60
|
# Get the url associated with this page
|
60
61
|
# @see SitePrism::Page#url
|
61
62
|
# @return [String] the url originally set in {.set_url}
|
62
63
|
def self.url
|
63
64
|
@url
|
64
65
|
end
|
65
|
-
|
66
|
+
|
66
67
|
# Get the url matcher associated with this page
|
67
68
|
# @see SitePrism::Page#url_matcher
|
68
69
|
# @return [Regexp] the url matcher originally set in {.set_url_matcher}
|
69
70
|
def self.url_matcher
|
70
71
|
@url_matcher
|
71
72
|
end
|
72
|
-
|
73
|
+
|
73
74
|
# Get the url associated with this page
|
74
75
|
# @see SitePrism::Page.url
|
75
76
|
def url
|
76
77
|
self.class.url
|
77
78
|
end
|
78
|
-
|
79
|
+
|
79
80
|
# Get the url matcher associated with this page
|
80
81
|
# @see SitePrism::Page.url_matcher
|
81
82
|
def url_matcher
|
82
83
|
self.class.url_matcher
|
83
84
|
end
|
84
|
-
|
85
|
+
|
85
86
|
# Gets the title of the current page
|
86
87
|
# @return [String, nil] the text value of the title element within the page's head block
|
87
88
|
def title
|
88
89
|
title_selector = 'html > head > title'
|
89
90
|
using_wait_time(0) { page.find(title_selector).text if page.has_selector?(title_selector) }
|
90
91
|
end
|
91
|
-
|
92
|
+
|
92
93
|
private
|
93
|
-
|
94
|
+
|
94
95
|
# Page specific element finder
|
95
96
|
def find_one locator
|
96
97
|
find locator
|
97
98
|
end
|
98
|
-
|
99
|
+
|
99
100
|
# Page specific elements finder
|
100
101
|
def find_all locator
|
101
102
|
all locator
|
102
103
|
end
|
103
|
-
|
104
|
+
|
104
105
|
# Page specific element existence check
|
105
106
|
def element_exists? locator
|
106
107
|
has_selector? locator
|
107
108
|
end
|
108
|
-
|
109
|
+
|
109
110
|
# Page specific element waiter
|
110
111
|
def element_waiter locator
|
111
112
|
wait_until { element_exists? locator }
|
112
113
|
end
|
114
|
+
|
115
|
+
def self.add_element_name element_name
|
116
|
+
@element_names ||= []
|
117
|
+
@element_names << element_name
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.element_names
|
121
|
+
@element_names
|
122
|
+
end
|
113
123
|
end
|
114
|
-
end
|
124
|
+
end
|
125
|
+
|
data/lib/site_prism/section.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module SitePrism
|
2
2
|
class Section
|
3
|
+
include ElementChecker
|
3
4
|
extend ElementContainer
|
4
|
-
|
5
|
+
|
5
6
|
attr_reader :root_element
|
6
|
-
|
7
|
+
|
7
8
|
def initialize root_element
|
8
9
|
@root_element = root_element
|
9
10
|
end
|
@@ -11,14 +12,14 @@ module SitePrism
|
|
11
12
|
def visible?
|
12
13
|
@root_element.visible?
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
private
|
16
|
-
|
17
|
+
|
17
18
|
# Section specific element finder
|
18
19
|
def find_one locator
|
19
20
|
@root_element.find locator
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
# Section specific elements finder
|
23
24
|
def find_all locator
|
24
25
|
@root_element.all locator
|
@@ -33,5 +34,15 @@ module SitePrism
|
|
33
34
|
def element_waiter locator
|
34
35
|
wait_until { element_exists? locator }
|
35
36
|
end
|
37
|
+
|
38
|
+
def self.add_element_name element_name
|
39
|
+
@element_names ||= []
|
40
|
+
@element_names << element_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.element_names
|
44
|
+
@element_names
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
48
|
+
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: site_prism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nat Ritmeyer
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-03-01 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: capybara
|
@@ -44,6 +44,7 @@ extensions: []
|
|
44
44
|
extra_rdoc_files: []
|
45
45
|
|
46
46
|
files:
|
47
|
+
- lib/site_prism/element_checker.rb
|
47
48
|
- lib/site_prism/element_container.rb
|
48
49
|
- lib/site_prism/exceptions.rb
|
49
50
|
- lib/site_prism/page.rb
|