Skip to content

Commit

Permalink
rspec update finished
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezy committed Dec 9, 2014
1 parent 9ea987a commit faad9f4
Showing 7 changed files with 366 additions and 366 deletions.
152 changes: 76 additions & 76 deletions spec/page-object/page-object_spec.rb

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions spec/page-object/page_factory_spec.rb
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class NoPO
end

it "should create a new page object and execute a block" do
@world.browser.should_not_receive(:goto)
expect(@world.browser).not_to receive(:goto)
@world.on_page FactoryTestPage do |page|
expect(page).to be_instance_of FactoryTestPage
end
@@ -67,7 +67,7 @@ class NoPO
end

it "should create a new page object and execute a block using 'on'" do
@world.browser.should_not_receive(:goto)
expect(@world.browser).not_to receive(:goto)
@world.on FactoryTestPage do |page|
expect(page).to be_instance_of FactoryTestPage
end
@@ -80,7 +80,7 @@ class NoPO
end

it "should create and visit a new page" do
@world.browser.should_receive(:goto).exactly(3).times
expect(@world.browser).to receive(:goto).exactly(3).times
@world.visit_page FactoryTestPage do |page|
expect(page).to be_instance_of FactoryTestPage
end
@@ -93,7 +93,7 @@ class NoPO
end

it "should merge params with the class level params if provided when visiting" do
@world.browser.should_receive(:goto)
expect(@world.browser).to receive(:goto)
FactoryTestPage.params = {:initial => :value}
@world.visit_page(FactoryTestPage, :using_params => {:new_value => :merged})
merged = FactoryTestPage.instance_variable_get("@merged_params")
@@ -106,7 +106,7 @@ class PageUsingParams
include PageObject
page_url "http://google.com/<%=params[:value]%>"
end
@world.browser.should_receive(:goto).with("http://google.com/PageObject")
expect(@world.browser).to receive(:goto).with("http://google.com/PageObject")
@world.visit_page(PageUsingParams, :using_params => {:value => 'PageObject'})
end

@@ -115,12 +115,12 @@ class PageUsingParmsAndInterpolated
include PageObject
page_url "http://google.com/#{1+2}/<%=params[:value]%>"
end
@world.browser.should_receive(:goto).with("http://google.com/3/PageObject")
expect(@world.browser).to receive(:goto).with("http://google.com/3/PageObject")
@world.visit_page(PageUsingParmsAndInterpolated, :using_params => {:value => 'PageObject'})
end

it "should create and visit a new page using 'visit'" do
@world.browser.should_receive(:goto).exactly(3).times
expect(@world.browser).to receive(:goto).exactly(3).times
@world.visit FactoryTestPage do |page|
expect(page).to be_instance_of FactoryTestPage
end
@@ -133,7 +133,7 @@ class PageUsingParmsAndInterpolated
end

it "should create and visit a new page when url is defined as 'direct_url'" do
@world.browser.should_receive(:goto)
expect(@world.browser).to receive(:goto)
@world.visit TestPageWithDirectUrl do |page|
expect(page).to be_instance_of TestPageWithDirectUrl
end
@@ -206,17 +206,17 @@ class PageUsingParmsAndInterpolated
pages = [[FactoryTestPage, :a_method], [AnotherPage, :b_method]]
PageObject::PageFactory.routes = {:default => pages}
fake_page = double('a_page')
FactoryTestPage.should_receive(:new).and_return(fake_page)
fake_page.should_receive(:a_method)
expect(FactoryTestPage).to receive(:new).and_return(fake_page)
expect(fake_page).to receive(:a_method)
expect(@world.navigate_to(AnotherPage).class).to eql AnotherPage
end

it "should pass parameters to methods when navigating" do
pages = [[FactoryTestPage, :a_method, 'blah'], [AnotherPage, :b_method]]
PageObject::PageFactory.routes = {:default => pages}
fake_page = double('a_page')
FactoryTestPage.should_receive(:new).and_return(fake_page)
fake_page.should_receive(:a_method).with('blah')
expect(FactoryTestPage).to receive(:new).and_return(fake_page)
expect(fake_page).to receive(:a_method).with('blah')
expect(@world.navigate_to(AnotherPage).class).to eql AnotherPage
end

@@ -230,8 +230,8 @@ class PageUsingParmsAndInterpolated
:default => [[FactoryTestPage, :a_method], [AnotherPage, :b_method]]
}
fake_page = double('a_page')
FactoryTestPage.should_receive(:new).and_return(fake_page)
fake_page.should_receive(:respond_to?).with(:a_method).and_return(false)
expect(FactoryTestPage).to receive(:new).and_return(fake_page)
expect(fake_page).to receive(:respond_to?).with(:a_method).and_return(false)
expect { @world.navigate_to(AnotherPage) }.to raise_error
end

@@ -244,13 +244,13 @@ class PageUsingParmsAndInterpolated

@world.current_page = FactoryTestPage.new(@world.browser)
f_page = FactoryTestPage.new(@world.browser)
FactoryTestPage.should_receive(:new).and_return(f_page)
f_page.should_receive(:respond_to?).with(:a_method).and_return(true)
f_page.should_receive(:a_method)
expect(FactoryTestPage).to receive(:new).and_return(f_page)
expect(f_page).to receive(:respond_to?).with(:a_method).and_return(true)
expect(f_page).to receive(:a_method)
a_page = AnotherPage.new(@world.browser)
AnotherPage.should_receive(:new).and_return(a_page)
a_page.should_receive(:respond_to?).with(:b_method).and_return(true)
a_page.should_receive(:b_method)
expect(AnotherPage).to receive(:new).and_return(a_page)
expect(a_page).to receive(:respond_to?).with(:b_method).and_return(true)
expect(a_page).to receive(:b_method)
expect(@world.continue_navigation_to(YetAnotherPage).class).to eql YetAnotherPage
end
end
88 changes: 44 additions & 44 deletions spec/page-object/page_populator_spec.rb
Original file line number Diff line number Diff line change
@@ -17,106 +17,106 @@ class PageObjectTestPageObject
let(:page_object) { PageObjectTestPageObject.new(browser) }

it "should set a value in a text field" do
page_object.should_receive(:tf=).with('value')
page_object.stub(:is_enabled?).and_return(true)
expect(page_object).to receive(:tf=).with('value')
allow(page_object).to receive(:is_enabled?).and_return(true)
page_object.populate_page_with('tf' => 'value')
end

it "should not set a value in a text field if it is not found on the page" do
browser.should_not_receive(:text_field)
expect(browser).not_to receive(:text_field)
page_object.populate_page_with('coffee' => 'value')
end

it "should not populate a text field when it is disabled" do
page_object.should_not_receive(:tf=)
page_object.should_receive(:tf_element).twice.and_return(browser)
browser.should_receive(:enabled?).and_return(false)
browser.should_receive(:tag_name).and_return('input')
expect(page_object).not_to receive(:tf=)
expect(page_object).to receive(:tf_element).twice.and_return(browser)
expect(browser).to receive(:enabled?).and_return(false)
expect(browser).to receive(:tag_name).and_return('input')
page_object.populate_page_with('tf' => true)
end

it "should not populate a text field when it is not visible" do
page_object.should_not_receive(:tf=)
page_object.should_receive(:tf_element).twice.and_return(browser)
browser.should_receive(:enabled?).and_return(true)
browser.should_receive(:visible?).and_return(false)
browser.should_receive(:tag_name).and_return('input')
expect(page_object).not_to receive(:tf=)
expect(page_object).to receive(:tf_element).twice.and_return(browser)
expect(browser).to receive(:enabled?).and_return(true)
expect(browser).to receive(:visible?).and_return(false)
expect(browser).to receive(:tag_name).and_return('input')
page_object.populate_page_with('tf' => true)
end

it "should set a value in a text area" do
page_object.should_receive(:ta=).with('value')
page_object.should_receive(:ta_element).and_return(browser)
browser.should_receive(:tag_name).and_return('textarea')
expect(page_object).to receive(:ta=).with('value')
expect(page_object).to receive(:ta_element).and_return(browser)
expect(browser).to receive(:tag_name).and_return('textarea')
page_object.populate_page_with('ta' => 'value')
end

it "should set a value in a select list" do
page_object.should_receive(:sl=).with('value')
page_object.stub(:is_enabled?).and_return(true)
expect(page_object).to receive(:sl=).with('value')
allow(page_object).to receive(:is_enabled?).and_return(true)
page_object.populate_page_with('sl' => 'value')
end

it "should set a value in a file field" do
page_object.should_receive(:ff=).with('value')
page_object.stub(:is_enabled?).and_return(true)
expect(page_object).to receive(:ff=).with('value')
allow(page_object).to receive(:is_enabled?).and_return(true)
page_object.populate_page_with('ff' => 'value')
end

it "should check a checkbox to true is specified" do
page_object.should_receive(:check_cb)
page_object.stub(:is_enabled?).and_return(true)
expect(page_object).to receive(:check_cb)
allow(page_object).to receive(:is_enabled?).and_return(true)
page_object.populate_page_with('cb' => true)
end

it "should uncheck a checkbox to false is specified" do
page_object.should_receive(:uncheck_cb)
page_object.stub(:is_enabled?).and_return(true)
expect(page_object).to receive(:uncheck_cb)
allow(page_object).to receive(:is_enabled?).and_return(true)
page_object.populate_page_with('cb' => false)
end

it "should select a radio button when true is specified" do
page_object.should_receive(:select_rb)
page_object.stub(:is_enabled?).and_return(true)
expect(page_object).to receive(:select_rb)
allow(page_object).to receive(:is_enabled?).and_return(true)
page_object.populate_page_with('rb' => true)
end

it "should select the correct element from a radio button group" do
page_object.should_receive(:select_rbg).with('blah')
expect(page_object).to receive(:select_rbg).with('blah')
page_object.populate_page_with('rbg' => 'blah')
end

it "should not populate a checkbox if it is disabled" do
page_object.should_not_receive(:check_cb)
page_object.should_receive(:cb_element).twice.and_return(browser)
browser.should_receive(:enabled?).and_return(false)
browser.should_receive(:tag_name).and_return('input')
expect(page_object).not_to receive(:check_cb)
expect(page_object).to receive(:cb_element).twice.and_return(browser)
expect(browser).to receive(:enabled?).and_return(false)
expect(browser).to receive(:tag_name).and_return('input')
page_object.populate_page_with('cb' => true)
end

it "should not populate a checkbox if it is not visible" do
page_object.should_not_receive(:check_cb)
page_object.should_receive(:cb_element).twice.and_return(browser)
browser.should_receive(:enabled?).and_return(true)
browser.should_receive(:visible?).and_return(false)
browser.should_receive(:tag_name).and_return('input')
expect(page_object).not_to receive(:check_cb)
expect(page_object).to receive(:cb_element).twice.and_return(browser)
expect(browser).to receive(:enabled?).and_return(true)
expect(browser).to receive(:visible?).and_return(false)
expect(browser).to receive(:tag_name).and_return('input')
page_object.populate_page_with('cb' => true)
end

it "should not populate a radio button when it is disabled" do
page_object.should_not_receive(:select_rb)
page_object.should_receive(:rb_element).twice.and_return(browser)
browser.should_receive(:enabled?).and_return(false)
browser.should_receive(:tag_name).and_return('input')
expect(page_object).not_to receive(:select_rb)
expect(page_object).to receive(:rb_element).twice.and_return(browser)
expect(browser).to receive(:enabled?).and_return(false)
expect(browser).to receive(:tag_name).and_return('input')
page_object.populate_page_with('rb' => true)
end

it "should not populate a radio button when it is not visible" do
page_object.should_not_receive(:select_rb)
page_object.should_receive(:rb_element).twice.and_return(browser)
browser.should_receive(:enabled?).and_return(true)
browser.should_receive(:visible?).and_return(false)
browser.should_receive(:tag_name).and_return('input')
expect(page_object).not_to receive(:select_rb)
expect(page_object).to receive(:rb_element).twice.and_return(browser)
expect(browser).to receive(:enabled?).and_return(true)
expect(browser).to receive(:visible?).and_return(false)
expect(browser).to receive(:tag_name).and_return('input')
page_object.populate_page_with('rb' => true)
end
end
Original file line number Diff line number Diff line change
@@ -11,55 +11,55 @@ class SeleniumTestPageObject
let(:selenium_page_object) { SeleniumTestPageObject.new(selenium_browser) }

before(:each) do
selenium_browser.stub(:switch_to).and_return(selenium_browser)
selenium_browser.stub(:default_content)
allow(selenium_browser).to receive(:switch_to).and_return(selenium_browser)
allow(selenium_browser).to receive(:default_content)
end

context "when building identifiers hash" do
it "should add tag_name when identifying by text for hidden_field" do
expected_identifier = {:text => 'foo', :tag_name => 'input', :type => 'hidden'}
PageObject::Elements::HiddenField.should_receive(:selenium_identifier_for).with(expected_identifier)
selenium_browser.should_receive(:find_element)
expect(PageObject::Elements::HiddenField).to receive(:selenium_identifier_for).with(expected_identifier)
expect(selenium_browser).to receive(:find_element)
selenium_page_object.platform.hidden_field_for(:text => 'foo')
end

it "should add tag_name when identifying by href for anchor" do
expected_identifier = {:href => 'foo', :tag_name => 'a'}
PageObject::Elements::Link.should_receive(:selenium_identifier_for).with(expected_identifier)
selenium_browser.should_receive(:find_element)
expect(PageObject::Elements::Link).to receive(:selenium_identifier_for).with(expected_identifier)
expect(selenium_browser).to receive(:find_element)
selenium_page_object.platform.link_for(:href => 'foo')
end

it "should add tag_name when identifying by text for div" do
expected_identifier = {:text => 'foo', :tag_name => 'div'}
PageObject::Elements::Div.should_receive(:selenium_identifier_for).with(expected_identifier)
selenium_browser.should_receive(:find_element)
expect(PageObject::Elements::Div).to receive(:selenium_identifier_for).with(expected_identifier)
expect(selenium_browser).to receive(:find_element)
selenium_page_object.platform.div_for(:text => 'foo')
end
end

context "when trying to find an element that does not exist" do
it "should return a surogate selenium object" do
selenium_browser.should_receive(:find_element).and_raise(Selenium::WebDriver::Error::NoSuchElementError)
expect(selenium_browser).to receive(:find_element).and_raise(Selenium::WebDriver::Error::NoSuchElementError)
page = SeleniumTestPageObject.new(selenium_browser)
element = page.link_element(:text => 'blah')
expect(element.element).to be_instance_of PageObject::Platforms::SeleniumWebDriver::SurrogateSeleniumElement
end

it "should know it is not exist" do
selenium_browser.should_receive(:find_element).twice.and_raise(Selenium::WebDriver::Error::NoSuchElementError)
expect(selenium_browser).to receive(:find_element).twice.and_raise(Selenium::WebDriver::Error::NoSuchElementError)
page = SeleniumTestPageObject.new(selenium_browser)
expect(page.link_element(:text => 'blah').element.exists?).to be false
end

it "should know it is not visible" do
selenium_browser.should_receive(:find_element).twice.and_raise(Selenium::WebDriver::Error::NoSuchElementError)
expect(selenium_browser).to receive(:find_element).twice.and_raise(Selenium::WebDriver::Error::NoSuchElementError)
page = SeleniumTestPageObject.new(selenium_browser)
expect(page.link_element(:text => 'blah').element).not_to be_visible
end

it "should raise an error when actions are requested" do
selenium_browser.should_receive(:find_element).and_raise(Selenium::WebDriver::Error::NoSuchElementError)
expect(selenium_browser).to receive(:find_element).and_raise(Selenium::WebDriver::Error::NoSuchElementError)
page = SeleniumTestPageObject.new(selenium_browser)
element = page.link_element(:text => 'blah')
expect { element.text }.to raise_error
Loading

0 comments on commit faad9f4

Please sign in to comment.