page-object 0.7.4 → 0.7.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/.rvmrc CHANGED
@@ -1 +1,2 @@
1
- rvm 1.9.3-p194@page-object --create
1
+ rvm --create use 1.9.3-p194@page-object
2
+
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ === Version 0.7.5 / 2012-10-14
2
+ * Enhancements
3
+ * Enhanced TabeleCell to return nil when there is no corresponding cell for a referenced column
4
+ * Added css selector support for SelectList and Div
5
+ * Added ability to pass clasname as string to visit_page, on_page, and if_page methods
6
+ * Added params class instance variable to hold hash values that can be used in the page
7
+ * Added ability to insert ERB into page_url string and have it access params
8
+
1
9
  === Version 0.7.4 / 2012-9-8
2
10
  * Enhancements
3
11
  * Added ability to find text_fields with :css when using Selenium
data/features/div.feature CHANGED
@@ -29,6 +29,15 @@ Feature: Div
29
29
  | text |
30
30
  | title |
31
31
 
32
+ @selenium_only
33
+ Scenario Outline: Locating divs on the page
34
+ When I search for the div by "<search_by>"
35
+ Then the text should be "page-object rocks!"
36
+
37
+ Scenarios:
38
+ | search_by |
39
+ | css |
40
+
32
41
  Scenario Outline: Locating divs using multiple parameters
33
42
  When I search for the div by "<param1>" and "<param2>"
34
43
  Then the text should be "page-object rocks!"
@@ -100,6 +100,9 @@
100
100
  <td>Data3</td>
101
101
  <td>Data4</td>
102
102
  </tr>
103
+ <tr>
104
+ <td>Data5</td>
105
+ </tr>
103
106
  </tbody>
104
107
  </table>
105
108
 
@@ -24,6 +24,17 @@ Feature: Select List
24
24
  | xpath |
25
25
  | index |
26
26
 
27
+ @selenium_only
28
+ Scenario Outline: Locating select lists on the Page using Selenium
29
+ When I search for the select list by "<search_by>"
30
+ Then I should be able to select "Test 2"
31
+ And the value for the selected item should be "Test 2"
32
+ And the value for the option should be "option2"
33
+
34
+ Examples:
35
+ | search_by |
36
+ | css |
37
+
27
38
  Scenario Outline: Locating a select list using multiple parameters
28
39
  When I search for the select list by "<param1>" and "<param2>"
29
40
  Then I should be able to select "Test 2"
@@ -20,7 +20,5 @@ When /^I select a link while the script is executing$/ do
20
20
  end
21
21
 
22
22
  Then /^I should see that the link exists$/ do
23
- require 'ruby-debug'
24
- debugger
25
23
  @page.link_id?.should == true
26
24
  end
@@ -60,6 +60,7 @@ class Page
60
60
 
61
61
  select_list(:sel_list_id, :id => "sel_list_id")
62
62
  select_list(:sel_list_class, :class => "sel_list_class")
63
+ select_list(:sel_list_css, :css => ".sel_list_class")
63
64
  select_list(:sel_list_index, :index => 0)
64
65
  select_list(:sel_list_name, :name => "sel_list_name")
65
66
  select_list(:sel_list_value, :value => "option1")
@@ -98,6 +99,7 @@ class Page
98
99
  div(:div_title, :title => 'div_title')
99
100
  div(:div_class_index, :class => "div_class", :index => 0)
100
101
  div(:div_name_index, :name => "div_name", :index => 0)
102
+ div(:div_css, :css => ".div_class")
101
103
 
102
104
  span(:span_id, :id => 'span_id')
103
105
  span(:span_name, :name => 'span_name')
@@ -70,6 +70,10 @@ Feature: Table
70
70
  When I retrieve a table element
71
71
  Then the data for row "Data3" and column "Data20" should be nil
72
72
 
73
+ Scenario: Retrieve data from a table that does not have a cell which corresponds to a column header
74
+ When I retrieve a table with thead element
75
+ Then the data for row "Data5" and column "Col2" should be nil
76
+
73
77
  Scenario Outline: Locating table cells on the Page
74
78
  When I retrieve a table element by "<search_by>"
75
79
  Then the data for row "1" should be "Data1" and "Data2"
@@ -1,3 +1,5 @@
1
+ require 'erb'
2
+
1
3
  module PageObject
2
4
  #
3
5
  # Contains the class level methods that are inserted into your page objects
@@ -9,6 +11,24 @@ module PageObject
9
11
  #
10
12
  module Accessors
11
13
 
14
+ #
15
+ # Set some values that can be used withing the class. This is
16
+ # typically used to provide values that help build dynamic urls in
17
+ # the page_url method
18
+ #
19
+ # @param [Hash] the value to set the params
20
+ #
21
+ def params=(the_params)
22
+ @params = the_params
23
+ end
24
+
25
+ #
26
+ # Return the params that exist on this page class
27
+ #
28
+ def params
29
+ @params ||= {}
30
+ end
31
+
12
32
  #
13
33
  # Specify the url for the page. A call to this method will generate a
14
34
  # 'goto' method to take you to the page.
@@ -19,7 +39,10 @@ module PageObject
19
39
  def page_url(url)
20
40
  define_method("goto") do
21
41
  url = url.kind_of?(Symbol) ? self.send(url) : url
22
- platform.navigate_to url
42
+ erb = ERB.new(%Q{#{url}})
43
+ merged_params = self.class.instance_variable_get("@merged_params")
44
+ params = merged_params ? merged_params : self.class.params
45
+ platform.navigate_to erb.result(binding)
23
46
  end
24
47
  end
25
48
  alias_method :direct_url, :page_url
@@ -221,6 +244,7 @@ module PageObject
221
244
  # @param [Hash] identifier how we find a select list. You can use a multiple paramaters
222
245
  # by combining of any of the following except xpath. The valid keys are:
223
246
  # * :class => Watir and Selenium
247
+ # * :css => Selenium only
224
248
  # * :id => Watir and Selenium
225
249
  # * :index => Watir and Selenium
226
250
  # * :name => Watir and Selenium
@@ -437,6 +461,7 @@ module PageObject
437
461
  # @param [Hash] identifier how we find a div. You can use a multiple paramaters
438
462
  # by combining of any of the following except xpath. The valid keys are:
439
463
  # * :class => Watir and Selenium
464
+ # * :css => Selenium only
440
465
  # * :id => Watir and Selenium
441
466
  # * :index => Watir and Selenium
442
467
  # * :name => Watir and Selenium
@@ -9,7 +9,7 @@ module PageObject
9
9
  end
10
10
 
11
11
  def self.selenium_finders
12
- super + [:text, :title]
12
+ super + [:text, :title, :css]
13
13
  end
14
14
 
15
15
  end
@@ -18,6 +18,10 @@ module PageObject
18
18
  super + [:text, :value]
19
19
  end
20
20
 
21
+ def self.selenium_finders
22
+ super + [:css]
23
+ end
24
+
21
25
  def include_platform_for platform
22
26
  super
23
27
  if platform[:platform] == :watir_webdriver
@@ -35,11 +35,14 @@ module PageObject
35
35
  # Create and navigate to a page object. The navigation will only work if the
36
36
  # 'page_url' method was call on the page object.
37
37
  #
38
- # @param [PageObject] a class that has included the PageObject module
38
+ # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
39
39
  # @param an optional block to be called
40
40
  # @return [PageObject] the newly created page object
41
41
  #
42
- def visit_page(page_class, &block)
42
+ def visit_page(page_class, params={:using_params => {}}, &block)
43
+ page_class = class_from_string(page_class) if page_class.is_a? String
44
+ merged = page_class.params.merge(params[:using_params])
45
+ page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
43
46
  on_page page_class, true, &block
44
47
  end
45
48
 
@@ -49,12 +52,13 @@ module PageObject
49
52
  #
50
53
  # Create a page object.
51
54
  #
52
- # @param [PageObject] a class that has included the PageObject module
55
+ # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
53
56
  # @param [Boolean] a boolean indicating if the page should be visited? default is false.
54
57
  # @param [block] an optional block to be called
55
58
  # @return [PageObject] the newly created page object
56
59
  #
57
60
  def on_page(page_class, visit=false, &block)
61
+ page_class = class_from_string(page_class) if page_class.is_a? String
58
62
  @current_page = page_class.new(@browser, visit)
59
63
  block.call @current_page if block
60
64
  @current_page
@@ -66,11 +70,12 @@ module PageObject
66
70
  #
67
71
  # Create a page object if and only if the current page is the same page to be created
68
72
  #
69
- # @param [PageObject] a class that has included the PageObject module
73
+ # @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
70
74
  # @param [block] an optional block to be called
71
75
  # @return [PageObject] the newly created page object
72
76
  #
73
77
  def if_page(page_class, &block)
78
+ page_class = class_from_string(page_class) if page_class.is_a? String
74
79
  return @current_page unless @current_page.class == page_class
75
80
  on_page(page_class, false, &block)
76
81
  end
@@ -128,7 +133,13 @@ module PageObject
128
133
  end
129
134
 
130
135
  private
131
-
136
+
137
+ def class_from_string(str)
138
+ str.split('::').inject(Object) do |mod, class_name|
139
+ mod.const_get(class_name)
140
+ end
141
+ end
142
+
132
143
  def path_for(how)
133
144
  path = PageObject::PageFactory.page_object_routes[how[:using]]
134
145
  fail("PageFactory route :#{how[:using].to_s} not found") unless path
@@ -13,7 +13,7 @@ module PageObject
13
13
  def [](idx)
14
14
  els = table_cells
15
15
  idx = find_index_by_title(idx) if idx.kind_of?(String)
16
- return nil unless idx
16
+ return nil unless idx && columns >= idx + 1
17
17
  Object::PageObject::Elements::TableCell.new(els[idx], :platform => :selenium_webdriver)
18
18
  end
19
19
 
@@ -11,7 +11,7 @@ module PageObject
11
11
  #
12
12
  def [](idx)
13
13
  idx = find_index_by_title(idx) if idx.kind_of?(String)
14
- return nil unless idx
14
+ return nil unless idx && columns >= idx + 1
15
15
  Object::PageObject::Elements::TableCell.new(element[idx], :platform => :watir_webdriver)
16
16
  end
17
17
 
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.7.4"
3
+ VERSION = "0.7.5"
4
4
  end
data/pageobject.gems ADDED
@@ -0,0 +1 @@
1
+ bundler
@@ -14,6 +14,7 @@ describe PageObject::Elements::TableRow do
14
14
  context "for selenium" do
15
15
  it "should return a table cell when indexed" do
16
16
  table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :selenium_webdriver)
17
+ table_row.stub(:columns).and_return(2)
17
18
  table_row_driver.should_receive(:find_elements).with(:xpath, ".//child::td|th").and_return(table_cell)
18
19
  table_cell.should_receive(:[]).and_return(table_cell)
19
20
  table_row[0].should be_instance_of PageObject::Elements::TableCell
@@ -43,6 +44,7 @@ describe PageObject::Elements::TableRow do
43
44
 
44
45
  it "should return a table cell when indexed" do
45
46
  table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir_webdriver)
47
+ table_row.stub(:columns).and_return(2)
46
48
  table_row_driver.should_receive(:[]).with(1).and_return(table_cell)
47
49
  table_row[1].should be_instance_of PageObject::Elements::TableCell
48
50
  end
@@ -13,7 +13,7 @@ describe PageObject do
13
13
  let(:watir_page_object) { PageObjectTestPageObject.new(watir_browser) }
14
14
  let(:selenium_page_object) { PageObjectTestPageObject.new(selenium_browser) }
15
15
 
16
- context "setting values for the Javascript Framework" do
16
+ context "setting values on the PageObject module" do
17
17
  it "should set the javascript framework" do
18
18
  PageObject::JavascriptFrameworkFacade.should_receive(:framework=)
19
19
  PageObject.javascript_framework = :foo
@@ -23,8 +23,58 @@ describe PageObject do
23
23
  PageObject::JavascriptFrameworkFacade.should_receive(:add_framework)
24
24
  PageObject.add_framework(:foo, :bar)
25
25
  end
26
+
27
+ it "should set a default page wait value" do
28
+ PageObject.default_page_wait = 20
29
+ wait = PageObject.instance_variable_get("@page_wait")
30
+ wait.should == 20
31
+ end
32
+
33
+ it "should provide the default page wait value" do
34
+ PageObject.instance_variable_set("@page_wait", 10)
35
+ PageObject.default_page_wait.should == 10
36
+ end
37
+
38
+ it "should default the page wait value to 30" do
39
+ PageObject.instance_variable_set("@page_wait", nil)
40
+ PageObject.default_page_wait.should == 30
41
+ end
42
+
43
+ it "should set the default element wait value" do
44
+ PageObject.default_element_wait = 20
45
+ wait = PageObject.instance_variable_get("@element_wait")
46
+ wait.should == 20
47
+ end
48
+
49
+ it "should provide the default element wait value" do
50
+ PageObject.instance_variable_set("@element_wait", 10)
51
+ PageObject.default_element_wait.should == 10
52
+ end
53
+
54
+ it "should default the element wait to 5" do
55
+ PageObject.instance_variable_set("@element_wait", nil)
56
+ PageObject.default_element_wait.should == 5
57
+ end
26
58
  end
27
-
59
+
60
+ context "setting values on the PageObject class instance" do
61
+ it "should set the params value" do
62
+ PageObjectTestPageObject.params = {:some => :value}
63
+ params = PageObjectTestPageObject.instance_variable_get("@params")
64
+ params[:some].should == :value
65
+ end
66
+
67
+ it "should provide the params value" do
68
+ PageObjectTestPageObject.instance_variable_set("@params", {:value => :updated})
69
+ PageObjectTestPageObject.params[:value].should == :updated
70
+ end
71
+
72
+ it "should default the params to an empty hash" do
73
+ PageObjectTestPageObject.instance_variable_set("@params", nil)
74
+ PageObjectTestPageObject.params.should == {}
75
+ end
76
+ end
77
+
28
78
  context "when created with a watir-webdriver browser" do
29
79
  it "should include the WatirPageObject module" do
30
80
  watir_page_object.platform.should be_kind_of PageObject::Platforms::WatirWebDriver::PageObject
@@ -19,6 +19,13 @@ class YetAnotherPage
19
19
  include PageObject
20
20
  end
21
21
 
22
+ module ContainingModule
23
+ class PageInsideModule
24
+ include PageObject
25
+ page_url "http://google.co.uk"
26
+ end
27
+ end
28
+
22
29
  class TestWorld
23
30
  include PageObject::PageFactory
24
31
  attr_accessor :browser
@@ -36,6 +43,12 @@ describe PageObject::PageFactory do
36
43
  @world.on_page FactoryTestPage do |page|
37
44
  page.should be_instance_of FactoryTestPage
38
45
  end
46
+ @world.on_page "FactoryTestPage" do |page|
47
+ page.should be_instance_of FactoryTestPage
48
+ end
49
+ @world.on_page "ContainingModule::PageInsideModule" do |page|
50
+ page.should be_instance_of ContainingModule::PageInsideModule
51
+ end
39
52
  end
40
53
 
41
54
  it "should create a new page object and execute a block using 'on'" do
@@ -43,20 +56,65 @@ describe PageObject::PageFactory do
43
56
  @world.on FactoryTestPage do |page|
44
57
  page.should be_instance_of FactoryTestPage
45
58
  end
59
+ @world.on "FactoryTestPage" do |page|
60
+ page.should be_instance_of FactoryTestPage
61
+ end
62
+ @world.on "ContainingModule::PageInsideModule" do |page|
63
+ page.should be_instance_of ContainingModule::PageInsideModule
64
+ end
46
65
  end
47
66
 
48
67
  it "should create and visit a new page" do
49
- @world.browser.should_receive(:goto)
68
+ @world.browser.should_receive(:goto).exactly(3).times
50
69
  @world.visit_page FactoryTestPage do |page|
51
70
  page.should be_instance_of FactoryTestPage
52
71
  end
72
+ @world.visit_page "FactoryTestPage" do |page|
73
+ page.should be_instance_of FactoryTestPage
74
+ end
75
+ @world.visit_page "ContainingModule::PageInsideModule" do |page|
76
+ page.should be_instance_of ContainingModule::PageInsideModule
77
+ end
53
78
  end
54
79
 
55
- it "should create and visit a new page using 'visit'" do
80
+ it "should merge params with the class level params if provided when visiting" do
56
81
  @world.browser.should_receive(:goto)
82
+ FactoryTestPage.params = {:initial => :value}
83
+ @world.visit_page(FactoryTestPage, :using_params => {:new_value => :merged})
84
+ merged = FactoryTestPage.instance_variable_get("@merged_params")
85
+ merged[:initial].should == :value
86
+ merged[:new_value].should == :merged
87
+ end
88
+
89
+ it "should use the params in the url when they are provided" do
90
+ class PageUsingParams
91
+ include PageObject
92
+ page_url "http://google.com/<%=params[:value]%>"
93
+ end
94
+ @world.browser.should_receive(:goto).with("http://google.com/PageObject")
95
+ @world.visit_page(PageUsingParams, :using_params => {:value => 'PageObject'})
96
+ end
97
+
98
+ it "should use the params as well as interpolated values" do
99
+ class PageUsingParmsAndInterpolated
100
+ include PageObject
101
+ page_url "http://google.com/#{1+2}/<%=params[:value]%>"
102
+ end
103
+ @world.browser.should_receive(:goto).with("http://google.com/3/PageObject")
104
+ @world.visit_page(PageUsingParmsAndInterpolated, :using_params => {:value => 'PageObject'})
105
+ end
106
+
107
+ it "should create and visit a new page using 'visit'" do
108
+ @world.browser.should_receive(:goto).exactly(3).times
57
109
  @world.visit FactoryTestPage do |page|
58
110
  page.should be_instance_of FactoryTestPage
59
111
  end
112
+ @world.visit "FactoryTestPage" do |page|
113
+ page.should be_instance_of FactoryTestPage
114
+ end
115
+ @world.visit "ContainingModule::PageInsideModule" do |page|
116
+ page.should be_instance_of ContainingModule::PageInsideModule
117
+ end
60
118
  end
61
119
 
62
120
  it "should create and visit a new page when url is defined as 'direct_url'" do
@@ -77,19 +135,46 @@ describe PageObject::PageFactory do
77
135
  @world.if_page(FactoryTestPage) do |page|
78
136
  fail
79
137
  end
138
+ @world.if_page("FactoryTestPage") do |page|
139
+ fail
140
+ end
141
+ @world.if_page("ContainingModule::PageInsideModule") do |page|
142
+ fail
143
+ end
80
144
  end
81
145
 
82
146
  it "should return the @current_page if asking for another page" do
83
147
  expected = TestPageWithDirectUrl.new(@world.browser)
84
148
  @world.instance_variable_set "@current_page", expected
85
149
  @world.if_page(FactoryTestPage).should == expected
150
+ @world.if_page("FactoryTestPage").should == expected
151
+ @world.if_page("ContainingModule::PageInsideModule").should == expected
86
152
  end
87
153
 
88
154
  it "should execute the block when we ask if it is the correct page" do
89
155
  @world.instance_variable_set "@current_page", FactoryTestPage.new(@world.browser)
156
+
157
+ done = false
90
158
  @world.if_page(FactoryTestPage) do |page|
91
159
  page.should be_instance_of FactoryTestPage
160
+ done = true
161
+ end
162
+ done.should be true
163
+
164
+ done = false
165
+ @world.if_page("FactoryTestPage") do |page|
166
+ page.should be_instance_of FactoryTestPage
167
+ done = true
168
+ end
169
+ done.should be true
170
+
171
+ done = false
172
+ @world.instance_variable_set "@current_page", ContainingModule::PageInsideModule.new(@world.browser)
173
+ @world.if_page("ContainingModule::PageInsideModule") do |page|
174
+ page.should be_instance_of ContainingModule::PageInsideModule
175
+ done = true
92
176
  end
177
+ done.should be true
93
178
  end
94
179
 
95
180
  it "should raise an error when you do not provide a default route" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page-object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
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: 2012-09-08 00:00:00.000000000 Z
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
@@ -315,6 +315,7 @@ files:
315
315
  - lib/page-object/platforms/watir_webdriver/unordered_list.rb
316
316
  - lib/page-object/version.rb
317
317
  - page-object.gemspec
318
+ - pageobject.gems
318
319
  - spec/page-object/element_locators_spec.rb
319
320
  - spec/page-object/elements/area_spec.rb
320
321
  - spec/page-object/elements/button_spec.rb
@@ -334,15 +335,15 @@ files:
334
335
  - spec/page-object/elements/option_spec.rb
335
336
  - spec/page-object/elements/ordered_list_spec.rb
336
337
  - spec/page-object/elements/paragraph_spec.rb
337
- - spec/page-object/elements/radio_button_spec.rb
338
338
  - spec/page-object/elements/select_list_spec.rb
339
+ - spec/page-object/elements/selenium/radio_button_spec.rb
340
+ - spec/page-object/elements/selenium/text_field_spec.rb
339
341
  - spec/page-object/elements/selenium_element_spec.rb
340
342
  - spec/page-object/elements/span_spec.rb
341
343
  - spec/page-object/elements/table_cell_spec.rb
342
344
  - spec/page-object/elements/table_row_spec.rb
343
345
  - spec/page-object/elements/table_spec.rb
344
346
  - spec/page-object/elements/text_area_spec.rb
345
- - spec/page-object/elements/text_field_spec.rb
346
347
  - spec/page-object/elements/unordered_list_spec.rb
347
348
  - spec/page-object/elements/watir_element_spec.rb
348
349
  - spec/page-object/javascript_framework_facade_spec.rb
@@ -370,7 +371,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
370
371
  version: '0'
371
372
  segments:
372
373
  - 0
373
- hash: -734083501090794232
374
+ hash: 1948566073686422532
374
375
  required_rubygems_version: !ruby/object:Gem::Requirement
375
376
  none: false
376
377
  requirements:
@@ -379,7 +380,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
379
380
  version: '0'
380
381
  segments:
381
382
  - 0
382
- hash: -734083501090794232
383
+ hash: 1948566073686422532
383
384
  requirements: []
384
385
  rubyforge_project: page-object
385
386
  rubygems_version: 1.8.24
@@ -517,15 +518,15 @@ test_files:
517
518
  - spec/page-object/elements/option_spec.rb
518
519
  - spec/page-object/elements/ordered_list_spec.rb
519
520
  - spec/page-object/elements/paragraph_spec.rb
520
- - spec/page-object/elements/radio_button_spec.rb
521
521
  - spec/page-object/elements/select_list_spec.rb
522
+ - spec/page-object/elements/selenium/radio_button_spec.rb
523
+ - spec/page-object/elements/selenium/text_field_spec.rb
522
524
  - spec/page-object/elements/selenium_element_spec.rb
523
525
  - spec/page-object/elements/span_spec.rb
524
526
  - spec/page-object/elements/table_cell_spec.rb
525
527
  - spec/page-object/elements/table_row_spec.rb
526
528
  - spec/page-object/elements/table_spec.rb
527
529
  - spec/page-object/elements/text_area_spec.rb
528
- - spec/page-object/elements/text_field_spec.rb
529
530
  - spec/page-object/elements/unordered_list_spec.rb
530
531
  - spec/page-object/elements/watir_element_spec.rb
531
532
  - spec/page-object/javascript_framework_facade_spec.rb