page_object_wrapper 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,18 @@ PageObjectWrapper.define_page('some_page_with_lost_of_errors') do
27
27
  action('','a string') do
28
28
  end
29
29
 
30
+ text_field :dublicate_tf do
31
+ label_alias :dublicate_tf
32
+ end
33
+
34
+ text_field :another_dublicate_tf do
35
+ label_alias 'not a symbol'
36
+ end
37
+
38
+ textarea :area do
39
+ label_alias :another_dublicate_tf
40
+ end
41
+
30
42
  validator('') do
31
43
  end
32
44
 
@@ -34,6 +46,7 @@ PageObjectWrapper.define_page('some_page_with_lost_of_errors') do
34
46
 
35
47
  table('') do
36
48
  end
49
+
37
50
  table(:some_table) do
38
51
  header []
39
52
  end
@@ -43,3 +56,6 @@ PageObjectWrapper.define_page('some_page_with_lost_of_errors') do
43
56
  end
44
57
  end
45
58
 
59
+ #PageObjectWrapper.define_page :dublicate_label do
60
+ # label_alias :dublicate_label
61
+ #end
@@ -0,0 +1,70 @@
1
+ PageObjectWrapper.define_page(:page_with_aliases) do
2
+ locator 'file://'+Dir.pwd+'/good_pages/some_test_page.html'
3
+ uniq_h1 :text => 'Testing display of HTML elements'
4
+ label_alias :page_name_alias
5
+ label_alias :another_page_name_alias
6
+
7
+ text_field(:text_field) do
8
+ label_alias :text_field_alias
9
+ locator :id => 'f1'
10
+ menu :loud, 'tf food'
11
+ end
12
+
13
+ button(:button) do
14
+ label_alias :button_alias
15
+ locator :name => 'foo'
16
+ menu :loud, 'try to feed me!'
17
+ end
18
+
19
+ elements_set(:eset) do
20
+ label_alias :eset_alias
21
+
22
+ textarea(:text_area) do
23
+ label_alias :text_area_alias
24
+ locator :id => 'f2'
25
+ menu :loud, 'ta food'
26
+ end
27
+
28
+ radio(:radio_button){
29
+ label_alias :radio_button_alias
30
+ locator :id => 'f3'
31
+ menu :loud, true
32
+ menu :quite, false
33
+ }
34
+
35
+ checkbox(:checkbox){
36
+ label_alias :checkbox_alias
37
+ locator :id => 'f5'
38
+ menu :loud, true
39
+ menu :quite, false
40
+ }
41
+
42
+ select(:select_list) do
43
+ label_alias :select_list_alias
44
+ locator :id => 'f10'
45
+ menu :loud, 'one'
46
+ menu :quite, 'two (default)'
47
+ end
48
+ end
49
+
50
+ action(:press_cool_button, :test_page_with_table) do
51
+ label_alias :action_alias
52
+ button(:name => 'foo').when_present.click
53
+ end
54
+
55
+ table(:table) do
56
+ label_alias :table_alias
57
+ locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
58
+ header [:country, :total_area, :land_area, :link, :checkbox]
59
+ end
60
+
61
+ validator(:textarea_value) do |expected|
62
+ label_alias :textarea_value_alias
63
+ textarea(:id => 'f2').value == expected
64
+ end
65
+
66
+ pagination :pagination do
67
+ label_alias :pagination_alias
68
+ locator "link(:text => 2)", 2
69
+ end
70
+ end
@@ -199,7 +199,7 @@ but they may have use as
199
199
 
200
200
  <h2>Forms</h2>
201
201
 
202
- <form action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi">
202
+ <form action="test_page_with_table.html">
203
203
  <div>
204
204
  <input type="hidden" name="hidden field" value="42">
205
205
  This is a form containing various fields (with some initial
@@ -72,7 +72,7 @@ PageObjectWrapper.define_page(:some_test_page) do
72
72
  end
73
73
 
74
74
  select(:s2) do
75
- locator "form(:action => 'http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi').select(:id => 'f11')"
75
+ locator "form(:action => 'test_page_with_table.html').select(:id => 'f11')"
76
76
  menu :loud, 'one'
77
77
  end
78
78
  end
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
+ <html lang="en-US">
3
+ <head>
4
+ <title>Echoing submitted form data</title>
5
+ </head>
6
+ <body>
7
+ <h1 style="font-size:1.2em">Echoing submitted form data</h1>
8
+ <table border="1" cellspacing="0">
9
+ <tr><th align="left" nowrap><tt>hidden field</tt></th><td nowrap><tt>42</tt></td></tr>
10
+ <tr><th align="left" nowrap><tt>foo</tt></th><td nowrap><tt>bar</tt></td></tr>
11
+ <tr><th align="left" nowrap><tt>text</tt></th><td nowrap><tt>tf�food</tt></td></tr>
12
+ <tr><th align="left" nowrap><tt>textarea</tt></th><td nowrap><tt>ta�food</tt></td></tr>
13
+ <tr><th align="left" nowrap><tt>radio</tt></th><td nowrap><tt>1</tt></td></tr>
14
+ <tr><th align="left" nowrap><tt>checkbox</tt></th><td nowrap><tt>on</tt></td></tr>
15
+ <tr><th align="left" nowrap><tt>select1</tt></th><td nowrap><tt>one</tt></td></tr>
16
+ <tr><th align="left" nowrap><tt>select2</tt></th><td nowrap><tt>one</tt></td></tr>
17
+ </table>
18
+ <p>Processed 2013-07-16T09:45Z
19
+ </p>
20
+ </body>
21
+ </html>
@@ -1,5 +1,5 @@
1
1
  PageObjectWrapper.define_page(:test_page_with_table) do
2
- locator 'http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi?hidden+field=42&foo=bar&text=Default+text.&textarea=Default+text.%0D%0A&radio=2&checkbox2=on&select1=two+%28default%29&select2=two+%28default%29'
2
+ locator 'test_page_with_table.html'
3
3
  uniq_h1 :text => 'Echoing submitted form data'
4
4
 
5
5
  table(:test_table) do
@@ -15,6 +15,9 @@ module PageObjectWrapper
15
15
 
16
16
  def self.use_browser b
17
17
  @@browser = b
18
+ @@browser.class.send :define_method, :label_alias do |sym|
19
+ # do nothing
20
+ end
18
21
  end
19
22
 
20
23
  def self.browser
@@ -15,7 +15,17 @@ module PageObjectWrapper
15
15
 
16
16
  def initialize label
17
17
  @label = label
18
+ @label_aliases = []
18
19
  end
20
+
21
+ def label_alias la
22
+ @label_aliases << la
23
+ end
24
+
25
+ def label_alias_value
26
+ @label_aliases
27
+ end
28
+
19
29
  protected
20
30
  def to_tree(*args)
21
31
  args.collect(&:label_value).join(" -> ")
@@ -12,6 +12,10 @@ module PageObjectWrapper
12
12
  @required = false
13
13
  end
14
14
 
15
+ def type_value
16
+ @type
17
+ end
18
+
15
19
  def menu food_type, value
16
20
  @menu[food_type] = value
17
21
  end
@@ -169,7 +169,6 @@ module PageObjectWrapper
169
169
 
170
170
  def self.open_page label, optional_hash=nil
171
171
  raise PageObjectWrapper::BrowserNotFound if PageObjectWrapper.browser.nil?
172
- raise PageObjectWrapper::UnknownPageObject, label.inspect if not @@pages.collect(&:label_value).include?(label)
173
172
  page_object = PageObject.find_page_object(label)
174
173
  url = ''
175
174
  url += PageObjectWrapper.domain if page_object.locator_value[0]=='/'
@@ -187,7 +186,6 @@ module PageObjectWrapper
187
186
 
188
187
  def self.map_current_page label
189
188
  raise PageObjectWrapper::BrowserNotFound if PageObjectWrapper.browser.nil?
190
- raise PageObjectWrapper::UnknownPageObject, label.inspect if not @@pages.collect(&:label_value).include?(label)
191
189
  page_object = PageObject.find_page_object(label)
192
190
  page_object.elements.select{ |e| e.required_value == true }.each{ |required_element|
193
191
  begin
@@ -219,6 +217,10 @@ module PageObjectWrapper
219
217
 
220
218
  def action(label, next_page=nil, &block)
221
219
  a = Action.new(label, next_page, &block)
220
+ begin
221
+ a.instance_eval( &block )
222
+ rescue # rescue any exception, because only action_alias method is known for POW inside
223
+ end # current block
222
224
  @actions << a
223
225
  a
224
226
  end
@@ -232,6 +234,10 @@ module PageObjectWrapper
232
234
 
233
235
  def validator(label, &block)
234
236
  v = Validator.new(label, &block)
237
+ begin
238
+ v.instance_eval( &block )
239
+ rescue # rescue any exception, because only action_alias method is known for POW inside
240
+ end # current block
235
241
  @validators << v
236
242
  v
237
243
  end
@@ -255,20 +261,23 @@ module PageObjectWrapper
255
261
  def validate
256
262
  output = []
257
263
  # commented out; already defined pages will e redifined with new definitions
258
- raise PageObjectWrapper::Load, "\tpage_object #{label_value.inspect} already defined\n" if labeled(@@pages).count(label_value) > 1
264
+ raise PageObjectWrapper::Load, "\tpage_object #{label_value.inspect} already defined\n" if PageObject.labeled(@@pages).count(label_value) > 1
259
265
  output << "\tlabel #{label_value.inspect} not a Symbol\n" if not label_value.is_a?(Symbol)
266
+ output << "\tlabel aliases #{label_alias_value.inspect} not an Array of Symbols\n" if (not label_alias_value.empty?) and label_alias_value.collect(&:class).uniq != [Symbol]
260
267
  output << "\tlocator #{locator_value.inspect} not a meaningful String\n" if not locator_value.is_a?(String) or locator_value.empty?
261
268
  @esets.each{|eset|
262
269
  eset_output = []
263
- eset_output << "\telements_set #{eset.label_value.inspect} already defined\n" if labeled(@esets).count(eset.label_value) > 1
270
+ eset_output << "\telements_set #{eset.label_value.inspect} already defined\n" if PageObject.labeled(@esets).count(eset.label_value) > 1
264
271
  eset_output << "\tlabel #{eset.label_value.inspect} not a Symbol\n" if not eset.label_value.is_a?(Symbol)
272
+ eset_output << "\tlabel aliases #{eset.label_alias_value.inspect} not an Array of Symbols\n" if (not eset.label_alias_value.empty?) and eset.label_alias_value.collect(&:class).uniq != [Symbol]
265
273
  eset_output.unshift "elements_set(#{eset.label_value.inspect}):\n" if not eset_output.empty?
266
274
  output += eset_output
267
275
  }
268
276
  @elements.each{|e|
269
277
  element_output = []
270
- element_output << "\telement #{e.label_value.inspect} already defined\n" if labeled(@elements).count(e.label_value) > 1
278
+ element_output << "\telement #{e.label_value.inspect} already defined\n" if PageObject.labeled(@elements).count(e.label_value) > 1
271
279
  element_output << "\tlabel #{e.label_value.inspect} not a Symbol\n" if not e.label_value.is_a?(Symbol)
280
+ element_output << "\tlabel aliases #{e.label_alias_value.inspect} not an Array of Symbols\n" if (not e.label_alias_value.empty?) and e.label_alias_value.collect(&:class).uniq != [Symbol]
272
281
  element_output << "\tlocator #{e.locator_value.inspect} not a meaningful Hash or String\n" if (not e.locator_value.is_a?(Hash) and not e.locator_value.is_a?(String)) \
273
282
  or e.locator_value.empty?
274
283
  element_output << "\tmenu #{e.menu_value.inspect} not properly defined (must be { :food_type => 'a string' | true | false })\n" if (not e.menu_value.empty?) and \
@@ -280,11 +289,12 @@ module PageObjectWrapper
280
289
  }
281
290
  @actions.each{|a|
282
291
  action_output = []
283
- action_output << "\taction #{a.label_value.inspect} already defined\n" if labeled(@actions).count(a.label_value) > 1
292
+ action_output << "\taction #{a.label_value.inspect} already defined\n" if PageObject.labeled(@actions).count(a.label_value) > 1
284
293
  action_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
294
+ action_output << "\tlabel aliases #{a.label_alias_value.inspect} not an Array of Symbols\n" if (not a.label_alias_value.empty?) and a.label_alias_value.collect(&:class).uniq != [Symbol]
285
295
  if not a.next_page_value.nil?
286
296
  action_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
287
- action_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
297
+ action_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not PageObject.labeled(@@pages).include?(a.next_page_value)
288
298
  end
289
299
  action_output << "\tfire event is not a Proc\n" if not a.fire_block_value.is_a?(Proc)
290
300
  action_output.unshift "action(#{a.label_value.inspect}):\n" if not action_output.empty?
@@ -292,34 +302,40 @@ module PageObjectWrapper
292
302
  }
293
303
  @aliases.each{|a|
294
304
  alias_output = []
295
- alias_output << "\talias #{a.label_value.inspect} already defined\n" if labeled(@aliases).count(a.label_value) > 1
305
+ alias_output << "\talias #{a.label_value.inspect} already defined\n" if PageObject.labeled(@aliases).count(a.label_value) > 1
296
306
  alias_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
307
+ alias_output << "\tlabel aliases #{a.label_alias_value.inspect} not an Array of Symbols\n" if (not a.label_alias_value.empty?) and a.label_alias_value.collect(&:class).uniq != [Symbol]
297
308
  if not a.next_page_value.nil?
298
309
  alias_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
299
- alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
310
+ alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not PageObject.labeled(@@pages).include?(a.next_page_value)
300
311
  end
301
- alias_output << "\taction #{a.action_value.inspect} not known Action\n" if not labeled(@actions).include? a.action_value
312
+ alias_output << "\taction #{a.action_value.inspect} not known Action\n" if not PageObject.labeled(@actions).include? a.action_value
302
313
  alias_output.unshift "alias(#{a.label_value.inspect}):\n" if not alias_output.empty?
303
314
  output += alias_output
304
315
  }
305
316
  @validators.each{|v|
306
317
  validator_output = []
307
- validator_output << "\tvalidator #{v.label_value.inspect} already defined\n" if labeled(@validators).count(v.label_value) > 1
318
+ validator_output << "\tvalidator #{v.label_value.inspect} already defined\n" if PageObject.labeled(@validators).count(v.label_value) > 1
308
319
  validator_output << "\tlabel #{v.label_value.inspect} not a Symbol\n" if not v.label_value.is_a?(Symbol)
320
+ validator_output << "\tlabel aliases #{v.label_alias_value.inspect} not an Array of Symbols\n" if (not v.label_alias_value.empty?) and v.label_alias_value.collect(&:class).uniq != [Symbol]
309
321
  validator_output << "\tvalidation block is not a Proc\n" if not v.validate_block_value.is_a?(Proc)
310
322
  validator_output.unshift "validator(#{v.label_value.inspect}):\n" if not validator_output.empty?
311
323
  output += validator_output
312
324
  }
313
325
  @tables.each{|t|
314
326
  table_output = []
327
+ table_output << "\ttable #{t.label_value.inspect} already defined\n" if PageObject.labeled(@tables).count(t.label_value) > 1
328
+ table_output << "\tlabel #{t.label_value.inspect} not a Symbol\n" if not t.label_value.is_a?(Symbol)
329
+ table_output << "\tlabel aliases #{t.label_alias_value.inspect} not an Array of Symbols\n" if (not t.label_alias_value.empty?) and t.label_alias_value.collect(&:class).uniq != [Symbol]
315
330
  table_output << "\theader #{t.header_value.inspect} not a meaningful Array\n" if not t.header_value.is_a?(Array) or t.header_value.empty?
316
331
  table_output.unshift "table(#{t.label_value.inspect}):\n" if not table_output.empty?
317
332
  output += table_output
318
333
  }
319
334
  @paginations.each{|p|
320
335
  pagination_output = []
321
- pagination_output << "\tpagination #{p.label_value.inspect} already defined\n" if labeled(@paginations).count(p.label_value) > 1
336
+ pagination_output << "\tpagination #{p.label_value.inspect} already defined\n" if PageObject.labeled(@paginations).count(p.label_value) > 1
322
337
  pagination_output << "\tlabel #{p.label_value.inspect} not a Symbol\n" if not p.label_value.is_a?(Symbol)
338
+ pagination_output << "\tlabel aliases #{p.label_alias_value.inspect} not an Array of Symbols\n" if (not p.label_alias_value.empty?) and p.label_alias_value.collect(&:class).uniq != [Symbol]
323
339
  pagination_output << "\tlocator #{p.locator_value.inspect} not a meaningful String\n" if not p.locator_value.is_a?(String) or p.locator_value.empty?
324
340
  pagination_output << "\t\"#{p.finds_value}\" not found in #{p.locator_value}\n" if not p.locator_value =~ /#{p.finds_value.to_s}/
325
341
  pagination_output.unshift "pagination(#{p.label_value.inspect}):\n" if not pagination_output.empty?
@@ -332,9 +348,8 @@ module PageObjectWrapper
332
348
  private
333
349
 
334
350
  def self.find_page_object(l)
335
- p = @@pages.select{|p| p.label_value == l}.first
336
- raise ArgumentError, "#{l.inspect} not known Page" if p.nil?
337
- p
351
+ raise PageObjectWrapper::UnknownPageObject, l.inspect unless PageObject.labeled( @@pages ).include? l
352
+ @@pages.select{|p| p.label_value == l or p.label_alias_value.include?(l)}.first
338
353
  end
339
354
 
340
355
  def self.return_watir_element(e)
@@ -443,7 +458,7 @@ module PageObjectWrapper
443
458
 
444
459
  if not next_page.nil?
445
460
  raise ArgumentError, "#{next_page.inspect} not a Symbol" if not next_page.is_a? Symbol
446
- raise ArgumentError, "#{next_page.inspect} not known Page" if not labeled(@@pages).include?(next_page)
461
+ raise ArgumentError, "#{next_page.inspect} not known Page" if not PageObject.labeled(@@pages).include?(next_page)
447
462
  end
448
463
 
449
464
  if not where.nil?
@@ -614,24 +629,30 @@ module PageObjectWrapper
614
629
  def press e
615
630
  raise PageObjectWrapper::BrowserNotFound if PageObjectWrapper.browser.nil? or not PageObjectWrapper.browser.exist?
616
631
  watir_element = PageObject.return_watir_element e
617
- raise PageObjectWrapper::InvalidElement, "Element #{e.locator_value} not found in #{PageObjectWrapper.current_page}"\
632
+ raise PageObjectWrapper::InvalidElement, "#{e.type_value} #{e.locator_value} not found in #{PageObjectWrapper.current_page.label_value}"\
618
633
  if not watir_element.present?
619
- raise PageObjectWrapper::InvalidElement, "Element #{e.locator_value} does not respond to #{e.press_action_value}"\
634
+ raise PageObjectWrapper::InvalidElement, "#{e.type_value} #{e.locator_value} does not respond to #{e.press_action_value}"\
620
635
  if not watir_element.respond_to? e.press_action_value
621
636
  watir_element.when_present.send e.press_action_value
622
637
  watir_element
623
638
  end
624
639
 
625
- def labeled(ary)
626
- ary.collect(&:label_value)
640
+ def self.labeled(ary)
641
+ labels = ary.collect(&:label_value)
642
+ label_aliases = []
643
+ ary.each{ |obj| label_aliases += obj.label_alias_value }
644
+ labels + label_aliases
627
645
  end
628
646
 
629
647
  [:eset, :element, :table, :pagination, :action, :alias, :validator].each{|el|
630
648
  PageObject.send :define_method, 'has_'+el.to_s+'?' do |label| # has_xxx?(label)
631
- labeled(instance_variable_get("@#{el.to_s.pluralize}")).include?(label.to_sym)
649
+ PageObject.labeled(instance_variable_get("@#{el.to_s.pluralize}")).include?(label.to_sym)
632
650
  end
633
651
  PageObject.send :define_method, el.to_s+'_for' do |label| # xxx_for(label)
634
- instance_variable_get("@#{el.to_s.pluralize}")[labeled(instance_variable_get("@#{el.to_s.pluralize}")).index(label.to_sym)]
652
+ instance_variable_get("@#{el.to_s.pluralize}").each{ |obj|
653
+ return obj if obj.label_value == label.to_sym or obj.label_alias_value.include? label.to_sym
654
+ }
655
+ raise ArgumentError, "cant define method #{ el.to_s + '_for' } because @#{el.to_s.pluralize} doesnt have element with label #{label.inspect}"
635
656
  end
636
657
  }
637
658
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PageObjectWrapper
2
- VERSION = "1.5.4" unless const_defined?(:VERSION)
2
+ VERSION = "1.5.5" unless const_defined?(:VERSION)
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "returned values" do
4
4
  before(:all){
5
- @b = Watir::Browser.new
5
+ @b = Watir::Browser.new :chrome
6
6
  PageObjectWrapper.use_browser @b
7
7
  }
8
8
 
@@ -16,6 +16,10 @@ describe "define_page_object" do
16
16
  it_should_behave_like "a label"
17
17
  end
18
18
 
19
+ describe "page_object label alias" do
20
+ it_should_behave_like "a label alias"
21
+ end
22
+
19
23
  describe "page_object locator" do
20
24
  it_should_behave_like "a locator"
21
25
  its(:locator_value) { should be_a String }
@@ -75,6 +79,10 @@ describe "define_page_object" do
75
79
  describe "element label" do
76
80
  it_should_behave_like "a label"
77
81
  end
82
+
83
+ describe "element label alias" do
84
+ it_should_behave_like "a label alias"
85
+ end
78
86
 
79
87
  describe "element locator" do
80
88
  it_should_behave_like "a locator"
@@ -102,6 +110,10 @@ describe "define_page_object" do
102
110
  describe "elements_set label" do
103
111
  it_should_behave_like "a label"
104
112
  end
113
+
114
+ describe "elements_set label alias" do
115
+ it_should_behave_like "a label alias"
116
+ end
105
117
  end
106
118
 
107
119
  context "element inside elements_set" do
@@ -112,6 +124,10 @@ describe "define_page_object" do
112
124
  describe "element label" do
113
125
  it_should_behave_like "a label"
114
126
  end
127
+
128
+ describe "element label alias" do
129
+ it_should_behave_like "a label alias"
130
+ end
115
131
 
116
132
  describe "element locator" do
117
133
  it_should_behave_like "a locator"
@@ -140,6 +156,10 @@ describe "define_page_object" do
140
156
  it_should_behave_like "a label"
141
157
  end
142
158
 
159
+ describe "action label alias" do
160
+ it_should_behave_like "a label alias"
161
+ end
162
+
143
163
  describe "action attributes" do
144
164
  it { should respond_to(:next_page_value) }
145
165
  it { should respond_to(:fire_block_value) }
@@ -158,6 +178,10 @@ describe "define_page_object" do
158
178
  it_should_behave_like "a label"
159
179
  end
160
180
 
181
+ describe "alias label alias" do
182
+ it_should_behave_like "a label alias"
183
+ end
184
+
161
185
  describe "alias attributes" do
162
186
  it { should respond_to(:next_page_value) }
163
187
  it { should respond_to(:action_value) }
@@ -176,6 +200,10 @@ describe "define_page_object" do
176
200
  it_should_behave_like "a label"
177
201
  end
178
202
 
203
+ describe "validator label alias" do
204
+ it_should_behave_like "a label alias"
205
+ end
206
+
179
207
  describe "validator attributes" do
180
208
  it { should respond_to(:validate_block_value) }
181
209
  its(:validate_block_value) { should be_a Proc }
@@ -190,6 +218,10 @@ describe "define_page_object" do
190
218
  describe "table label" do
191
219
  it_should_behave_like "a label"
192
220
  end
221
+
222
+ describe "table label alias" do
223
+ it_should_behave_like "a label alias"
224
+ end
193
225
 
194
226
  describe "element locator" do
195
227
  it_should_behave_like "a locator"
@@ -225,6 +257,10 @@ describe "define_page_object" do
225
257
  describe "pagination label" do
226
258
  it_should_behave_like "a label"
227
259
  end
260
+
261
+ describe "pagination label alias" do
262
+ it_should_behave_like "a label alias"
263
+ end
228
264
 
229
265
  describe "pagination locator" do
230
266
  it_should_behave_like "a locator"
@@ -11,7 +11,7 @@ describe "page_object.feed_xxx" do
11
11
 
12
12
  context "browser is opened" do
13
13
  before(:all){
14
- @b = Watir::Browser.new
14
+ @b = Watir::Browser.new :chrome
15
15
  PageObjectWrapper.use_browser @b
16
16
  }
17
17
  before(:each){ @tp = PageObjectWrapper.open_page(:some_test_page) }
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe "label_aliases" do
4
+ before(:all){
5
+ @b = Watir::Browser.new :chrome
6
+ PageObjectWrapper.use_browser @b
7
+ }
8
+
9
+ after(:all){ PageObjectWrapper.browser.quit }
10
+
11
+ let(:tp){ PageObjectWrapper.open_page :page_name_alias }
12
+
13
+ it "opens correct page by alias" do
14
+ tp = PageObjectWrapper.open_page :page_name_alias
15
+ tp2 = PageObjectWrapper.open_page :another_page_name_alias
16
+ tp.should eq tp2
17
+ PageObjectWrapper.current_page?(:page_with_aliases).should eq true
18
+ PageObjectWrapper.current_page?(:page_name_alias).should eq true
19
+ PageObjectWrapper.current_page?(:another_page_name_alias).should eq true
20
+ end
21
+
22
+ it "works with text_field" do
23
+ tp.feed_text_field_alias 'text'
24
+ PageObjectWrapper.current_result.should be_a Watir::TextField
25
+ PageObjectWrapper.current_result?(:value, 'text').should eq true
26
+ end
27
+
28
+ it "works with returned values" do
29
+ tf = tp.text_field_alias
30
+ tf.should be_a Watir::TextField
31
+ end
32
+
33
+ it "works with elements_set" do
34
+ tp.feed_eset_alias :loud
35
+ expected = ["ta food", "1", "on", "one"]
36
+ PageObjectWrapper.current_result.should be_a Array
37
+ PageObjectWrapper.current_result?("collect(&:value)", expected).should eq true
38
+ end
39
+
40
+ it "works with action" do
41
+ tp.fire_action_alias
42
+ PageObjectWrapper.current_result.should be_a PageObjectWrapper::PageObject
43
+ PageObjectWrapper.current_result?(:label_value, :test_page_with_table).should eq true
44
+ end
45
+
46
+ it "works with table alias" do
47
+ tp.select_from_table_alias(:country, :row => 2)
48
+ PageObjectWrapper.current_result.should be_a Watir::TableCell
49
+ PageObjectWrapper.current_result?(:text, 'Denmark').should eq true
50
+ end
51
+ end
52
+
data/spec/load_spec.rb CHANGED
@@ -10,9 +10,9 @@ describe "PageObjectWrapper.load" do
10
10
  begin
11
11
  PageObjectWrapper.load(File.dirname(__FILE__)+'/../bad_pages')
12
12
  rescue Exception => e
13
- # puts '=============='
14
- # puts e.message
15
- # puts '=============='
13
+ #puts '=============='
14
+ #puts e.message
15
+ #puts '=============='
16
16
  e.should be_a(PageObjectWrapper::Load)
17
17
  e.message.should == 'page_object("some_page_with_lost_of_errors"):
18
18
  label "some_page_with_lost_of_errors" not a Symbol
@@ -33,6 +33,15 @@ element(:e):
33
33
  element(:e):
34
34
  element :e already defined
35
35
  locator {} not a meaningful Hash or String
36
+ element(:dublicate_tf):
37
+ element :dublicate_tf already defined
38
+ locator nil not a meaningful Hash or String
39
+ element(:another_dublicate_tf):
40
+ element :another_dublicate_tf already defined
41
+ label aliases ["not a symbol"] not an Array of Symbols
42
+ locator nil not a meaningful Hash or String
43
+ element(:area):
44
+ locator nil not a meaningful Hash or String
36
45
  element(""):
37
46
  element "" already defined
38
47
  label "" not a Symbol
@@ -50,6 +59,8 @@ alias(""):
50
59
  action "unknown action" not known Action
51
60
  validator(""):
52
61
  label "" not a Symbol
62
+ table(""):
63
+ label "" not a Symbol
53
64
  table(:some_table):
54
65
  header [] not a meaningful Array
55
66
  pagination(""):
@@ -10,7 +10,7 @@ describe "PageObjectWrapper.open_page" do
10
10
  context "browser is opened" do
11
11
 
12
12
  before(:all){
13
- @b = Watir::Browser.new
13
+ @b = Watir::Browser.new :chrome
14
14
  PageObjectWrapper.use_browser @b
15
15
  }
16
16
 
@@ -80,9 +80,9 @@ describe "page_object.select_from_xxx" do
80
80
  context "several rows found" do
81
81
  it "returns first found row" do
82
82
  table_page = tp.fire_press_cool_button
83
- t_row = table_page.select_row_from_test_table(:column_1 => 'Default text.')
83
+ t_row = table_page.select_row_from_test_table(:column_1 => 'one')
84
84
  t_row.should be_a Hash
85
- t_row[:column_0].text.should eq 'text'
85
+ t_row[:column_0].text.should eq 'select1'
86
86
  end
87
87
  end
88
88
 
@@ -6,6 +6,12 @@ shared_examples_for "a label" do
6
6
  specify { subject.label_value.should be_a(Symbol)}
7
7
  end
8
8
 
9
+ shared_examples_for "a label alias" do
10
+ it { should respond_to(:label_alias)}
11
+ it { should respond_to(:label_alias_value)}
12
+ specify { subject.label_alias_value.should be_a(Array)}
13
+ end
14
+
9
15
  shared_examples_for "a locator" do
10
16
  it { should respond_to(:locator) }
11
17
  it { should respond_to(:locator_value)}
data/spec/xxx_each.rb CHANGED
@@ -10,7 +10,7 @@ describe 'page_object.each_xxx' do
10
10
 
11
11
  context "browser is opened" do
12
12
  before(:all){
13
- @b = Watir::Browser.new
13
+ @b = Watir::Browser.new :chrome
14
14
  PageObjectWrapper.use_browser @b
15
15
  }
16
16
  after(:all){ PageObjectWrapper.browser.quit }
data/spec/xxx_open.rb CHANGED
@@ -10,7 +10,7 @@ describe 'page_object.open_xxx' do
10
10
 
11
11
  context "browser is opened" do
12
12
  before(:all){
13
- @b = Watir::Browser.new
13
+ @b = Watir::Browser.new :chrome
14
14
  PageObjectWrapper.use_browser @b
15
15
  }
16
16
  after(:all){ PageObjectWrapper.browser.quit }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_object_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-11 00:00:00.000000000 Z
12
+ date: 2013-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &20960480 !ruby/object:Gem::Requirement
16
+ requirement: &11533360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20960480
24
+ version_requirements: *11533360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &20959820 !ruby/object:Gem::Requirement
27
+ requirement: &11532880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20959820
35
+ version_requirements: *11532880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: babosa
38
- requirement: &20959380 !ruby/object:Gem::Requirement
38
+ requirement: &11532300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20959380
46
+ version_requirements: *11532300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &20958840 !ruby/object:Gem::Requirement
49
+ requirement: &11547780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20958840
57
+ version_requirements: *11547780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: debugger
60
- requirement: &20974600 !ruby/object:Gem::Requirement
60
+ requirement: &11546920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20974600
68
+ version_requirements: *11546920
69
69
  description: Wraps watir-webdriver with convenient testing interface, based on PageObjects
70
70
  automation testing pattern. Simplifies resulting automated test understanding.
71
71
  email:
@@ -80,6 +80,7 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - bad_pages/bad_page.rb
83
+ - good_pages/aliases_page.rb
83
84
  - good_pages/another_test_page.rb
84
85
  - good_pages/dynamic_url_page.rb
85
86
  - good_pages/google_page.rb
@@ -89,6 +90,7 @@ files:
89
90
  - good_pages/required_missing_page.rb
90
91
  - good_pages/some_test_page.html
91
92
  - good_pages/some_test_page.rb
93
+ - good_pages/test_page_with_table.html
92
94
  - good_pages/test_table_page.rb
93
95
  - good_pages/uniq_missing_page.rb
94
96
  - img/scheme.png
@@ -111,6 +113,7 @@ files:
111
113
  - spec/feed_xxx_spec.rb
112
114
  - spec/fire_xxx_and_validate_xxx_spec.rb
113
115
  - spec/generate_spec.rb
116
+ - spec/label_alias_spec.rb
114
117
  - spec/load_spec.rb
115
118
  - spec/menu_xxx_spec.rb
116
119
  - spec/open_page_spec.rb
@@ -153,6 +156,7 @@ test_files:
153
156
  - spec/feed_xxx_spec.rb
154
157
  - spec/fire_xxx_and_validate_xxx_spec.rb
155
158
  - spec/generate_spec.rb
159
+ - spec/label_alias_spec.rb
156
160
  - spec/load_spec.rb
157
161
  - spec/menu_xxx_spec.rb
158
162
  - spec/open_page_spec.rb