Skip to content

Instantly share code, notes, and snippets.

@pilot
Forked from weaverryan/FeatureContext.php
Created June 20, 2012 08:02
Show Gist options
  • Save pilot/2958717 to your computer and use it in GitHub Desktop.
Save pilot/2958717 to your computer and use it in GitHub Desktop.
Behat Definition to help click generic links on different rows of a table
<?php
// ...
class FeatureContext extends MinkContext
{
/**
* Looks for a table, then looks for a row that contains the given text.
* Once it finds the right row, it clicks a link in that row.
*
* Really handy when you have a generic "Edit" link on each row of
* a table, and you want to click a specific one (e.g. the "Edit" link
* in the row that contains "Item #2")
*
* @When /^I click on "([^"]*)" on the row containing "([^"]*)"$/
*/
public function iClickOnOnTheRowContaining($linkName, $rowText)
{
/** @var $row \Behat\Mink\Element\NodeElement */
$row = $this->getPage()->find('css', sprintf('table tr:contains("%s")', $rowText));
if (!$row) {
throw new \Exception(sprintf('Cannot find any row on the page containing the text "%s"', $rowText));
}
$row->clickLink($linkName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment