Skip to content

Instantly share code, notes, and snippets.

@dariodiaz
Forked from weaverryan/FeatureContext.php
Created August 29, 2012 16:21
Show Gist options
  • Save dariodiaz/3515149 to your computer and use it in GitHub Desktop.
Save dariodiaz/3515149 to your computer and use it in GitHub Desktop.
behat: 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