spec/page-object/accessors_spec.rb in page-object-0.0.1 vs spec/page-object/accessors_spec.rb in page-object-0.0.2

- old
+ new

@@ -1,16 +1,19 @@ require 'spec_helper' class TestPageObject include PageObject - link(:google_search, {:link => 'Google Search'}) - text_field(:first_name, {:id => 'first_name'}) - select_list(:state, {:id => 'state'}) - checkbox(:active, {:id => 'is_active_id'}) - radio_button(:first, {:id => 'first_choice'}) - button(:click_me, { :id => 'button_submit'}) + link(:google_search, :link => 'Google Search') + text_field(:first_name, :id => 'first_name') + select_list(:state, :id => 'state') + checkbox(:active, :id => 'is_active_id') + radio_button(:first, :id => 'first_choice') + button(:click_me, :id => 'button_submit') + div(:message, :id => 'message_id') + table(:cart, :id => 'cart_id') + cell(:total, :id => 'total') end describe PageObject::Accessors do let(:watir_browser) { mock_watir_browser } let(:selenium_browser) { mock_selenium_browser } @@ -83,11 +86,11 @@ end context "Selenium implementation" do it "should get the text from the text field element" do selenium_browser.should_receive(:find_element).and_return(selenium_browser) - selenium_browser.should_receive(:value).and_return('Katie') + selenium_browser.should_receive(:attribute).with('value').and_return('Katie') selenium_page_object.first_name.should == 'Katie' end it "should set some text on a text field element" do selenium_browser.should_receive(:find_element).and_return(selenium_browser) @@ -288,10 +291,134 @@ describe "button accessors" do 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 end - + + context "watir implementation" do + it "should be able to click a button" do + watir_browser.should_receive(:button).and_return(watir_browser) + watir_browser.should_receive(:click) + watir_page_object.click_me + end + + it "should retrieve a button element" do + watir_browser.should_receive(:button).and_return(watir_browser) + element = watir_page_object.click_me_button + element.should be_instance_of PageObject::Elements::Button + end + end + + context "selenium implementation" do + it "should be able to click a button" do + selenium_browser.should_receive(:find_element).and_return(selenium_browser) + selenium_browser.should_receive(:click) + selenium_page_object.click_me + end + + it "should retrieve a button element" do + selenium_browser.should_receive(:find_element).and_return(selenium_browser) + element = selenium_page_object.click_me_button + element.should be_instance_of PageObject::Elements::Button + + end + end + end + + describe "div accessors" do + 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 + end + + context "watir implementation" do + it "should retrieve the text from a div" do + watir_browser.should_receive(:div).and_return(watir_browser) + watir_browser.should_receive(:text).and_return("Message from div") + watir_page_object.message.should == "Message from div" + end + + it "should retrieve the div element from the page" do + watir_browser.should_receive(:div).and_return(watir_browser) + element = watir_page_object.message_div + element.should be_instance_of PageObject::Elements::Div + end + end + + context "selenium implementation" do + it "should retrieve the text from a div" do + selenium_browser.should_receive(:find_element).and_return(selenium_browser) + selenium_browser.should_receive(:text).and_return("Message from div") + selenium_page_object.message.should == "Message from div" + + end + + it "should retrieve the div element from the page" do + selenium_browser.should_receive(:find_element).and_return(selenium_browser) + element = selenium_page_object.message_div + element.should be_instance_of PageObject::Elements::Div + + end + end + end + + 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 + end + + context "watir implementation" do + it "should retrieve the table element from the page" do + watir_browser.should_receive(:table).and_return(watir_browser) + element = watir_page_object.cart_table + element.should be_instance_of PageObject::Elements::Table + end + end + + context "selenium implementation" do + it "should retrieve the table element from the page" do + selenium_browser.should_receive(:find_element).and_return(selenium_browser) + element = selenium_page_object.cart_table + element.should be_instance_of(PageObject::Elements::Table) + + end + end + end + + describe "table cell accessors" do + 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 + end + + context "watir implementation" do + it "should retrieve the text for the cell" do + watir_browser.should_receive(:td).and_return(watir_browser) + watir_browser.should_receive(:text).and_return('10.00') + watir_page_object.total.should == '10.00' + end + + it "should retrieve the cell element from the page" do + watir_browser.should_receive(:td).and_return(watir_browser) + element = watir_page_object.total_cell + element.should be_instance_of PageObject::Elements::TableCell + end + end + + context "selenium implementation" do + it "should retrieve the text from the cell" do + selenium_browser.should_receive(:find_element).and_return(selenium_browser) + selenium_browser.should_receive(:text).and_return('celldata') + selenium_page_object.total.should == 'celldata' + end + end end end