From 3c7bfae29cb81f6868400a401b6be7e59c617cd9 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 22 Aug 2014 10:12:49 +0800 Subject: [PATCH] MDL-46572 behat: extended table head look up to check if header is link Header can be a link, this step will now look if header has a text or header link has the text Part of MDL-46191 --- lib/tests/behat/behat_general.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index d29a9cc659c..f3a17ffc98d 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1000,9 +1000,14 @@ class behat_general extends behat_base { $tablenode = $this->get_selected_node('table', $table); $tablexpath = $tablenode->getXpath(); - // Check if column exists, it can be in thead or tbody first row. - $columnheaderxpath = $tablexpath . "[thead/tr/th[normalize-space(.)='$column'] | " - . "tbody/tr[1]/th[normalize-space(.)='" . $column . "']]"; + // Header can be in thead or tbody (first row), following xpath should work. + $theadheaderxpath = "thead/tr[1]/th[(normalize-space(.)='" . $column . "' or a[normalize-space(text())='" . + $column . "'])]"; + $tbodyheaderxpath = "tbody/tr[1]/td[(normalize-space(.)='" . $column . "' or a[normalize-space(text())='" . + $column . "'])]"; + + // Check if column exists. + $columnheaderxpath = $tablexpath . "[" . $theadheaderxpath . " | " . $tbodyheaderxpath . "]"; $columnheader = $this->getSession()->getDriver()->find($columnheaderxpath); if (empty($columnheader)) { $columnexceptionmsg = $column . '" in table "' . $table . '"'; @@ -1016,17 +1021,16 @@ class behat_general extends behat_base { // Following conditions were considered before finding column count. // 1. Table header can be in thead/tr/th or tbody/tr/td[1]. // 2. First column can have th (Gradebook -> user report), so having lenient sibling check. - $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/thead/tr[1]/th[normalize-space(.)='" . - $column . "']/preceding-sibling::*) + 1]"; - $columnvaluexpath = $rowxpath . $columnpositionxpath . "[text()[contains(normalize-space(.),'" . $value . "')]]"; - + $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/" . $theadheaderxpath . + "/preceding-sibling::*) + 1]"; + $columnvaluexpath = $rowxpath . $columnpositionxpath . "[contains(normalize-space(.),'" . $value . "')]"; // Looks for the requested node inside the container node. $coumnnode = $this->getSession()->getDriver()->find($columnvaluexpath); if (empty($coumnnode)) { // Check if tbody/tr[1] contains header selector. - $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/tbody/tr[1]/td[normalize-space(.)='" . - $column . "']/preceding-sibling::*) + 1]"; - $columnvaluexpath = $rowxpath . $columnpositionxpath . "[text()[contains(normalize-space(.),'" . $value . "')]]"; + $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/" . $tbodyheaderxpath . + "/preceding-sibling::*) + 1]"; + $columnvaluexpath = $rowxpath . $columnpositionxpath . "[contains(normalize-space(.),'" . $value . "')]"; $coumnnode = $this->getSession()->getDriver()->find($columnvaluexpath); if (empty($coumnnode)) { $locatorexceptionmsg = $value . '" in "' . $row . '" row with column "' . $column;