From 72c04e9a62362a6fa04e9ba17a71ed316cb4e94a Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Tue, 17 Nov 2015 00:10:24 +0200 Subject: [PATCH] Add code blocks to the ch21 (html-tables) --- knpu/html-tables.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/knpu/html-tables.md b/knpu/html-tables.md index c2dc66a..bd5e9c2 100644 --- a/knpu/html-tables.md +++ b/knpu/html-tables.md @@ -1,12 +1,12 @@ # Finding inside HTML Tables To finish the scenario, we need a `Then` that's able to look for a check mark on -a specific row. The checkmark icon itself is an element with a `fa-check` class. +a specific row. The check mark icon itself is an element with a `fa fa-check` class. There is no built in definition to find elements inside of a specific row. So let's describe this using natural language. How about: - Then the "Foo1" row should have a check +[[[ code('b5e1a9c227') ]]] Execute Behat to get that definition printed out for us: @@ -21,20 +21,29 @@ will put the definitions inside of the `FeatureContext` class for you: ./vendor/bin/behat features/product_admin.feature:21 --append-snippets ``` -Change `arg1` to be `rowText`. Ok, this is a bit harder. First, we need to find a -row that contains that `$rowText` and *then* look inside of just *that* element to -see if it has a `fa-check` class in it. +Change `arg1` to be `rowText`: + +[[[ code('d7f998cd64') ]]] + +Ok, this is a bit harder. First, we need to find a row that contains that `$rowText` +and *then* look inside of just *that* element to see if it has a `fa-check` class in it. Start by finding via CSS, `$row = $this->getPage()->find('css')`. For the selector, use `table tr:` and then the `contains` pseudo selector that looks for some text inside. -Pass `%s` and set the value using `sprintf`. +Pass `%s` and set the value using `sprintf()`: + +[[[ code('ee059f0baa') ]]] `$row` will now be the first `tr` containing this text, or null. It's not perfect: if `$rowText` had some bad characters in it, the selector would fail. But this is -my test so I'll be lazy until I can't. Add -`assertNotNull($row, 'Could not find a row with text '.$rowText)`. Finally, assert -that the row's HTML has a `fa-check` class inside of it with -`assertContains('fa-check', $row->getHtml(),'Did not find the check in the row');`. +my test so I'll be lazy until I can't. Add `assertNotNull()` function: + +[[[ code('e3aa726b1b') ]]] + +Finally, assert that the row's HTML has a `fa-check` class inside of it with +`assertContains()`: + +[[[ code('f83db91ed0') ]]] Moment of truth: @@ -42,4 +51,4 @@ Moment of truth: ./vendor/bin/behat features/product_admin.feature:21 ``` -We're green! Now, let's get even harder. \ No newline at end of file +We're green! Now, let's get even harder.