Skip to content

Commit

Permalink
super called when factory method invoked with non PageObject class
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezy committed Feb 26, 2014
1 parent 583eaf2 commit 7de1143
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
=== Version 0.9.7
* Enhancements
* super called when factory method invoked with non PageObject class
* Updated to use the latest watir-webdriver 0.6.8
* Updated to use the latest selenium-webdriver 2.40.0

Expand Down
1 change: 1 addition & 0 deletions lib/page-object/page_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def visit_page(page_class, params={:using_params => {}}, &block)
#
def on_page(page_class, params={:using_params => {}}, visit=false, &block)
page_class = class_from_string(page_class) if page_class.is_a? String
return super(page_class, params, visit, &block) unless page_class.ancestors.include? PageObject
merged = page_class.params.merge(params[:using_params])
page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
@current_page = page_class.new(@browser, visit)
Expand Down
25 changes: 20 additions & 5 deletions spec/page-object/page_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ class YetAnotherPage
end

module ContainingModule
class PageInsideModule
include PageObject
page_url "http://google.co.uk"
end
class PageInsideModule
include PageObject
page_url "http://google.co.uk"
end
end

class WorldSuper
attr_reader :super_called
def on_page(cls, params={}, visit=false, &block)
@super_called = true
end
end

class TestWorld

class TestWorld < WorldSuper
include PageObject::PageFactory
attr_accessor :browser
attr_accessor :current_page
Expand All @@ -38,6 +46,13 @@ class TestWorld
@world.browser = mock_watir_browser
end

it "should call super when non page-object class passed " do
class NoPO
end
@world.on(NoPO)
@world.super_called.should be_true
end

it "should create a new page object and execute a block" do
@world.browser.should_not_receive(:goto)
@world.on_page FactoryTestPage do |page|
Expand Down

0 comments on commit 7de1143

Please sign in to comment.