knpuniversity / behat

Screencast code, script and kittens behind "BDD, Behat, Mink and other Wonderful Things Tutorial"
http://knpuniversity.com/screencast/behat
Other
12 stars 14 forks source link

Your Mink example could use the WebAssert instead of assertNotNull after using find() #22

Open stof opened 8 years ago

stof commented 8 years ago
$searchBox = $this->assertSession()->elementExists('css', 'input[name="searchTerm"]');

$searchBox->setValue(...)

WebAssert::elementExists accepts the same arguments than Element::find (plus an optional third one if you want to search in specific element rather than the whole page), but it throws an ExpectationException when there is no node instead of returning null.

There is a nice side-effect compared to using a PHPUnit assertion on the element: as the exception thrown is a MinkException, this will play well with the MinkExtension feature allowing to open the failing page on failure (to debug what failed by seeing the actual content)

weaverryan commented 8 years ago

@stof Ah, I haven't used the assertSession - I thought (by its name) it was purely an asserter, but this actually finds and asserts, which indeed is very very handy. I'm going to look into adding a quick chapter about this somewhere (or maybe updating an existing chapter).

I also hadn't seen the https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Listener/FailureShowListener.php - that's also interesting.

Thanks!

weaverryan commented 8 years ago

Code changes merged and deployed in at #23. Only todo is to record a small addition to the mink-inside-feature-context chapter.