From f9d3667e7b45f1c644b763f3ee1289b630e7c774 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 28 Mar 2013 10:40:55 +0800 Subject: [PATCH] MDL-38179 behat: Step definition to click on a table row element --- lib/tests/behat/behat_general.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index ea6b623bad8..76fbdc3a56a 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -138,6 +138,28 @@ class behat_general extends behat_base { $node->click(); } + /** + * Click on the specified element inside a table row containing the specified text. + * + * @Given /^I click on "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" in the "(?P(?:[^"]|\\")*)" table row$/ + * @throws ElementNotFoundException + * @param string $element Element we look for + * @param string $selectortype The type of what we look for + * @param string $tablerowtext The table row text + */ + public function i_click_on_in_the_table_row($element, $selectortype, $tablerowtext) { + + // The table row container. + $nocontainerexception = new ElementNotFoundException($this->getSession(), '"' . $tablerowtext . '" row text '); + $tablerowtext = str_replace("'", "\'", $tablerowtext); + $rownode = $this->find('xpath', "//tr[contains(., '" . $tablerowtext . "')]", $nocontainerexception); + + // Looking for the element DOM node inside the specified row. + list($selector, $locator) = $this->transform_selector($selectortype, $element); + $elementnode = $this->find($selector, $locator, false, $rownode); + $elementnode->click(); + } + /** * Checks, that page contains specified text. *