Skip to content

Commit

Permalink
Add code blocks to the ch21 (html-tables)
Browse files Browse the repository at this point in the history
  • Loading branch information
bocharsky-bw committed Nov 16, 2015
1 parent de0f40c commit 72c04e9
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions knpu/html-tables.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -21,25 +21,34 @@ 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:

```bash
./vendor/bin/behat features/product_admin.feature:21
```

We're green! Now, let's get even harder.
We're green! Now, let's get even harder.

0 comments on commit 72c04e9

Please sign in to comment.