Skip to content

Commit

Permalink
MDL-46572 behat: extended table head look up to check if header is link
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Rajesh Taneja authored and mdjnelson committed Aug 28, 2014
1 parent 1446e02 commit 3c7bfae
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,9 +1000,14 @@ public function row_column_of_table_should_contain($row, $column, $table, $value
$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 . '"';
Expand All @@ -1016,17 +1021,16 @@ public function row_column_of_table_should_contain($row, $column, $table, $value
// 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;
Expand Down

0 comments on commit 3c7bfae

Please sign in to comment.