spec/page-object/accessors_spec.rb in page-object-0.0.4 vs spec/page-object/accessors_spec.rb in page-object-0.0.5
- old
+ new
@@ -1,10 +1,11 @@
require 'spec_helper'
class TestPageObject
include PageObject
+ page_url "http://apple.com"
link(:google_search, :link => 'Google Search')
text_field(:first_name, :id => 'first_name')
hidden_field(:social_security_number, :id => 'ssn')
text_area(:address, :id => 'address')
select_list(:state, :id => 'state')
@@ -20,22 +21,68 @@
list_item(:item_one, :id => 'one')
unordered_list(:menu, :id => 'main_menu')
ordered_list(:top_five, :id => 'top')
end
+class BlockPageObject
+ include PageObject
+
+ attr_reader :value
+
+ text_field :first_name do |browser| "text_field" end
+ hidden_field :secret do |browser| "hidden_field" end
+ text_area :address do |browser| "text_area" end
+ select_list :state do |browser| "select_list" end
+ link :continue do |browser| "link" end
+ checkbox :active do |browser| "checkbox" end
+ radio_button :first do |browser| "radio_button" end
+ button :click_me do |browser| "button" end
+ div :footer do |browser| "div" end
+ span :alert do |browser| "span" end
+ table :cart do |browser| "table" end
+ cell :total do |browser| "cell" end
+ image :logo do |browser| "image" end
+ form :login do |browser| "form" end
+ list_item :item_one do |browser| "list_item" end
+ unordered_list :menu do |browser| "unordered_list" end
+ ordered_list :top_five do |browser| "ordered_list" end
+end
+
describe PageObject::Accessors do
let(:watir_browser) { mock_watir_browser }
let(:selenium_browser) { mock_selenium_browser }
let(:watir_page_object) { TestPageObject.new(watir_browser) }
let(:selenium_page_object) { TestPageObject.new(selenium_browser) }
+ let(:block_page_object) { BlockPageObject.new(watir_browser) }
+ describe "goto a page" do
+ it "should navigate to a page when requested" do
+ watir_browser.should_receive(:goto)
+ page = TestPageObject.new(watir_browser, true)
+ end
+
+ it "should not navigate to a page when not requested" do
+ watir_browser.should_not_receive(:goto)
+ page = TestPageObject.new(watir_browser)
+ end
+
+ it "should not navigate to a page when 'page_url' not specified" do
+ watir_browser.should_not_receive(:goto)
+ page = BlockPageObject.new(watir_browser, true)
+ end
+ end
+
describe "link accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:google_search)
watir_page_object.should respond_to(:google_search_link)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.continue_link.should == "link"
+ end
end
context "Watir implementation" do
it "should select a link" do
watir_browser.stub_chain(:link, :click)
@@ -69,10 +116,14 @@
it "should generate accessor methods" do
watir_page_object.should respond_to(:first_name)
watir_page_object.should respond_to(:first_name=)
watir_page_object.should respond_to(:first_name_text_field)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.first_name_text_field.should == "text_field"
+ end
end
context "Watir implementation" do
it "should get the text from the text field element" do
watir_browser.should_receive(:text_field).and_return(watir_browser)
@@ -119,10 +170,14 @@
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:social_security_number)
watir_page_object.should respond_to(:social_security_number_hidden_field)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.secret_hidden_field.should == "hidden_field"
+ end
end
context "watir implementation" do
it "should get the text from a hidden field" do
watir_browser.should_receive(:hidden).and_return(watir_browser)
@@ -157,10 +212,14 @@
it "should generate accessor methods" do
watir_page_object.should respond_to(:address)
watir_page_object.should respond_to(:address=)
watir_page_object.should respond_to(:address_text_area)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.address_text_area.should == "text_area"
+ end
end
context "watir implementation" do
it "should set some text on the text area" do
watir_browser.should_receive(:textarea).and_return(watir_browser)
@@ -207,10 +266,14 @@
it "should generate accessor methods" do
watir_page_object.should respond_to :state
watir_page_object.should respond_to :state=
watir_page_object.should respond_to(:state_select_list)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.state_select_list.should == "select_list"
+ end
end
context "Watir implementation" do
it "should get the current item from a select list" do
watir_browser.should_receive(:select_list).and_return watir_browser
@@ -259,10 +322,14 @@
watir_page_object.should respond_to :check_active
watir_page_object.should respond_to :uncheck_active
watir_page_object.should respond_to :active_checked?
watir_page_object.should respond_to(:active_checkbox)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.active_checkbox.should == "checkbox"
+ end
end
context "Watir implementation" do
it "should check a check box element" do
watir_browser.should_receive(:checkbox).and_return(watir_browser)
@@ -325,10 +392,14 @@
watir_page_object.should respond_to :select_first
watir_page_object.should respond_to :clear_first
watir_page_object.should respond_to :first_selected?
watir_page_object.should respond_to(:first_radio_button)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.first_radio_button.should == "radio_button"
+ end
end
context "Watir implementation" do
it "should select a radio button" do
watir_browser.should_receive(:radio).and_return(watir_browser)
@@ -388,10 +459,14 @@
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to :click_me
watir_page_object.should respond_to :click_me_button
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.click_me_button.should == "button"
+ end
end
context "watir implementation" do
it "should be able to click a button" do
watir_browser.should_receive(:button).and_return(watir_browser)
@@ -426,10 +501,14 @@
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:message)
watir_page_object.should respond_to(:message_div)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.footer_div.should == "div"
+ end
end
context "watir implementation" do
it "should retrieve the text from a div" do
watir_browser.should_receive(:div).and_return(watir_browser)
@@ -465,10 +544,14 @@
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:alert)
watir_page_object.should respond_to(:alert_span)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.alert_span.should == "span"
+ end
end
context "watir implementation" do
it "should retrieve the text from a span" do
watir_browser.should_receive(:span).and_return(watir_browser)
@@ -502,10 +585,14 @@
describe "table accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:cart_table)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.cart_table.should == "table"
+ end
end
context "watir implementation" do
it "should retrieve the table element from the page" do
watir_browser.should_receive(:table).and_return(watir_browser)
@@ -527,10 +614,14 @@
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:total)
watir_page_object.should respond_to(:total_cell)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.total_cell.should == "cell"
+ end
end
context "watir implementation" do
it "should retrieve the text for the cell" do
watir_browser.should_receive(:td).and_return(watir_browser)
@@ -557,10 +648,14 @@
describe "image accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:logo_image)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.logo_image.should == "image"
+ end
end
context "watir implementation" do
it "should retrieve the image element from the page" do
watir_browser.should_receive(:image).and_return(watir_browser)
@@ -581,10 +676,14 @@
describe "form accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:login_form)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.login_form.should == "form"
+ end
end
context "watir implementation" do
it "should retrieve the form element from the page" do
watir_browser.should_receive(:form).and_return(watir_browser)
@@ -606,10 +705,14 @@
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:item_one)
watir_page_object.should respond_to(:item_one_list_item)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.item_one_list_item.should == "list_item"
+ end
end
context "watir implementation" do
it "should retrieve the text from the list item" do
watir_browser.should_receive(:li).and_return(watir_browser)
@@ -642,10 +745,14 @@
describe "unordered list accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:menu_unordered_list)
end
+
+ it "should call a block on the element method when present" do
+ block_page_object.menu_unordered_list.should == "unordered_list"
+ end
end
context "watir implementation" do
it "should retrieve the element from the page" do
watir_browser.should_receive(:ul).and_return(watir_browser)
@@ -665,9 +772,13 @@
describe "ordered list accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:top_five_ordered_list)
+ end
+
+ it "should call a block on the element method when present" do
+ block_page_object.top_five_ordered_list.should == "ordered_list"
end
end
context "watir implementation" do
it "should retrieve the element from the page" do