Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code blocks to the ch21 (html-tables) #34

Merged
merged 1 commit into from
Nov 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.