-1

I'm learning Laravel and am currently looking at how automated functional tests should be written. I'm used to tools like Selenium and Spiderling, where I can specify where on a page a text fragment should be found.

For example, in Spiderling, I can do this:

$page = $this->visit(self::DOMAIN . '/browse');
$firstSource = $page->
    find('table#reports tbody tr:first-child td:last-child')->
    text();
$this->assertEquals('Item 1', $firstSource);

That's pretty explicit: the text "Item 1" must be in the first row of the reports table, in the last cell.

As I understand it from the docs, to check for a text fragment in Laravel, one can do this:

$this->
    visit('/browse')->
    see('Item 1');

However, to me that is not very satisfying - how can I guard against a regression error that gets the text right but the placement wrong? I'd be happy to use either CSS or XPath here.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

The solution is nice and easy, just not documented. In the InteractsWithPages trait there's a method seeInElement:

$this->
    visit('/browse')->
    seeInElement('table#reports tbody tr:first-child td:last-child', 'Item 1');
halfer
  • 19,824
  • 17
  • 99
  • 186