【问题标题】:Selecting an node by attribute with Goutte / Symfony CssSelector component使用 Goutte / Symfony CssSelector 组件按属性选择节点
【发布时间】:2012-04-11 16:19:51
【问题描述】:

我正在使用Goutte(它是 Symfony 功能测试组件的独立包)来测试 Wordpress 主题:

public function testDocumentHasBasicNodes(){
    $this->assertEquals(1, $this->crawler->filter('title')->count(),
            'document shall have a TITLE node');

    $this->assertEquals(1, $this->crawler->filter('meta')->count(),
            'document shall have a meta[charset="utf-8"] node');
}

第一个测试通过但是:

indexTest::testDocumentHasBasicNodes
document shall have a meta[charset="utf-8"] node
Failed asserting that 0 matches expected 1.

总结一下我的问题:
如何使用 Goutte / Symfony CSS Selector 组件按属性获取节点?

【问题讨论】:

    标签: phpunit functional-testing goutte


    【解决方案1】:

    你可以像这样按属性过滤。

    $this->assertEquals(1, $this->crawler->filter('meta[charset="utf-8"]')->count(),
        'document shall have a meta[charset="utf-8"] node');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多