【问题标题】:Using SitePrism's page object elements to perform page assertions使用 SitePrism 的页面对象元素来执行页面断言
【发布时间】:2014-08-31 02:34:05
【问题描述】:

我想知道是否有办法直接使用页面对象元素执行page.should 断言,而不是将 xpath 或 CSS 选择器字符串作为参数。

即:

页面类:

class FooClass < SitePrism::Page
  element :action_select, '.autocomplete.medium'
end

步骤定义:

page.should have_css('.autocomplete.medium')

#Sort of thing desired:

page.should have_css(action_select.get_css)

.get_css 不存在,但它用于说明所需的内容。

【问题讨论】:

    标签: rspec automation cucumber capybara site-prism


    【解决方案1】:

    element 方法创建了一个has_&lt;element name&gt;? 方法,可以检查元素是否存在。

    例如,对于您的页面:

    page.has_action_select?
    #=> returns true if it exists, false if it doesn't
    

    这允许你的断言是:

    page.should have_action_select
    

    更多详情可以查看site prism page

    【讨论】:

    • 很好的答案,感谢 Justin Ko 和 Nat Ritmeyer 提供的重要信息!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    相关资源
    最近更新 更多