ingenerator / behat-tableassert

Assertions for all sorts of tabular data in behat
BSD 3-Clause "New" or "Revised" License
5 stars 5 forks source link

Add a table parser for any arbitrary repeating HTML structure #2

Open acoulton opened 8 years ago

acoulton commented 8 years ago

For example, to parse list-groups or other repeating multi element structures from a Mink NodeElement.

eg to get from:

<div class="list-group-item">
  <div class="list-group-item-heading">Heading text</div>
  <div class="list-group-item-body">
    <strong>User: </strong><span class="username">@someuser</span>
  </div>
</div>

to:

| title        | username  |
| Heading text | @someuser |

So you would provide an array of container node elements and the mapping of CSS / xpath selector to column title.

$table = $parser->parse(
    $container->findAll('css', '.list-group-item'),
    [
      'title' => ['css', '.list-group-item-heading'],
      'user'  => ['css', '.list-group-item-body .username']
    ]
);