spec/page-object/accessors_spec.rb in page-object-0.3.1 vs spec/page-object/accessors_spec.rb in page-object-0.3.2
- old
+ new
@@ -19,10 +19,13 @@
image(:logo, :id => 'logo')
form(:login, :id => 'login')
list_item(:item_one, :id => 'one')
unordered_list(:menu, :id => 'main_menu')
ordered_list(:top_five, :id => 'top')
+ h1(:heading1, :id => 'main_heading')
+ h2(:heading2, :id => 'main_heading')
+ h3(:heading3, :id => 'main_heading')
end
class BlockPageObject
include PageObject
@@ -77,10 +80,19 @@
"unordered_list"
end
ordered_list :top_five do |element|
"ordered_list"
end
+ h1 :heading1 do |element|
+ "h1"
+ end
+ h2 :heading2 do |element|
+ "h2"
+ end
+ h3 :heading3 do |element|
+ "h3"
+ end
end
describe PageObject::Accessors do
let(:watir_browser) { mock_watir_browser }
let(:selenium_browser) { mock_selenium_browser }
@@ -855,9 +867,132 @@
context "selenium implementation" do
it "should retrieve the element from the page" do
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
element = selenium_page_object.top_five_element
element.should be_instance_of PageObject::Elements::OrderedList
+ end
+ end
+ end
+
+ describe "h1 accessors" do
+ context "when called on a page object" do
+ it "should generate accessor methods" do
+ watir_page_object.should respond_to(:heading1)
+ watir_page_object.should respond_to(:heading1_element)
+ end
+
+ it "should call a block on the element method when present" do
+ block_page_object.heading1_element.should == "h1"
+ end
+ end
+
+ context "watir implementation" do
+ it "should retrieve the text from the h1" do
+ watir_browser.should_receive(:h1).and_return(watir_browser)
+ watir_browser.should_receive(:text).and_return("value")
+ watir_page_object.heading1.should == "value"
+ end
+
+ it "should retrieve the element from the page" do
+ watir_browser.should_receive(:h1).and_return(watir_browser)
+ element = watir_page_object.heading1_element
+ element.should be_instance_of PageObject::Elements::Heading
+ end
+ end
+
+ context "selenium implementation" do
+ it "should retrieve the text from the h1" do
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
+ selenium_browser.should_receive(:text).and_return("value")
+ selenium_page_object.heading1.should == "value"
+ end
+
+ it "should retrieve the element from the page" do
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
+ element = selenium_page_object.heading1_element
+ element.should be_instance_of PageObject::Elements::Heading
+ end
+ end
+ end
+
+ describe "h2 accessors" do
+ context "when called on a page object" do
+ it "should generate accessor methods" do
+ watir_page_object.should respond_to(:heading2)
+ watir_page_object.should respond_to(:heading2_element)
+ end
+
+ it "should call a block on the element method when present" do
+ block_page_object.heading2_element.should == "h2"
+ end
+ end
+
+ context "watir implementation" do
+ it "should retrieve the text from the h2" do
+ watir_browser.should_receive(:h2).and_return(watir_browser)
+ watir_browser.should_receive(:text).and_return("value")
+ watir_page_object.heading2.should == "value"
+ end
+
+ it "should retrieve the element from the page" do
+ watir_browser.should_receive(:h2).and_return(watir_browser)
+ element = watir_page_object.heading2_element
+ element.should be_instance_of PageObject::Elements::Heading
+ end
+ end
+
+ context "selenium implementation" do
+ it "should retrieve the text from the h2" do
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
+ selenium_browser.should_receive(:text).and_return("value")
+ selenium_page_object.heading2.should == "value"
+ end
+
+ it "should retrieve the element from the page" do
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
+ element = selenium_page_object.heading2_element
+ element.should be_instance_of PageObject::Elements::Heading
+ end
+ end
+
+ describe "h3 accessors" do
+ context "when called on a page object" do
+ it "should generate accessor methods" do
+ watir_page_object.should respond_to(:heading3)
+ watir_page_object.should respond_to(:heading3_element)
+ end
+
+ it "should call a block on the element method when present" do
+ block_page_object.heading3_element.should == "h3"
+ end
+ end
+
+ context "watir implementation" do
+ it "should retrieve the text from the h3" do
+ watir_browser.should_receive(:h3).and_return(watir_browser)
+ watir_browser.should_receive(:text).and_return("value")
+ watir_page_object.heading3.should == "value"
+ end
+
+ it "should retrieve the element from the page" do
+ watir_browser.should_receive(:h3).and_return(watir_browser)
+ element = watir_page_object.heading3_element
+ element.should be_instance_of PageObject::Elements::Heading
+ end
+ end
+
+ context "selenium implementation" do
+ it "should retrieve the text from the h3" do
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
+ selenium_browser.should_receive(:text).and_return("value")
+ selenium_page_object.heading3.should == "value"
+ end
+
+ it "should retrieve the element from the page" do
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
+ element = selenium_page_object.heading3_element
+ element.should be_instance_of PageObject::Elements::Heading
+ end
end
end
end
end