site_prism 2.3 → 2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,6 +29,10 @@ class SearchResults < SitePrism::Page
29
29
 
30
30
  section :menu, MenuSection, "#gbx3"
31
31
  sections :search_results, SearchResultSection, "#results li"
32
+
33
+ def search_result_links
34
+ search_results.map {|sr| sr.title['href']}
35
+ end
32
36
  end
33
37
 
34
38
  # define sections used on multiple pages or multiple times on one page
@@ -75,7 +79,7 @@ Then /^the search results page contains 10 individual search results$/ do
75
79
  end
76
80
 
77
81
  Then /^the search results contain a link to the wikipedia sausages page$/ do
78
- @results_page.search_results.map {|sr| sr.title['href']}.should include "http://en.wikipedia.org/wiki/Sausage"
82
+ @results_page.search_result_links.should include "http://en.wikipedia.org/wiki/Sausage"
79
83
  end
80
84
  ```
81
85
 
@@ -414,6 +418,26 @@ Then /^the search field exists$/ do
414
418
  end
415
419
  ```
416
420
 
421
+ #### Testing that an element does not exist
422
+
423
+ To test that an element does not exist on the page, it is not possible to just call
424
+ `#should_not have_search_field`. SitePrism supplies the `#has_no_<element>?` method
425
+ that should be used to test for non-existence. Using the above example:
426
+
427
+ ```ruby
428
+ @home = Home.new
429
+ @home.load
430
+ @home.has_no_search_field? #=> returns true if it doesn't exist, false if it does
431
+ ```
432
+
433
+ ...which makes for nice test code:
434
+
435
+ ```ruby
436
+ Then /^the search field exists$/ do
437
+ @home.should have_no_search_field #NB: NOT => @home.should_not_ have_search_field
438
+ end
439
+ ```
440
+
417
441
  #### Waiting for an element to exist on a page
418
442
 
419
443
  Another method added by calling `element` is the `wait_for_<element_name>` method.
@@ -499,6 +523,7 @@ end
499
523
  ```ruby
500
524
  @home.search_field
501
525
  @home.has_search_field?
526
+ @home.has_no_search_field?
502
527
  @home.wait_for_search_field
503
528
  @home.wait_for_search_field(10)
504
529
  @home.wait_until_search_field_visible
@@ -1269,7 +1294,7 @@ class App
1269
1294
  end
1270
1295
 
1271
1296
  def results_page
1272
- SearchResults.new
1297
+ SearchResults.new
1273
1298
  end
1274
1299
 
1275
1300
  def maps
@@ -1290,6 +1315,10 @@ When /^I search for Sausages$/ do
1290
1315
  @app.home.search_button.click
1291
1316
  end
1292
1317
 
1318
+ Then /^I am on the results page$/ do
1319
+ @app.results_page.should be_displayed
1320
+ end
1321
+
1293
1322
  # etc...
1294
1323
  ```
1295
1324
 
@@ -38,6 +38,7 @@ module SitePrism::ElementContainer
38
38
  def iframe(iframe_name, iframe_page_class, iframe_id)
39
39
  add_to_mapped_items iframe_name
40
40
  create_existence_checker iframe_name, iframe_id
41
+ create_nonexistence_checker iframe_name, iframe_id
41
42
  create_waiter iframe_name, iframe_id
42
43
  define_method iframe_name do |&block|
43
44
  within_frame iframe_id.split("#").last do
@@ -69,6 +70,7 @@ module SitePrism::ElementContainer
69
70
 
70
71
  def add_helper_methods(name, *find_args)
71
72
  create_existence_checker name, *find_args
73
+ create_nonexistence_checker name, *find_args
72
74
  create_waiter name, *find_args
73
75
  create_visibility_waiter name, *find_args
74
76
  create_invisibility_waiter name, *find_args
@@ -93,13 +95,24 @@ module SitePrism::ElementContainer
93
95
  end
94
96
  end
95
97
 
98
+ def create_nonexistence_checker(element_name, *find_args)
99
+ method_name = "has_no_#{element_name.to_s}?"
100
+ create_helper_method method_name, *find_args do
101
+ define_method method_name do
102
+ Capybara.using_wait_time 0 do
103
+ element_does_not_exist? *find_args
104
+ end
105
+ end
106
+ end
107
+ end
108
+
96
109
  def create_waiter(element_name, *find_args)
97
110
  method_name = "wait_for_#{element_name.to_s}"
98
111
  create_helper_method method_name, *find_args do
99
112
  define_method method_name do |timeout = Capybara.default_wait_time|
100
- Capybara.using_wait_time timeout do
101
- element_exists? *find_args
102
- end
113
+ Capybara.using_wait_time timeout do
114
+ element_exists? *find_args
115
+ end
103
116
  end
104
117
  end
105
118
  end
@@ -108,13 +121,12 @@ module SitePrism::ElementContainer
108
121
  method_name = "wait_until_#{element_name.to_s}_visible"
109
122
  create_helper_method method_name, *find_args do
110
123
  define_method method_name do |timeout = Capybara.default_wait_time|
111
- Capybara.using_wait_time timeout do
112
- element_exists? *find_args
113
- end
114
- Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementVisibility do
115
- sleep 0.1 until find_first(*find_args).visible?
124
+ Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementVisibility do
125
+ Capybara.using_wait_time 0 do
126
+ sleep 0.05 while not element_exists? *find_args, visible: true
116
127
  end
117
128
  end
129
+ end
118
130
  end
119
131
  end
120
132
 
@@ -122,12 +134,12 @@ module SitePrism::ElementContainer
122
134
  method_name = "wait_until_#{element_name.to_s}_invisible"
123
135
  create_helper_method method_name, *find_args do
124
136
  define_method method_name do |timeout = Capybara.default_wait_time|
125
- Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementInvisibility do
126
- Capybara.using_wait_time 0 do
127
- sleep 0.05 while element_exists?(*find_args) && find_first(*find_args).visible?
128
- end
137
+ Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementInvisibility do
138
+ Capybara.using_wait_time 0 do
139
+ sleep 0.05 while element_exists? *find_args, visible: true
129
140
  end
130
141
  end
142
+ end
131
143
  end
132
144
  end
133
145
 
@@ -44,15 +44,10 @@ module SitePrism
44
44
  !current_url.match(/^https/).nil?
45
45
  end
46
46
 
47
- def title
48
- title_selector = 'html > head > title'
49
- using_wait_time(0) { page.find(title_selector).text if page.has_selector?(title_selector) }
50
- end
51
-
52
47
  private
53
48
 
54
49
  def find_first *find_args
55
- first *find_args
50
+ find *find_args
56
51
  end
57
52
 
58
53
  def find_all *find_args
@@ -62,6 +57,10 @@ module SitePrism
62
57
  def element_exists? *find_args
63
58
  has_selector? *find_args
64
59
  end
60
+
61
+ def element_does_not_exist? *find_args
62
+ has_no_selector? *find_args
63
+ end
65
64
  end
66
65
  end
67
66
 
@@ -33,7 +33,7 @@ module SitePrism
33
33
  private
34
34
 
35
35
  def find_first *find_args
36
- root_element.first *find_args
36
+ root_element.find *find_args
37
37
  end
38
38
 
39
39
  def find_all *find_args
@@ -45,6 +45,12 @@ module SitePrism
45
45
  root_element.has_selector? *find_args
46
46
  end
47
47
  end
48
+
49
+ def element_does_not_exist? *find_args
50
+ unless root_element.nil?
51
+ root_element.has_no_selector? *find_args
52
+ end
53
+ end
48
54
  end
49
55
  end
50
56
 
@@ -1,4 +1,4 @@
1
1
  module SitePrism
2
- VERSION = "2.3"
2
+ VERSION = "2.4"
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.3'
4
+ version: '2.4'
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-04-05 00:00:00.000000000 Z
12
+ date: 2013-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.0.2
21
+ version: '2.1'
22
22
  - - <
23
23
  - !ruby/object:Gem::Version
24
24
  version: '3.0'
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 2.0.2
32
+ version: '2.1'
33
33
  - - <
34
34
  - !ruby/object:Gem::Version
35
35
  version: '3.0'
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 1.8.25
104
+ rubygems_version: 1.8.23
105
105
  signing_key:
106
106
  specification_version: 3
107
107
  summary: A Page Object Model DSL for Capybara