page_object_wrapper 1.3.5 → 1.3.6

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/README.md CHANGED
@@ -174,20 +174,32 @@ current\_page
174
174
  *preconditions*
175
175
  **tp** is a :some\_test\_page object opened in the browser
176
176
 
177
- context "argument = :fresh_food":
178
- it "populates all xxx elements with :fresh_food":
179
- tp = PageObjectWrapper.current_page
180
- tp.feed_test_elements(:fresh_food)
181
-
182
- context "argument = nil":
183
- it "populates all xxx elements with :fresh_food":
184
- tp = PageObjectWrapper.current_page
185
- tp.feed_test_elements
186
-
187
- context "argument = :missing_food":
188
- it "populates all xxx elements with :missing_food":
189
- tp = PageObjectWrapper.open_page(:some_test_page)
190
- tp.feed_test_elements(:missing_food)
177
+ context "menu not specified":
178
+ it "does nothing":
179
+ tp.feed_test_elements
180
+ browser.text_field(:id => 'f1').value.should eq 'Default text.'
181
+ ....
182
+
183
+ describe "basic usage":
184
+ it "FEEDS elements which have provided menu inside defimition":
185
+ tp.feed_test_elements(:loud)
186
+ browser.text_field(:id => 'f1').value.should eq 'tf food'
187
+ ....
188
+
189
+ it "feeds ONLY elements which has provided menu":
190
+ tp.feed_test_elements(:quite)
191
+ browser.text_field(:id => 'f1').value.should eq 'Default text.'
192
+ ....
193
+
194
+ it "overrides defined menu when passing arguments":
195
+ tp.feed_test_elements(:loud, :tf => 'cheef menu', :rb1 => false, :rb2 => true, :cb2 => true, :s2 => 'three')
196
+ browser.text_field(:id => 'f1').value.should eq 'cheef menu'
197
+ ....
198
+
199
+ it "can be used without providing a menu":
200
+ tp.feed_test_elements(:tf => 'cheef menu', :rb2 => true, :cb2 => true, :s2 => 'three')
201
+ browser.text_field(:id => 'f1').value.should eq 'cheef menu'
202
+ ....
191
203
 
192
204
  #### xxx\_menu
193
205
  *parameters*
@@ -198,8 +210,8 @@ food value for this type which is defined in page\_object
198
210
  *preconditions*
199
211
  **tp** is a :some\_test\_page object opened in the browser
200
212
 
201
- tp.tf_menu(:fresh_food) # => 'default fresh food'
202
- tp.tf_menu(:user_defined) # => 'some food'
213
+ tp.tf_menu(:loud) # => 'tf food'
214
+ tp.rb1_menu(:loud) # => 'true' # pay attention that String is being returned (not true, TrueClass)
203
215
 
204
216
  #### fire\_xxx
205
217
  *parameters*
@@ -312,9 +324,25 @@ correct arguments are:
312
324
  tp.select_from_table_with_header(:country, {:row => 123}, :some_test_page).should eq nil
313
325
 
314
326
  #### each\_xxx
315
- TODO
327
+ context "correct parameters ( limit = 3 )":
328
+ it "opens browser on subeach page and yields corresponding page_object":
329
+ gp = PageObjectWrapper.open_page(:google_pagination)
330
+ counter = 0
331
+ gp.pagination_each( :limit => 3 ){ |subpage|
332
+ counter += 1
333
+ subpage.should be_a PageObject
334
+ subpage.validate_current_number?(counter).should be_true
335
+ }
316
336
  #### open\_xxx
317
- TODO
337
+ context "correct parameters":
338
+ it "opens browser on provided subpage returns corresponding page_object":
339
+ n = 10
340
+ yp = PageObjectWrapper.open_page(:yandex_pagination)
341
+ yp.pagination_open(n).should be_a PageObject
342
+ yp.validate_current_number?(n).should be_true
343
+ gp = PageObjectWrapper.open_page(:google_pagination)
344
+ gp.pagination_open(n).should be_a PageObject
345
+ gp.validate_current_number?(n).should be_true
318
346
  ## Contributing
319
347
 
320
348
  1. Fork it
@@ -35,7 +35,7 @@ PageObjectWrapper.define_page('some_page_with_lost_of_errors') do
35
35
  end
36
36
 
37
37
  pagination('') do
38
- locator 'pagination locator'
38
+ locator Hash.new, 1
39
39
  end
40
40
  end
41
41
 
@@ -1,4 +1,4 @@
1
1
  PageObjectWrapper.define_page(:google_page) do
2
2
  locator 'google.com'
3
- uniq_input :id => 'gbqfq'
3
+ uniq_text_field :name => 'q'
4
4
  end
@@ -0,0 +1,34 @@
1
+ PageObjectWrapper.define_page(:google_pagination) do
2
+ locator 'https://www.google.ru/#hl=ru&newwindow=1&tbo=d&output=search&sclient=psy-ab&q=123&oq=123&gs_l=hp.3..35i39j0l3.1315.1644.0.1789.3.3.0.0.0.0.101.214.2j1.3.0...0.0...1c.1.2.hp.RHZTJZtdIWY&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.41867550,d.bGE&fp=bd383a4eab7647dd&biw=1920&bih=965'
3
+ uniq_input :id => 'gbqfq'
4
+
5
+ pagination :pagination do
6
+ locator "a(:text => '2')", '2'
7
+ end
8
+
9
+ validator :current_number? do |n|
10
+ td( :text => n.to_s ).present?
11
+ end
12
+ end
13
+
14
+ PageObjectWrapper.define_page :yandex_pagination do
15
+ locator 'http://yandex.ru/yandsearch?text=123&lr=213&msid=20941.6968.1359721756.81263'
16
+ uniq_input :class => 'b-form-input__input'
17
+
18
+ pagination :pagination do
19
+ locator "link(:class => 'b-pager__page b-link b-link_ajax_yes', :text => '2')", '2'
20
+ end
21
+
22
+ validator :current_number? do |n|
23
+ div( :class => 'b-pager__pages', :text => /#{n.to_s}.*/ ).present?
24
+ end
25
+ end
26
+
27
+ PageObjectWrapper.define_page(:google_invalid_pagination) do
28
+ locator 'https://www.google.ru/#hl=ru&newwindow=1&tbo=d&output=search&sclient=psy-ab&q=123&oq=123&gs_l=hp.3..35i39j0l3.1315.1644.0.1789.3.3.0.0.0.0.101.214.2j1.3.0...0.0...1c.1.2.hp.RHZTJZtdIWY&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.41867550,d.bGE&fp=bd383a4eab7647dd&biw=1920&bih=965'
29
+ uniq_input :id => 'gbqfq'
30
+
31
+ pagination :invalid_pagination do
32
+ locator "table(:id => 'nav').tr.td.a(:text => '1000')", '1000'
33
+ end
34
+ end
@@ -6,26 +6,46 @@ PageObjectWrapper.define_page(:some_test_page) do
6
6
  elements_set(:test_elements) do
7
7
  text_field(:tf) do
8
8
  locator :id => 'f1'
9
- menu :user_defined, 'some food'
9
+ menu :loud, 'tf food'
10
10
  end
11
11
 
12
12
  textarea(:ta) do
13
13
  locator :id => 'f2'
14
+ menu :loud, 'ta food'
14
15
  end
16
+
17
+ radio(:rb1){
18
+ locator :id => 'f3'
19
+ menu :loud, true
20
+ menu :quite, false
21
+ }
15
22
 
23
+ radio(:rb2){
24
+ locator :id => 'f4'
25
+ menu :loud, false
26
+ }
27
+
28
+ checkbox(:cb1){
29
+ locator :id => 'f5'
30
+ menu :loud, true
31
+ menu :quite, false
32
+ }
33
+
34
+ checkbox(:cb2){
35
+ locator :id => 'f6'
36
+ menu :loud, false
37
+ }
38
+
16
39
  select(:s1) do
17
40
  locator :id => 'f10'
18
- menu :fresh_food, 'one'
19
- menu :missing_food, 'three'
41
+ menu :loud, 'one'
42
+ menu :quite, 'two (default)'
20
43
  end
21
44
 
22
45
  select(:s2) do
23
46
  locator "form(:action => 'http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi').select(:id => 'f11')"
24
- menu :fresh_food, 'one'
47
+ menu :loud, 'one'
25
48
  end
26
-
27
- checkbox(:cb){ locator :id => 'f5' }
28
- radio(:rb){ locator :id => 'f3' }
29
49
  end
30
50
 
31
51
  action(:press_cool_button, :test_page_with_table) do
@@ -55,11 +75,11 @@ PageObjectWrapper.define_page(:some_test_page) do
55
75
  header [:country, :total_area, :land_area]
56
76
  end
57
77
 
58
- pagination(:some_pagination) do
59
- locator :xpath => ''
60
- end
61
-
62
78
  validator(:textarea_value) do |expected|
63
79
  textarea(:id => 'f2').value == expected
64
80
  end
81
+
82
+ pagination :some_pagination do
83
+ locator "link(:text => 2)", 2
84
+ end
65
85
  end
@@ -5,7 +5,7 @@ class Element < DslElementWithLocator
5
5
  def initialize(label, type)
6
6
  super label
7
7
  @type = type
8
- @menu = { :fresh_food => 'default fresh food', :missing_food => 'default missing food' }
8
+ @menu = Hash.new
9
9
  end
10
10
 
11
11
  def menu food_type, value
@@ -6,4 +6,6 @@ module PageObjectWrapper
6
6
  class Load < StandardError; end
7
7
  class BrowserNotFound < StandardError; end
8
8
  class DynamicUrl < StandardError; end
9
+ class InvalidPagination < StandardError; end
10
+ class OutOfBoundsSubpage < StandardError; end
9
11
  end
@@ -25,7 +25,7 @@ class PageObject < DslElementWithLocator
25
25
  SELECT_FROM = Regexp.new(/^select_from_([\w_]+)$/)
26
26
  PAGINATION_EACH = Regexp.new(/^([\w_]+)_each$/)
27
27
  PAGINATION_OPEN = Regexp.new(/^([\w_]+)_open$/)
28
- VALIDATE = Regexp.new(/^validate_([\w_]+)$/)
28
+ VALIDATE = Regexp.new(/^validate_([\w_\?]+)$/)
29
29
 
30
30
  def initialize(label)
31
31
  super label
@@ -41,7 +41,7 @@ class PageObject < DslElementWithLocator
41
41
  end
42
42
 
43
43
  # lazy evaluated calls of real watir elements are handled by :method_missing
44
- def method_missing(method_name, *args)
44
+ def method_missing(method_name, *args, &block)
45
45
  case
46
46
  when KNOWN_ELEMENTS.include?(method_name.to_s.gsub(/^uniq_/,''))
47
47
  # page_object.uniq_xxx(hash)
@@ -81,7 +81,7 @@ class PageObject < DslElementWithLocator
81
81
  when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
82
82
  # page_object.each_pagination
83
83
  pagination = pagination_for($1)
84
- run_each_subpage(pagination, *args)
84
+ run_each_subpage(pagination, *args, &block)
85
85
  when (PAGINATION_OPEN.match(method_name) and has_pagination?($1))
86
86
  # page_object.open_padination(1)
87
87
  pagination = pagination_for($1)
@@ -247,7 +247,7 @@ class PageObject < DslElementWithLocator
247
247
  element_output << "\t\telement #{e.label_value.inspect} already defined\n" if labeled(eset.elements).count(e.label_value) > 1
248
248
  element_output << "\t\tlabel #{e.label_value.inspect} not a Symbol\n" if not e.label_value.is_a?(Symbol)
249
249
  element_output << "\t\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)) or e.locator_value.empty?
250
- element_output << "\t\tmenu #{e.menu_value.inspect} not properly defined (must be {:food_type => 'a string'})\n" if (e.menu_value.keys.collect(&:class).uniq! != [Symbol]) or (e.menu_value.values.collect(&:class).uniq! != [String])
250
+ element_output << "\t\tmenu #{e.menu_value.inspect} not properly defined (must be { :food_type => 'a string' | true | false })\n" if (e.menu_value.keys.collect(&:class).uniq != [Symbol]) or not (e.menu_value.values.collect(&:class).uniq - [String, TrueClass, FalseClass]).empty?
251
251
  element_output.unshift "\telement(#{e.label_value.inspect}):\n" if not element_output.empty?
252
252
  output += element_output
253
253
  }
@@ -288,7 +288,7 @@ class PageObject < DslElementWithLocator
288
288
  table_output = []
289
289
  table_output << "\ttable #{t.label_value.inspect} already defined\n" if labeled(@tables).count(t.label_value) > 1
290
290
  table_output << "\tlabel #{t.label_value.inspect} not a Symbol\n" if not t.label_value.is_a?(Symbol)
291
- table_output << "\tlocator #{t.locator_value.inspect} not a meaningful Hash\n" if not t.locator_value.is_a?(Hash) or t.locator_value.empty?
291
+ table_output << "\tlocator #{t.locator_value.inspect} not a meaningful Hash or String\n" if (not t.locator_value.is_a?(Hash) and not t.locator_value.is_a?(String)) or t.locator_value.empty?
292
292
  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?
293
293
  table_output.unshift "table(#{t.label_value.inspect}):\n" if not table_output.empty?
294
294
  output += table_output
@@ -297,7 +297,8 @@ class PageObject < DslElementWithLocator
297
297
  pagination_output = []
298
298
  pagination_output << "\tpagination #{p.label_value.inspect} already defined\n" if labeled(@paginations).count(p.label_value) > 1
299
299
  pagination_output << "\tlabel #{p.label_value.inspect} not a Symbol\n" if not p.label_value.is_a?(Symbol)
300
- pagination_output << "\tlocator #{p.locator_value.inspect} not a meaningful Hash\n" if not p.locator_value.is_a?(Hash) or p.locator_value.empty?
300
+ 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?
301
+ pagination_output << "\t\"#{p.finds_value}\" not found in #{p.locator_value}\n" if not p.locator_value =~ /#{p.finds_value.to_s}/
301
302
  pagination_output.unshift "pagination(#{p.label_value.inspect}):\n" if not pagination_output.empty?
302
303
  output += pagination_output
303
304
  }
@@ -327,30 +328,38 @@ private
327
328
  eset.elements.collect{|e| return_watir_element(e)}
328
329
  end
329
330
 
330
- def feed_elements(elements, menu_type=nil)
331
+ def feed_elements(elements, *args)
332
+ menu_name, cheef_menu = nil, nil
333
+
334
+ if args[0].is_a? Symbol
335
+ menu_name = args[0]
336
+ cheef_menu = args[1]
337
+ elsif args[0].is_a? Hash
338
+ cheef_menu = args[0]
339
+ end
331
340
  raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
332
- menu_type ||= :fresh_food
333
- known_types = []
334
- elements.each{ |e| known_types += e.menu_value.keys }
335
- raise PageObjectWrapper::UnknownMenuType, menu_type.inspect if not known_types.include?(menu_type)
341
+ if not cheef_menu.nil?
342
+ raise ArgumentError, "#{cheef_menu.inspect} not meaningful Hash" if not cheef_menu.is_a? Hash or cheef_menu.empty?
343
+ end
344
+ menus = []
345
+ elements.each{ |e| menus += e.menu_value.keys }
336
346
  elements.each{|e|
337
- food = e.menu_value[menu_type].to_s
347
+ if not cheef_menu.nil? and cheef_menu.keys.include? e.label_value
348
+ food = cheef_menu[e.label_value]
349
+ else
350
+ food = e.menu_value[menu_name].to_s
351
+ end
338
352
  watir_element = return_watir_element(e)
339
353
  case watir_element
340
354
  when Watir::CheckBox
341
- watir_element.when_present.set
355
+ watir_element.when_present.set eval(food) if ["true", "false"].include? food
342
356
  when Watir::Radio
343
- watir_element.when_present.set
357
+ watir_element.when_present.set if food=="true"
344
358
  when Watir::Select
345
- begin
346
- watir_element.when_present.select food
347
- rescue Watir::Exception::NoValueFoundException => e
348
- # proceed to next element if missing_food is not found in select list
349
- next
350
- end
359
+ watir_element.select food if watir_element.include? food
351
360
  else
352
361
  if watir_element.respond_to?(:set)
353
- watir_element.when_present.set food
362
+ watir_element.when_present.set food if food!=''
354
363
  else
355
364
  raise PageObjectWrapper::UnableToFeedObject, to_tree(@@current_page, e) + ' check element type'
356
365
  end
@@ -444,12 +453,38 @@ private
444
453
  end
445
454
  end
446
455
 
447
- def each_pagination
456
+ def run_each_subpage(p, opts=nil, &block)
448
457
  raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
458
+ limit = opts[:limit] if not opts.nil?
459
+ raise PageObjectWrapper::InvalidPagination, opts.inspect if limit < 0 if not limit.nil?
460
+
461
+ current_link = @@browser.instance_eval p.locator_value
462
+ raise PageObjectWrapper::InvalidPagination, p.locator_value+'; '+p.finds_value if not current_link.present?
463
+ current_page_number = p.finds_value.to_i
464
+ counter = 0
465
+
466
+ while current_link.present?
467
+ break if limit.is_a? Integer and counter >= limit
468
+ current_link.when_present.click
469
+ self.class.map_current_page self.label_value
470
+ current_link.wait_while_present # waiting for the page to load by waiting current_link to become inactive
471
+ block.call self
472
+ current_page_number += 1
473
+ current_link_locator = p.locator_value.gsub( p.finds_value.to_s, current_page_number.to_s )
474
+ current_link = @@browser.instance_eval current_link_locator
475
+ counter += 1
476
+ end
449
477
  end
450
478
 
451
- def open_padination n
479
+ def open_subpage p, n, *args
452
480
  raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
481
+ pagination_link = @@browser.instance_eval p.locator_value
482
+ raise PageObjectWrapper::InvalidPagination, p.locator_value+'; '+p.finds_value if not pagination_link.present?
483
+ n_th_link_locator = p.locator_value.gsub( p.finds_value.to_s, n.to_s )
484
+ n_th_link = @@browser.instance_eval n_th_link_locator
485
+ n_th_link.when_present.click
486
+ self.class.map_current_page self.label_value
487
+ self
453
488
  end
454
489
 
455
490
 
@@ -1,8 +1,23 @@
1
1
  require 'Dsl'
2
- class Pagination < DslElementWithLocator
2
+ class Pagination < DslElement
3
3
 
4
4
  def initialize(label)
5
5
  super label
6
+ @locator = nil
7
+ @finds = nil
8
+ end
9
+
10
+ def locator hash, finds
11
+ @locator = hash
12
+ @finds = finds
13
+ end
14
+
15
+ def locator_value
16
+ @locator
17
+ end
18
+
19
+ def finds_value
20
+ @finds
6
21
  end
7
22
  end
8
23
 
@@ -1,3 +1,3 @@
1
1
  module PageObjectWrapper
2
- VERSION = "1.3.5"
2
+ VERSION = "1.3.6"
3
3
  end
@@ -80,16 +80,9 @@ describe "define_page_object" do
80
80
 
81
81
  its(:menu_value) { should be_a Hash}
82
82
 
83
- describe "default menu" do
84
- its(:menu_value){ should have_key(:fresh_food) }
85
- its(:menu_value){ should have_value 'default fresh food'}
86
- its(:menu_value){ should have_key(:missing_food) }
87
- its(:menu_value){ should have_value 'default missing food'}
88
- end
89
-
90
83
  describe "user defined menu" do
91
- its(:menu_value){ should have_key :user_defined }
92
- its(:menu_value){ should have_value 'some food'}
84
+ its(:menu_value){ should have_key :loud }
85
+ its(:menu_value){ should have_value 'tf food'}
93
86
  end
94
87
  end
95
88
  end
@@ -191,7 +184,7 @@ describe "define_page_object" do
191
184
 
192
185
  describe "pagination locator" do
193
186
  it_should_behave_like "a locator"
194
- its(:locator_value) { should be_a Hash }
187
+ its(:locator_value) { should be_a String }
195
188
  end
196
189
  end
197
190
  end
@@ -14,76 +14,69 @@ describe "page_object.feed_xxx" do
14
14
  @b = Watir::Browser.new
15
15
  PageObjectWrapper.use_browser @b
16
16
  }
17
+ before(:each){ @tp = PageObjectWrapper.open_page(:some_test_page) }
17
18
  after(:all){ PageObjectWrapper.browser.quit }
18
-
19
- it "returns current page object" do
20
- tp = PageObjectWrapper.open_page(:some_test_page)
21
- tp.feed_test_elements.should eq(tp)
22
- end
23
19
 
24
20
  context "xxx not found among current_page element_sets" do
25
21
  it "raises NoMethodError" do
26
- tp = PageObjectWrapper.current_page
27
- expect{tp.feed_empty_set}.to raise_error(NoMethodError)
22
+ expect{@tp.feed_unknown_elements_set}.to raise_error(NoMethodError)
28
23
  end
29
24
  end
30
25
 
31
- context "argument = :fresh_food" do
32
- it "populates all xxx elements with :fresh_food" do
33
- tp = PageObjectWrapper.current_page
34
- tp.feed_test_elements(:fresh_food)
35
- @b.text_field(:id=>'f1').value.should eq 'default fresh food'
36
- @b.textarea(:id=>'f2').value.should eq 'default fresh food'
37
- @b.select(:id=>'f10').value.should eq "one"
38
- @b.select(:id=>'f11').value.should eq "one"
39
- @b.checkbox(:id=>'f5').should be_set
40
- @b.radio(:id=>'f3').should be_set
41
- end
26
+ it "returns current page object" do
27
+ @tp.feed_test_elements(:quite).should be_a PageObject
42
28
  end
43
29
 
44
- context "argument = :user_defined" do
45
- it "populates all xxx elements with :user_defined" do
46
- tp = PageObjectWrapper.open_page(:some_test_page)
47
- tp.feed_test_elements(:user_defined)
48
- @b.text_field(:id=>'f1').value.should eq 'some food'
49
- @b.textarea(:id=>'f2').value.should eq ''
50
- @b.select(:id=>'f10').value.should eq "two (default)"
51
- @b.select(:id=>'f11').value.should eq "two (default)"
52
- @b.checkbox(:id=>'f5').should be_set
53
- @b.radio(:id=>'f3').should be_set
30
+ context "menu not specified" do
31
+ it "does nothing" do
32
+ @tp.feed_test_elements
33
+ @b.text_field(:id => 'f1').value.should eq 'Default text.'
34
+ @b.textarea(:id => 'f2').value.should eq "Default text.\n"
35
+ @b.radio(:id => 'f3').should_not be_set
36
+ @b.radio(:id => 'f4').should be_set
37
+ @b.checkbox(:id => 'f5').should_not be_set
38
+ @b.checkbox(:id => 'f6').should be_set
39
+ @b.select(:id => 'f10').value.should eq 'two (default)'
40
+ @b.select(:id => 'f11').value.should eq 'two (default)'
54
41
  end
55
42
  end
56
43
 
57
- context "argument = nil" do
58
- it "populates all xxx elements with :fresh_food" do
59
- tp = PageObjectWrapper.current_page
60
- tp.feed_test_elements
61
- @b.text_field(:id=>'f1').value.should eq 'default fresh food'
62
- @b.textarea(:id=>'f2').value.should eq 'default fresh food'
63
- @b.select(:id=>'f10').value.should eq "one"
64
- @b.select(:id=>'f11').value.should eq "one"
65
- @b.checkbox(:id=>'f5').should be_set
66
- @b.radio(:id=>'f3').should be_set
67
- end
68
- end
44
+ describe "basic usage" do
45
+ it "FEEDS elements which has provided menu" do
46
+ @tp.feed_test_elements(:loud)
47
+ @b.text_field(:id => 'f1').value.should eq 'tf food'
48
+ @b.textarea(:id => 'f2').value.should eq "ta food"
49
+ @b.radio(:id => 'f3').should be_set
50
+ @b.radio(:id => 'f4').should_not be_set
51
+ @b.checkbox(:id => 'f5').should be_set
52
+ @b.checkbox(:id => 'f6').should_not be_set
53
+ @b.select(:id => 'f10').value.should eq 'one'
54
+ @b.select(:id => 'f11').value.should eq 'one'
55
+ end
69
56
 
70
- context "argument = :missing_food" do
71
- it "populates all xxx elements with :missing_food" do
72
- tp = PageObjectWrapper.open_page(:some_test_page)
73
- tp.feed_test_elements(:missing_food)
74
- @b.text_field(:id=>'f1').value.should eq 'default missing food'
75
- @b.textarea(:id=>'f2').value.should eq 'default missing food'
76
- @b.select(:id=>'f10').value.should eq "three"
77
- @b.select(:id=>'f11').value.should eq "two (default)"
78
- @b.checkbox(:id=>'f5').should be_set
79
- @b.radio(:id=>'f3').should be_set
57
+ it "feeds ONLY elements which has provided menu" do
58
+ @tp.feed_test_elements(:quite)
59
+ @b.text_field(:id => 'f1').value.should eq 'Default text.'
60
+ @b.textarea(:id => 'f2').value.should eq "Default text.\n"
61
+ @b.radio(:id => 'f4').should be_set
62
+ @b.checkbox(:id => 'f6').should be_set
63
+ @b.select(:id => 'f11').value.should eq 'two (default)'
64
+ end
65
+
66
+ it "overrides defined menu when passing arguments" do
67
+ @tp.feed_test_elements(:loud, :tf => 'cheef menu', :rb1 => false, :rb2 => true, :cb2 => true, :s2 => 'three')
68
+ @b.text_field(:id => 'f1').value.should eq 'cheef menu'
69
+ @b.radio(:id => 'f4').should be_set
70
+ @b.checkbox(:id => 'f6').should be_set
71
+ @b.select(:id => 'f11').value.should eq 'three'
80
72
  end
81
- end
82
73
 
83
- context "food not found in select list" do
84
- it "continues execution" do
85
- atp = PageObjectWrapper.current_page
86
- atp.feed_test_elements(:missing_food).should eq(atp)
74
+ it "can be used without providing a menu" do
75
+ @tp.feed_test_elements(:tf => 'cheef menu', :rb2 => true, :cb2 => true, :s2 => 'three')
76
+ @b.text_field(:id => 'f1').value.should eq 'cheef menu'
77
+ @b.radio(:id => 'f4').should be_set
78
+ @b.checkbox(:id => 'f6').should be_set
79
+ @b.select(:id => 'f11').value.should eq 'three'
87
80
  end
88
81
  end
89
82
  end
@@ -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
@@ -22,13 +22,14 @@ elements_set("some elements_set label"):
22
22
  element(""):
23
23
  label "" not a Symbol
24
24
  locator nil not a meaningful Hash or String
25
- menu {:fresh_food=>[], :missing_food=>"default missing food"} not properly defined (must be {:food_type => \'a string\'})
25
+ menu {:fresh_food=>[]} not properly defined (must be { :food_type => \'a string\' | true | false })
26
26
  element(:e):
27
27
  element :e already defined
28
- menu {:fresh_food=>"default fresh food", :missing_food=>"default missing food", "a string"=>"another string"} not properly defined (must be {:food_type => \'a string\'})
28
+ menu {"a string"=>"another string"} not properly defined (must be { :food_type => \'a string\' | true | false })
29
29
  element(:e):
30
30
  element :e already defined
31
31
  locator {} not a meaningful Hash or String
32
+ menu {} not properly defined (must be { :food_type => \'a string\' | true | false })
32
33
  action(""):
33
34
  label "" not a Symbol
34
35
  next_page "a string" not a Symbol
@@ -42,13 +43,14 @@ validator(""):
42
43
  label "" not a Symbol
43
44
  table(""):
44
45
  label "" not a Symbol
45
- locator nil not a meaningful Hash
46
+ locator nil not a meaningful Hash or String
46
47
  table(:some_table):
47
- locator nil not a meaningful Hash
48
+ locator nil not a meaningful Hash or String
48
49
  header [] not a meaningful Array
49
50
  pagination(""):
50
51
  label "" not a Symbol
51
- locator "pagination locator" not a meaningful Hash
52
+ locator {} not a meaningful String
53
+ "1" not found in {}
52
54
  '
53
55
  end
54
56
  end
@@ -9,21 +9,17 @@ describe "getting food specified for element" do
9
9
 
10
10
  it{ should respond_to(:tf_menu) }
11
11
 
12
- it "tf_menu(:fresh_food)" do
13
- subject.tf_menu(:fresh_food).should eq 'default fresh food'
12
+ it "tf_menu(:loud)" do
13
+ subject.tf_menu(:loud).should eq 'tf food'
14
14
  end
15
- it "tf_menu(:missing_food)" do
16
- subject.tf_menu(:missing_food).should eq 'default missing food'
15
+ it "rb1(:quite)" do
16
+ subject.rb1_menu(:quite).should eq "false"
17
17
  end
18
- it "tf_menu(:user_defined)" do
19
- subject.tf_menu(:user_defined).should eq 'some food'
20
- end
21
- it "tf_menu(:unknown_food)" do
18
+ it "tf_menu(:unknown_menu)" do
22
19
  subject.tf_menu(:unknown_food).should eq ''
23
20
  end
24
- it "tf_menu('unknown_food')" do
21
+ it "s2_menu('unknown_food')" do
25
22
  subject.tf_menu(:unknown_food).should eq ''
26
23
  end
27
-
28
24
  end
29
25
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'page_object.each_xxx' do
4
+ context "browser is closed" do
5
+ it "raises PageObjectWrapper::BrowserNotFound" do
6
+ gp = PageObjectWrapper.receive_page(:google_pagination)
7
+ expect{ gp.pagination_each{ |p| puts p.inspect } }.to raise_error(PageObjectWrapper::BrowserNotFound)
8
+ end
9
+ end
10
+
11
+ context "browser is opened" do
12
+ before(:all){
13
+ @b = Watir::Browser.new
14
+ PageObjectWrapper.use_browser @b
15
+ }
16
+ after(:all){ PageObjectWrapper.browser.quit }
17
+
18
+ context "invalid locator" do
19
+ it "raises PageObjectWrapper::InvalidPagination" do
20
+ gip = PageObjectWrapper.open_page :google_invalid_pagination
21
+ expect{ gip.invalid_pagination_each{ |p| p.inspect }}.to raise_error PageObjectWrapper::InvalidPagination
22
+ end
23
+ end
24
+
25
+ context "invalid limit" do
26
+ it "raises PageObjectWrapper::InvalidPagination" do
27
+ gp = PageObjectWrapper.open_page :google_pagination
28
+ expect{ gp.pagination_each( :limit => -1 ){ |p| p.inspect }}.to raise_error PageObjectWrapper::InvalidPagination
29
+ end
30
+ end
31
+
32
+ context "correct parameters ( limit = 3 )" do
33
+ it "opens browser on subeach page and yields corresponding page_object" do
34
+ gp = PageObjectWrapper.open_page(:google_pagination)
35
+ counter = 0
36
+ gp.pagination_each( :limit => 3 ){ |subpage|
37
+ counter += 1
38
+ subpage.should be_a PageObject
39
+ subpage.validate_current_number?(counter).should be_true
40
+ }
41
+ yp = PageObjectWrapper.open_page(:yandex_pagination)
42
+ counter = 0
43
+ yp.pagination_each( :limit => 3 ){ |subpage|
44
+ counter += 1
45
+ subpage.should be_a PageObject
46
+ subpage.validate_current_number?(counter).should be_true
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'page_object.open_xxx' do
4
+ context "browser is closed" do
5
+ it "raises PageObjectWrapper::BrowserNotFound" do
6
+ gp = PageObjectWrapper.receive_page(:google_pagination)
7
+ expect{ gp.pagination_open 1 }.to raise_error(PageObjectWrapper::BrowserNotFound)
8
+ end
9
+ end
10
+
11
+ context "browser is opened" do
12
+ before(:all){
13
+ @b = Watir::Browser.new
14
+ PageObjectWrapper.use_browser @b
15
+ }
16
+ after(:all){ PageObjectWrapper.browser.quit }
17
+
18
+ context "invalid locator" do
19
+ it "raises PageObjectWrapper::InvalidPagination" do
20
+ gip = PageObjectWrapper.open_page :google_invalid_pagination
21
+ expect{ gip.invalid_pagination_open(1) }.to raise_error PageObjectWrapper::InvalidPagination
22
+ end
23
+ end
24
+
25
+ context "inappropriate number provided" do
26
+ it "raises Watir::Wait::TimeoutError" do
27
+ gp = PageObjectWrapper.open_page(:google_pagination)
28
+ expect{ gp.pagination_open(0)}.to raise_error Watir::Wait::TimeoutError
29
+ end
30
+ end
31
+
32
+ context "correct parameters" do
33
+ it "opens browser on provided subpage returns corresponding page_object" do
34
+ n = 10
35
+ yp = PageObjectWrapper.open_page(:yandex_pagination)
36
+ yp.pagination_open(n).should be_a PageObject
37
+ yp.validate_current_number?(n).should be_true
38
+ gp = PageObjectWrapper.open_page(:google_pagination)
39
+ gp.pagination_open(n).should be_a PageObject
40
+ gp.validate_current_number?(n).should be_true
41
+ end
42
+ end
43
+ end
44
+ end
@@ -25,11 +25,11 @@ describe "page_object.xxx" do
25
25
  its(:s2){ should be_a(Watir::Select) }
26
26
  its("s2.id"){ should eq 'f11' }
27
27
 
28
- its(:cb){ should be_a(Watir::CheckBox) }
29
- its("cb.id"){ should eq 'f5' }
28
+ its(:cb1){ should be_a(Watir::CheckBox) }
29
+ its("cb1.id"){ should eq 'f5' }
30
30
 
31
- its(:rb){ should be_a(Watir::Radio) }
32
- its("rb.id"){ should eq 'f3' }
31
+ its(:rb1){ should be_a(Watir::Radio) }
32
+ its("rb1.id"){ should eq 'f3' }
33
33
 
34
34
  its(:table_with_header){ should be_a(Watir::Table) }
35
35
  its("table_with_header.summary"){ should eq 'Each row names a Nordic country and specifies its total area and land area, in square kilometers' }
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.3.5
4
+ version: 1.3.6
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: 2012-12-29 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &14087000 !ruby/object:Gem::Requirement
16
+ requirement: &8082160 !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: *14087000
24
+ version_requirements: *8082160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &14086460 !ruby/object:Gem::Requirement
27
+ requirement: &8080940 !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: *14086460
35
+ version_requirements: *8080940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &14085880 !ruby/object:Gem::Requirement
38
+ requirement: &8079160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *14085880
46
+ version_requirements: *8079160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: debugger
49
- requirement: &14085340 !ruby/object:Gem::Requirement
49
+ requirement: &7571760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *14085340
57
+ version_requirements: *7571760
58
58
  description: Wraps watir-webdriver with convenient testing interface, based on PageObjects
59
59
  automation testing pattern. Simplifies resulting automated test understanding.
60
60
  email:
@@ -74,6 +74,7 @@ files:
74
74
  - good_pages/google_page.rb
75
75
  - good_pages/google_wrong_uniq_page.rb
76
76
  - good_pages/goole_as_page.rb
77
+ - good_pages/pagination_example_page.rb
77
78
  - good_pages/some_test_page.html
78
79
  - good_pages/some_test_page.rb
79
80
  - good_pages/test_table_page.rb
@@ -92,19 +93,18 @@ files:
92
93
  - lib/page_object_wrapper/known_elements.rb
93
94
  - lib/page_object_wrapper/version.rb
94
95
  - page_object_wrapper.gemspec
95
- - page_object_wrapper.gemspec.orig
96
96
  - spec/define_page_object_spec.rb
97
- - spec/each_xxx.rb
98
97
  - spec/feed_xxx_spec.rb
99
98
  - spec/fire_xxx_and_validate_xxx_spec.rb
100
99
  - spec/generate_spec.rb
101
100
  - spec/load_spec.rb
102
101
  - spec/menu_xxx_spec.rb
103
102
  - spec/open_page_spec.rb
104
- - spec/open_xxx.rb
105
103
  - spec/select_from_xxx_spec.rb
106
104
  - spec/shared_examples.rb
107
105
  - spec/spec_helper.rb
106
+ - spec/xxx_each.rb
107
+ - spec/xxx_open.rb
108
108
  - spec/xxx_spec.rb
109
109
  homepage: https://github.com/evgeniy-khatko/page_object_wrapper
110
110
  licenses: []
@@ -133,15 +133,15 @@ specification_version: 3
133
133
  summary: Wraps watir-webdriver with convenient testing interface.
134
134
  test_files:
135
135
  - spec/define_page_object_spec.rb
136
- - spec/each_xxx.rb
137
136
  - spec/feed_xxx_spec.rb
138
137
  - spec/fire_xxx_and_validate_xxx_spec.rb
139
138
  - spec/generate_spec.rb
140
139
  - spec/load_spec.rb
141
140
  - spec/menu_xxx_spec.rb
142
141
  - spec/open_page_spec.rb
143
- - spec/open_xxx.rb
144
142
  - spec/select_from_xxx_spec.rb
145
143
  - spec/shared_examples.rb
146
144
  - spec/spec_helper.rb
145
+ - spec/xxx_each.rb
146
+ - spec/xxx_open.rb
147
147
  - spec/xxx_spec.rb
@@ -1,27 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'page_object_wrapper/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = "page_object_wrapper"
8
- gem.version = PageObjectWrapper::VERSION
9
- gem.authors = ["Evgeniy Khatko"]
10
- gem.email = ["evgeniy.khatko@gmail.com"]
11
- gem.description = %q{Wraps watir-webdriver with convenient testing interface, based on PageObjects automation testing pattern. Simplifies resulting automated test understanding.}
12
- gem.summary = %q{Wraps watir-webdriver with convenient testing interface.}
13
- gem.homepage = "https://github.com/evgeniy-khatko/page_object_wrapper"
14
- gem.add_dependency "watir-webdriver"
15
- gem.add_dependency "activesupport"
16
- gem.add_development_dependency "rspec", ">= 2.0.0"
17
- <<<<<<< HEAD
18
- gem.add_development_dependency "debugger"
19
-
20
- =======
21
- >>>>>>> 3c944dcc705aa45b76ecda84a061beb9ee0ed4af
22
-
23
- gem.files = `git ls-files`.split($/)
24
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
25
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
- gem.require_paths = ["lib","lib/page_object_wrapper"]
27
- end
File without changes
File without changes