Created
June 19, 2012 21:05
-
-
Save weaverryan/2956537 to your computer and use it in GitHub Desktop.
Behat Definition to help click generic links on different rows of a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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