Laravel 页面内容测试可以由 CSS 或 XPath 表达式约束吗?
Can Laravel page content tests be constrained by a CSS or XPath expression?
我正在学习 Laravel,目前正在研究应如何编写自动化功能测试。我习惯了像 Selenium 和 Spiderling 这样的工具,我可以在其中指定应该在页面上的哪个位置找到文本片段。
比如在Spiderling中,我可以这样做:
$page = $this->visit(self::DOMAIN . '/browse');
$firstSource = $page->
find('table#reports tbody tr:first-child td:last-child')->
text();
$this->assertEquals('Item 1', $firstSource);
这很明确:文本 "Item 1" 必须位于 reports
table 的第一行,在最后一个单元格中。
据我了解 the docs,要检查 Laravel 中的文本片段,可以这样做:
$this->
visit('/browse')->
see('Item 1');
但是,对我来说这不是很令人满意 - 我如何防止出现文本正确但位置错误的回归错误?我很乐意在这里使用 CSS 或 XPath。
该解决方案既好又简单,只是没有记录。在 InteractsWithPages
特征中有一个方法 seeInElement
:
$this->
visit('/browse')->
seeInElement('table#reports tbody tr:first-child td:last-child', 'Item 1');
我正在学习 Laravel,目前正在研究应如何编写自动化功能测试。我习惯了像 Selenium 和 Spiderling 这样的工具,我可以在其中指定应该在页面上的哪个位置找到文本片段。
比如在Spiderling中,我可以这样做:
$page = $this->visit(self::DOMAIN . '/browse');
$firstSource = $page->
find('table#reports tbody tr:first-child td:last-child')->
text();
$this->assertEquals('Item 1', $firstSource);
这很明确:文本 "Item 1" 必须位于 reports
table 的第一行,在最后一个单元格中。
据我了解 the docs,要检查 Laravel 中的文本片段,可以这样做:
$this->
visit('/browse')->
see('Item 1');
但是,对我来说这不是很令人满意 - 我如何防止出现文本正确但位置错误的回归错误?我很乐意在这里使用 CSS 或 XPath。
该解决方案既好又简单,只是没有记录。在 InteractsWithPages
特征中有一个方法 seeInElement
:
$this->
visit('/browse')->
seeInElement('table#reports tbody tr:first-child td:last-child', 'Item 1');