【问题标题】:how test if a table row with id 'foo' has a certain class?如何测试具有 id 'foo' 的表行是否具有某个类?
【发布时间】:2012-10-12 06:27:36
【问题描述】:

对于我的 rails 3.0 应用程序,我使用 rspec+capybara 填充字段、单击按钮并测试是否存在“页面上任何位置”的一段文本。

但是我找不到任何关于如何将断言(具有值、包含或具有类)应用于我知道其 ID 的元素的任何解释。

例如,我正在尝试测试其id=row_1002 的表行(具有包含highlightrow 的类(可能还有其他类)

我还想测试带有id=row_1002 的行是否在该行的任何位置包含文本“Foobar”。

我尝试过的许多引发错误的方法包括:

find('tr', id: "row_1002")[:class].should include('highlightrow')

【问题讨论】:

    标签: rspec capybara


    【解决方案1】:

    你应该可以这样做:

    find('td#row_1002')[:class].should include('highlightrow')
    

    以及在行中的任意位置查找 id 包含文本“Foobar”的行:

    find('td#row_1002').text.should include('Foobar')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-29
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      相关资源
      最近更新 更多