page_object_wrapper 1.3.4 → 1.3.5

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
@@ -44,64 +44,72 @@ optional arguments are enclosed with [ ]
44
44
 
45
45
  #### definition example
46
46
 
47
- PageObjectWrapper.define_page(:some_test_page) do
48
- locator 'http://www.cs.tut.fi/~jkorpela/www/testel.html'
49
- uniq_h1 :text => 'Testing display of HTML elements'
50
-
51
- elements_set(:test_elements) do
52
- text_field(:tf) do
53
- locator :id => 'f1'
54
- menu :user_defined, 'some food'
55
- end
56
-
57
- textarea(:ta) do
58
- locator :id => 'f2'
59
- end
60
-
61
- select(:s1) do
62
- locator :id => 'f10'
63
- menu :fresh_food, 'one'
64
- menu :missing_food, 'three'
65
- end
66
-
67
- select(:s2) do
68
- locator "form(:action => 'http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi').select(:id => 'f11')"
69
- menu :fresh_food, 'one'
70
- end
71
-
72
- checkbox(:cb){ locator :id => 'f5' }
73
- radio(:rb){ locator :id => 'f3' }
47
+ PageObjectWrapper.define_page(:some_test_page) do
48
+ #locator 'http://www.cs.tut.fi/~jkorpela/www/testel.html'
49
+ locator 'file://'+Dir.pwd+'/good_pages/some_test_page.html'
50
+ uniq_h1 :text => 'Testing display of HTML elements'
51
+
52
+ elements_set(:test_elements) do
53
+ text_field(:tf) do
54
+ locator :id => 'f1'
55
+ menu :user_defined, 'some food'
74
56
  end
75
57
 
76
- action(:press_cool_button, :test_page_with_table) do
77
- button(:name => 'foo').when_present.click
58
+ textarea(:ta) do
59
+ locator :id => 'f2'
60
+ end
61
+
62
+ select(:s1) do
63
+ locator :id => 'f10'
64
+ menu :fresh_food, 'one'
65
+ menu :missing_food, 'three'
78
66
  end
79
67
 
80
- action(:fill_textarea, :some_test_page) do |fill_with|
81
- data = (fill_with.nil?)? 'Default data' : fill_with
82
- textarea(:id => 'f2').set data
68
+ select(:s2) do
69
+ locator "form(:action => 'http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi').select(:id => 'f11')"
70
+ menu :fresh_food, 'one'
83
71
  end
84
72
 
85
- action_alias(:fill_textarea_alias, :some_test_page){ action :fill_textarea }
73
+ checkbox(:cb){ locator :id => 'f5' }
74
+ radio(:rb){ locator :id => 'f3' }
75
+ end
86
76
 
87
- table(:table_without_header) do
88
- locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
89
- end
77
+ action(:press_cool_button, :test_page_with_table) do
78
+ button(:name => 'foo').when_present.click
79
+ end
90
80
 
91
- table(:table_with_header) do
92
- locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
93
- header [:country, :total_area, :land_area]
94
- end
81
+ action(:fill_textarea, :some_test_page) do |fill_with|
82
+ data = (fill_with.nil?)? 'Default data' : fill_with
83
+ textarea(:id => 'f2').set data
84
+ end
95
85
 
96
- pagination(:some_pagination) do
97
- locator :xpath => ''
98
- end
86
+ action :fill_textarea_with_returned_value do |fill_with|
87
+ data = (fill_with.nil?)? 'Default data' : fill_with
88
+ textarea(:id => 'f2').set data
89
+ data
90
+ end
99
91
 
100
- validator(:textarea_value) do |expected|
101
- textarea(:id => 'f2').value == expected
102
- end
92
+ action_alias(:fill_textarea_alias, :some_test_page){ action :fill_textarea }
93
+ action_alias(:fill_textarea_with_returned_value_alias){ action :fill_textarea_with_returned_value }
94
+
95
+ table(:table_without_header) do
96
+ locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
103
97
  end
104
98
 
99
+ table(:table_with_header) do
100
+ locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
101
+ header [:country, :total_area, :land_area]
102
+ end
103
+
104
+ pagination(:some_pagination) do
105
+ locator :xpath => ''
106
+ end
107
+
108
+ validator(:textarea_value) do |expected|
109
+ textarea(:id => 'f2').value == expected
110
+ end
111
+ end
112
+
105
113
  here we have defined a page object with locator (url) = 'http://www.cs.tut.fi/~jkorpela/www/testel.html'
106
114
  - uniq\_xxx is used to define a uniq element on that page, which uniquely identifies the page from other pages
107
115
  - uniq\_xxx is being checked when openning the page with PageObjectWrapper.open\_page and when running an page\_object.action
@@ -210,9 +218,18 @@ next\_page from xxx action
210
218
  tp = PageObjectWrapper.current_page
211
219
  tp.fire_fill_textarea('User defined data')
212
220
 
213
- it "returns next_page":
214
- tp = PageObjectWrapper.current_page
215
- np = tp.fire_press_cool_button
221
+ context "next_page == nil":
222
+ it "returns action returned value":
223
+ tp = PageObjectWrapper.current_page
224
+ data = tp.fire_fill_textarea_with_returned_value('data to fill with')
225
+ tp.validate_textarea_value(data).should be(true)
226
+
227
+ context "next_page not nil":
228
+ it "returns next_page":
229
+ tp = PageObjectWrapper.current_page
230
+ np = tp.fire_press_cool_button
231
+ np.should be_a(PageObject)
232
+ np.label_value.should eq(:test_page_with_table)
216
233
 
217
234
  context "xxx is alias":
218
235
  it "executes corresponding action":
@@ -273,6 +290,12 @@ correct arguments are:
273
290
  it "returns nil":
274
291
  tp.select_from_table_without_header(:column_0, :column_1 => /123/).should eq nil
275
292
  tp.select_from_table_with_header(:country, :total_area => /123/).should eq nil
293
+ context "found by row number":
294
+ it "returns found cells":
295
+ tp.select_from_table_without_header(:column_0, :row => 2).text.should eq 'Iceland'
296
+ tp.select_from_table_with_header(:country, :row => 3).text.should eq 'Norway'
297
+ it "returns nil":
298
+ tp.select_from_table_with_header(:country, :row => 123).should eq nil
276
299
 
277
300
  context "next_page specified":
278
301
  context "found by String":
@@ -281,6 +304,12 @@ correct arguments are:
281
304
  context "not found by String":
282
305
  it "returns nil":
283
306
  tp.select_from_table_without_header(:column_0, {:column_1 => '123'}, :some_test_page).should eq nil
307
+ context "found by row number":
308
+ it "returns found cells":
309
+ tp.select_from_table_without_header(:column_0, {:row => 2}, :some_test_page).should eq PageObjectWrapper.receive_page(:some_test_page)
310
+ tp.select_from_table_with_header(:country, {:row => 3}, :some_test_page).should eq PageObjectWrapper.receive_page(:some_test_page)
311
+ it "returns nil":
312
+ tp.select_from_table_with_header(:country, {:row => 123}, :some_test_page).should eq nil
284
313
 
285
314
  #### each\_xxx
286
315
  TODO
@@ -20,13 +20,13 @@ PageObjectWrapper.define_page('some_page_with_lost_of_errors') do
20
20
  end
21
21
  end
22
22
 
23
- action('',nil) do
23
+ action('','a string') do
24
24
  end
25
25
 
26
26
  validator('') do
27
27
  end
28
28
 
29
- action_alias('',nil){ action 'unknown action'}
29
+ action_alias('','a string'){ action 'unknown action'}
30
30
 
31
31
  table('') do
32
32
  end
@@ -37,7 +37,14 @@ PageObjectWrapper.define_page(:some_test_page) do
37
37
  textarea(:id => 'f2').set data
38
38
  end
39
39
 
40
+ action :fill_textarea_with_returned_value do |fill_with|
41
+ data = (fill_with.nil?)? 'Default data' : fill_with
42
+ textarea(:id => 'f2').set data
43
+ data
44
+ end
45
+
40
46
  action_alias(:fill_textarea_alias, :some_test_page){ action :fill_textarea }
47
+ action_alias(:fill_textarea_with_returned_value_alias){ action :fill_textarea_with_returned_value }
41
48
 
42
49
  table(:table_without_header) do
43
50
  locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
@@ -2,7 +2,7 @@ require 'Dsl'
2
2
  class Action < DslElement
3
3
  attr_reader :fire_block_value, :next_page_value
4
4
 
5
- def initialize(label, next_page, &block)
5
+ def initialize(label, next_page=nil, &block)
6
6
  super label
7
7
  @next_page_value = next_page
8
8
  @fire_block_value = block
@@ -195,13 +195,13 @@ class PageObject < DslElementWithLocator
195
195
  eset
196
196
  end
197
197
 
198
- def action(label, next_page, &block)
198
+ def action(label, next_page=nil, &block)
199
199
  a = Action.new(label, next_page, &block)
200
200
  @actions << a
201
201
  a
202
202
  end
203
203
 
204
- def action_alias(label, next_page, &block)
204
+ def action_alias(label, next_page=nil, &block)
205
205
  a = Alias.new(label, next_page)
206
206
  a.instance_eval(&block)
207
207
  @aliases << a
@@ -256,8 +256,10 @@ class PageObject < DslElementWithLocator
256
256
  action_output = []
257
257
  action_output << "\taction #{a.label_value.inspect} already defined\n" if labeled(@actions).count(a.label_value) > 1
258
258
  action_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
259
- action_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
260
- action_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
259
+ if not a.next_page_value.nil?
260
+ action_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
261
+ action_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
262
+ end
261
263
  action_output << "\tfire event is not a Proc\n" if not a.fire_block_value.is_a?(Proc)
262
264
  action_output.unshift "action(#{a.label_value.inspect}):\n" if not action_output.empty?
263
265
  output += action_output
@@ -266,8 +268,10 @@ class PageObject < DslElementWithLocator
266
268
  alias_output = []
267
269
  alias_output << "\talias #{a.label_value.inspect} already defined\n" if labeled(@aliases).count(a.label_value) > 1
268
270
  alias_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
269
- alias_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
270
- alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
271
+ if not a.next_page_value.nil?
272
+ alias_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
273
+ alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
274
+ end
271
275
  alias_output << "\taction #{a.action_value.inspect} not known Action\n" if not labeled(@actions).include? a.action_value
272
276
  alias_output.unshift "alias(#{a.label_value.inspect}):\n" if not alias_output.empty?
273
277
  output += alias_output
@@ -358,9 +362,13 @@ private
358
362
  def fire_action(a, *args)
359
363
  raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
360
364
  block = (a.is_a? Action)? a.fire_block_value : action_for(a.action_value).fire_block_value
361
- @@browser.instance_exec *args, &block
362
- self.class.map_current_page a.next_page_value
363
- @@current_page
365
+ block_result = @@browser.instance_exec *args, &block
366
+ if not a.next_page_value.nil?
367
+ self.class.map_current_page a.next_page_value
368
+ return @@current_page
369
+ else
370
+ return block_result
371
+ end
364
372
  end
365
373
 
366
374
  def run_validator(v, *args)
@@ -1,3 +1,3 @@
1
1
  module PageObjectWrapper
2
- VERSION = "1.3.4"
2
+ VERSION = "1.3.5"
3
3
  end
@@ -34,20 +34,32 @@ describe "page_object.fire_xxx" do
34
34
  tp.validate_textarea_value('User defined data').should be(true)
35
35
  end
36
36
 
37
+ context "next_page == nil" do
38
+ it "returns action returned value" do
39
+ tp = PageObjectWrapper.current_page
40
+ data = tp.fire_fill_textarea_with_returned_value('data to fill with')
41
+ tp.validate_textarea_value(data).should be(true)
42
+ end
43
+ end
44
+
45
+ context "next_page not nil" do
46
+ it "returns next_page" do
47
+ tp = PageObjectWrapper.current_page
48
+ np = tp.fire_press_cool_button
49
+ np.should be_a(PageObject)
50
+ np.label_value.should eq(:test_page_with_table)
51
+ end
52
+ end
53
+
37
54
  context "xxx is alias" do
38
55
  it "executes corresponding action" do
39
56
  tp = PageObjectWrapper.open_page(:some_test_page)
40
57
  tp.fire_fill_textarea_alias
41
58
  tp.validate_textarea_value('Default data').should be(true)
59
+ data = tp.fire_fill_textarea_with_returned_value_alias('data to fill with')
60
+ tp.validate_textarea_value(data).should be(true)
42
61
  end
43
62
  end
44
63
 
45
- it "returns next_page" do
46
- tp = PageObjectWrapper.current_page
47
- np = tp.fire_press_cool_button
48
- np.should be_a(PageObject)
49
- np.label_value.should eq(:test_page_with_table)
50
- end
51
-
52
64
  end
53
65
  end
data/spec/load_spec.rb CHANGED
@@ -31,12 +31,12 @@ elements_set("some elements_set label"):
31
31
  locator {} not a meaningful Hash or String
32
32
  action(""):
33
33
  label "" not a Symbol
34
- next_page nil not a Symbol
35
- next_page nil unknown page_object
34
+ next_page "a string" not a Symbol
35
+ next_page "a string" unknown page_object
36
36
  alias(""):
37
37
  label "" not a Symbol
38
- next_page nil not a Symbol
39
- next_page nil unknown page_object
38
+ next_page "a string" not a Symbol
39
+ next_page "a string" unknown page_object
40
40
  action "unknown action" not known Action
41
41
  validator(""):
42
42
  label "" not a Symbol
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.4
4
+ version: 1.3.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: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &14274520 !ruby/object:Gem::Requirement
16
+ requirement: &14087000 !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: *14274520
24
+ version_requirements: *14087000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &14221140 !ruby/object:Gem::Requirement
27
+ requirement: &14086460 !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: *14221140
35
+ version_requirements: *14086460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &14166080 !ruby/object:Gem::Requirement
38
+ requirement: &14085880 !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: *14166080
46
+ version_requirements: *14085880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: debugger
49
- requirement: &14146280 !ruby/object:Gem::Requirement
49
+ requirement: &14085340 !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: *14146280
57
+ version_requirements: *14085340
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: