rubycapybarasite-prism

Siteprism section won't respond to has_element


I'm trying to use SitePrism with my ruby/capybara/selenium test suite and I continue to get an error around expecting an element to respond to has_<element_name>? The last line of the spec is what is failing. It is giving me an error saying:

expected #<PageObjects::Pages::SalesPage:0x00000000066782b0> to respond to 'has_toolbar_title?'

sales_page.rb

module PageObjects
  module Pages
    class SalesPage < SitePrism::Page

      set_url "REDACTED"
      section :toolbar, PageObjects::Sections::Toolbar, '#qHybridViewToolbar'

    end
  end
end

toolbar.rb

module PageObjects
  module Sections
    class Toolbar < SitePrism::Section
      element :new_button,    '#ToolBtnNew'
      element :edit_button,   '#ToolBtnUpdate'
      element :delete_button, '#ToolBtnDelete'
      element :toolbar_title, '#qToolbarViewTitle'
    end
  end
end

my_spec.rb

require 'spec_helper'

describe 'On sales page' do

  context 'without a password' do
    it "does the things" do
      sales_page = PageObjects::Pages::SalesPage.new
      sales_page.load

      expect(sales_page).to have_toolbar

      sales_page.toolbar.new_button.click
      puts sales_page.toolbar.toolbar_title
      puts sales_page.toolbar.toolbar_title.text
      expect(sales_page).to have_toolbar_title

    end
  end
end

Solution

  • This error is completely correct. You're asking the page whether it has a toolbar_title, but the toolbar_title is actually on the toolbar. You need to call

    expect(sales_page.toolbar).to have_toolbar_title