Skip to content

Instantly share code, notes, and snippets.

@johnennewdeeson
Last active September 17, 2015 11:40
Show Gist options
  • Save johnennewdeeson/e92bc6b76cd3eb74f14c to your computer and use it in GitHub Desktop.
Save johnennewdeeson/e92bc6b76cd3eb74f14c to your computer and use it in GitHub Desktop.
Drupal Behat Step definition for clicking an operations link in a table where another cell in the same row contains a known value
/**
* @When I click :link_text in table row containing :text
*/
public function iClickOperationLinkInTableRowWithText($link_text, $text) {
$session = $this->getSession();
$el = $session->getPage()->find('xpath', "//td[contains(., '{$text}')]");
if (empty($el)) {
throw new ExpectationException(t('No such text in table - @text', array(
'@text' => $text,
)), $session);
}
$tr = $el->getParent();
$link = $tr->findLink($link_text);
if (empty($link)) {
throw new ExpectationException(t('No such link @link_text in row with @text', array(
'@link_text' => $link_text,
'@text' => $text,
)), $session);
}
$link->click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment