我正在尝试将SitePrism与我的ruby / capybara / selenium测试套件一起使用,并且我仍然会因为期望元素响应has_<element_name>?
而出现错误。规范的最后一行是失败的。它给了我一个错误说:
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
答案 0 :(得分:1)
此错误完全正确。您询问页面是否有toolbar_title,但toolbar_title实际上在工具栏上。你需要打电话
expect(sales_page.toolbar).to have_toolbar_title