【问题标题】:Cucumber - Capybara search for text within table rowCucumber - Capybara 在表格行中搜索文本
【发布时间】:2017-03-07 22:56:58
【问题描述】:

我正在尝试在单个表格行中搜索我的黄瓜测试。

我将每一行的格式设置为:

%tr
  %td= title
  %td= complete
  %td= goal

我希望在具有给定标题的行中搜索,并检查目标

有没有一种简单的方法可以做到这一点?

【问题讨论】:

    标签: ruby ruby-on-rails-3 html-table cucumber capybara


    【解决方案1】:

    对于遇到这个问题的其他人,我认为更好的方法是:

    find('tr', text: 'My title').should have_content(goal)
    

    这样你就不会在不需要时添加标题属性

    【讨论】:

    • 这也是允许的:within find('tr', text: 'My title') { click_link 'edit' }
    【解决方案2】:

    我可能会为您感兴趣的td 添加一个属性。执行以下操作:

    %tr
      %td{title= "#{title}"}= title
      %td= complete
      %td= goal
    

    然后你可以参考 StackOverflow 上关于使用 css 在特定元素中查找的这个问题。

    Capybara, finding within a css element

    【讨论】:

    • 这基本上就是我最终所做的 - 我在表格行中添加了一个 id,然后将其用于我的测试:page.find("##{my_code}").should have_content(goal )
    猜你喜欢
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多