17/04/2015 - BEHAT
Assuming that you have a set of div elements that contain different text inside and want to confirm the content.
As you can see this is just a raw example so you better tidy it up a bit.
class FeatureContext extends MinkContext implements KernelAwareContext
{
/**
* @When /^The content of repeated "([^"]*)" div should be:$/
*/
public function iReadContentOfDiv($class, TableNode $table)
{
$session = $this->getSession();
$page = $session->getPage();
$element = $page->findAll('css', $class);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not evaluate CSS: "%s"', $class));
}
$found = [];
foreach ($element as $e) {
$found[] = $e->getText();
}
foreach ($table->getHash() as $element) {
if (!in_array($element['content'], $found)) {
throw new Exception(sprintf('Data "%s" not found in DOM element "%s".', $element['content'], $class));
}
}
}
}
Feature: Test
Scenario: Iterate classes
Given I am on "about"
Then I should see "Welcome to About page"
And The content of repeated ".message" div should be:
| content |
| Text 1 |
| Text 2 |
| Text 3 |