Skip to content
Browse files

added params hash as new page class variable

  • Loading branch information...
1 parent f4fffd2 commit d26a177b678836b198b63330ae164972fcef6a67 @cheezy committed Oct 14, 2012
Showing with 71 additions and 2 deletions.
  1. +1 −0 ChangeLog
  2. +18 −0 lib/page-object/accessors.rb
  3. +52 −2 spec/page-object/page-object_spec.rb
View
1 ChangeLog
@@ -3,6 +3,7 @@
* Enhanced TabeleCell to return nil when there is no corresponding cell for a referenced column
* Added css selector support for SelectList and Div
* Added ability to pass clasname as string to visit_page, on_page, and if_page methods
+ * Added params class instance variable to hold hash values that can be used in the page
=== Version 0.7.4 / 2012-9-8
* Enhancements
View
18 lib/page-object/accessors.rb
@@ -10,6 +10,24 @@ module PageObject
module Accessors
#
+ # Set some values that can be used withing the class. This is
+ # typically used to provide values that help build dynamic urls in
+ # the page_url method
+ #
+ # @param [Hash] the value to set the params
+ #
+ def params=(the_params)
+ @params = the_params
+ end
+
+ #
+ # Return the params that exist on this page class
+ #
+ def params
+ @params ||= {}
+ end
+
+ #
# Specify the url for the page. A call to this method will generate a
# 'goto' method to take you to the page.
#
View
54 spec/page-object/page-object_spec.rb
@@ -13,7 +13,7 @@ class CustomPlatform
let(:watir_page_object) { PageObjectTestPageObject.new(watir_browser) }
let(:selenium_page_object) { PageObjectTestPageObject.new(selenium_browser) }
- context "setting values for the Javascript Framework" do
+ context "setting values on the PageObject module" do
it "should set the javascript framework" do
PageObject::JavascriptFrameworkFacade.should_receive(:framework=)
PageObject.javascript_framework = :foo
@@ -23,8 +23,58 @@ class CustomPlatform
PageObject::JavascriptFrameworkFacade.should_receive(:add_framework)
PageObject.add_framework(:foo, :bar)
end
+
+ it "should set a default page wait value" do
+ PageObject.default_page_wait = 20
+ wait = PageObject.instance_variable_get("@page_wait")
+ wait.should == 20
+ end
+
+ it "should provide the default page wait value" do
+ PageObject.instance_variable_set("@page_wait", 10)
+ PageObject.default_page_wait.should == 10
+ end
+
+ it "should default the page wait value to 30" do
+ PageObject.instance_variable_set("@page_wait", nil)
+ PageObject.default_page_wait.should == 30
+ end
+
+ it "should set the default element wait value" do
+ PageObject.default_element_wait = 20
+ wait = PageObject.instance_variable_get("@element_wait")
+ wait.should == 20
+ end
+
+ it "should provide the default element wait value" do
+ PageObject.instance_variable_set("@element_wait", 10)
+ PageObject.default_element_wait.should == 10
+ end
+
+ it "should default the element wait to 5" do
+ PageObject.instance_variable_set("@element_wait", nil)
+ PageObject.default_element_wait.should == 5
+ end
end
-
+
+ context "setting values on the PageObject class instance" do
+ it "should set the params value" do
+ PageObjectTestPageObject.params = {:some => :value}
+ params = PageObjectTestPageObject.instance_variable_get("@params")
+ params[:some].should == :value
+ end
+
+ it "should provide the params value" do
+ PageObjectTestPageObject.instance_variable_set("@params", {:value => :updated})
+ PageObjectTestPageObject.params[:value].should == :updated
+ end
+
+ it "should default the params to an empty hash" do
+ PageObjectTestPageObject.instance_variable_set("@params", nil)
+ PageObjectTestPageObject.params.should == {}
+ end
+ end
+
context "when created with a watir-webdriver browser" do
it "should include the WatirPageObject module" do
watir_page_object.platform.should be_kind_of PageObject::Platforms::WatirWebDriver::PageObject

0 comments on commit d26a177

Please sign in to comment.
Something went wrong with that request. Please try again.