site_prism 2.0 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -409,6 +409,22 @@ of seconds to wait. Using the above example:
409
409
  @home.wait_until_search_field_invisible(10)
410
410
  ```
411
411
 
412
+ #### CSS Selectors vs. XPath Expressions
413
+
414
+ While the above examples all use CSS selectors to find elements, it is
415
+ possible to use XPath expressions too. In SitePrism, everywhere that you
416
+ can use a CSS selector, you can use an XPath expression. An example:
417
+
418
+ ```ruby
419
+ class Home < SitePrism::Page
420
+ # CSS Selector:
421
+ element :first_name, "div#signup input[name='first-name']"
422
+
423
+ #same thing as an XPath expression:
424
+ element :first_name, :xpath, "//div[@id='signup']//input[@name='first-name']"
425
+ end
426
+ ```
427
+
412
428
  #### Summary of what the element method provides:
413
429
 
414
430
  Given:
@@ -1,34 +1,34 @@
1
1
  module SitePrism::ElementContainer
2
2
 
3
- def element element_name, element_selector = nil
4
- build element_name, element_selector do
3
+ def element element_name, *find_args
4
+ build element_name, *find_args do
5
5
  define_method element_name.to_s do
6
- find_first element_selector
6
+ find_first *find_args
7
7
  end
8
8
  end
9
9
  end
10
10
 
11
- def elements collection_name, collection_selector = nil
12
- build collection_name, collection_selector do
11
+ def elements collection_name, *find_args
12
+ build collection_name, *find_args do
13
13
  define_method collection_name.to_s do
14
- find_all collection_selector
14
+ find_all *find_args
15
15
  end
16
16
  end
17
17
  end
18
18
  alias :collection :elements
19
19
 
20
- def section section_name, section_class, section_selector
21
- build section_name, section_selector do
20
+ def section section_name, section_class, *find_args
21
+ build section_name, *find_args do
22
22
  define_method section_name do
23
- section_class.new find_first section_selector
23
+ section_class.new find_first *find_args
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
- def sections section_collection_name, section_class, section_collection_selector
29
- build section_collection_name, section_collection_selector do
28
+ def sections section_collection_name, section_class, *find_args
29
+ build section_collection_name, *find_args do
30
30
  define_method section_collection_name do
31
- find_all(section_collection_selector).collect do |element|
31
+ find_all(*find_args).collect do |element|
32
32
  section_class.new element
33
33
  end
34
34
  end
@@ -57,73 +57,73 @@ module SitePrism::ElementContainer
57
57
 
58
58
  private
59
59
 
60
- def build name, selector
61
- if selector.nil?
60
+ def build name, *find_args
61
+ if find_args.empty?
62
62
  create_no_selector name
63
63
  else
64
64
  add_to_mapped_items name
65
65
  yield
66
66
  end
67
- add_checkers_and_waiters name, selector
67
+ add_checkers_and_waiters name, *find_args
68
68
  end
69
69
 
70
- def add_checkers_and_waiters name, selector
71
- create_existence_checker name, selector
72
- create_waiter name, selector
73
- create_visibility_waiter name, selector
74
- create_invisibility_waiter name, selector
70
+ def add_checkers_and_waiters name, *find_args
71
+ create_existence_checker name, *find_args
72
+ create_waiter name, *find_args
73
+ create_visibility_waiter name, *find_args
74
+ create_invisibility_waiter name, *find_args
75
75
  end
76
76
 
77
- def build_checker_or_waiter element_name, proposed_method_name, selector
78
- if selector.nil?
77
+ def build_checker_or_waiter element_name, proposed_method_name, *find_args
78
+ if find_args.empty?
79
79
  create_no_selector element_name, proposed_method_name
80
80
  else
81
81
  yield
82
82
  end
83
83
  end
84
84
 
85
- def create_existence_checker element_name, element_selector
85
+ def create_existence_checker element_name, *find_args
86
86
  method_name = "has_#{element_name.to_s}?"
87
- build_checker_or_waiter element_name, method_name, element_selector do
87
+ build_checker_or_waiter element_name, method_name, *find_args do
88
88
  define_method method_name do
89
89
  Capybara.using_wait_time 0 do
90
- element_exists? element_selector
90
+ element_exists? *find_args
91
91
  end
92
92
  end
93
93
  end
94
94
  end
95
95
 
96
- def create_waiter element_name, element_selector
96
+ def create_waiter element_name, *find_args
97
97
  method_name = "wait_for_#{element_name.to_s}"
98
- build_checker_or_waiter element_name, method_name, element_selector do
98
+ build_checker_or_waiter element_name, method_name, *find_args do
99
99
  define_method method_name do |timeout = Capybara.default_wait_time|
100
100
  Capybara.using_wait_time timeout do
101
- element_exists? element_selector
101
+ element_exists? *find_args
102
102
  end
103
103
  end
104
104
  end
105
105
  end
106
106
 
107
- def create_visibility_waiter element_name, element_selector
107
+ def create_visibility_waiter element_name, *find_args
108
108
  method_name = "wait_until_#{element_name.to_s}_visible"
109
- build_checker_or_waiter element_name, method_name, element_selector do
109
+ build_checker_or_waiter element_name, method_name, *find_args do
110
110
  define_method method_name do |timeout = Capybara.default_wait_time|
111
111
  Capybara.using_wait_time timeout do
112
- element_exists? element_selector
112
+ element_exists? *find_args
113
113
  end
114
114
  Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementVisibility do
115
- sleep 0.1 until find_first(element_selector).visible?
115
+ sleep 0.1 until find_first(*find_args).visible?
116
116
  end
117
117
  end
118
118
  end
119
119
  end
120
120
 
121
- def create_invisibility_waiter element_name, element_selector
121
+ def create_invisibility_waiter element_name, *find_args
122
122
  method_name = "wait_until_#{element_name.to_s}_invisible"
123
- build_checker_or_waiter element_name, method_name, element_selector do
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
- sleep 0.1 while element_exists?(element_selector) && find_first(element_selector).visible?
126
+ sleep 0.1 while element_exists?(*find_args) && find_first(*find_args).visible?
127
127
  end
128
128
  end
129
129
  end
@@ -49,16 +49,16 @@ module SitePrism
49
49
 
50
50
  private
51
51
 
52
- def find_first selector
53
- first selector
52
+ def find_first *find_args
53
+ first *find_args
54
54
  end
55
55
 
56
- def find_all selector
57
- all selector
56
+ def find_all *find_args
57
+ all *find_args
58
58
  end
59
59
 
60
- def element_exists? selector
61
- has_selector? selector
60
+ def element_exists? *find_args
61
+ has_selector? *find_args
62
62
  end
63
63
  end
64
64
  end
@@ -24,16 +24,16 @@ module SitePrism
24
24
 
25
25
  private
26
26
 
27
- def find_first selector
28
- root_element.first selector
27
+ def find_first *find_args
28
+ root_element.first *find_args
29
29
  end
30
30
 
31
- def find_all selector
32
- root_element.all selector
31
+ def find_all *find_args
32
+ root_element.all *find_args
33
33
  end
34
34
 
35
- def element_exists? selector
36
- root_element.has_selector? selector
35
+ def element_exists? *find_args
36
+ root_element.has_selector? *find_args
37
37
  end
38
38
  end
39
39
  end
@@ -1,4 +1,4 @@
1
1
  module SitePrism
2
- VERSION = "2.0"
2
+ VERSION = "2.1"
3
3
  end
4
4
 
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.0'
4
+ version: '2.1'
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-01-15 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara