Skip to content
Snippets Groups Projects
Unverified Commit ba57c851 authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Fix behat tests for action menues under javascript

parent 4c398f79
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,7 @@ class behat_tool_lifecycle extends behat_base { ...@@ -49,6 +49,7 @@ class behat_tool_lifecycle extends behat_base {
* @throws Exception * @throws Exception
*/ */
public function click_on_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename) { public function click_on_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename) {
$this->open_or_close_action_menu($tool, $rowname, $tablename);
$xpathelement = $this->i_should_see_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename); $xpathelement = $this->i_should_see_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename);
$this->execute('behat_general::i_click_on', [$xpathelement, 'xpath_element']); $this->execute('behat_general::i_click_on', [$xpathelement, 'xpath_element']);
...@@ -66,10 +67,14 @@ class behat_tool_lifecycle extends behat_base { ...@@ -66,10 +67,14 @@ class behat_tool_lifecycle extends behat_base {
* @throws Exception * @throws Exception
*/ */
public function i_should_see_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename) { public function i_should_see_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename) {
$xpathelement = $this->get_xpath_of_tool_in_table($tool, $rowname, $tablename); $xpathelement = $this->get_xpath_of_tool_in_table($tool, $rowname, $tablename);
$this->open_or_close_action_menu($tool, $rowname, $tablename);
try { try {
$this->find('xpath', $xpathelement); $this->find('xpath', $xpathelement);
$this->open_or_close_action_menu($tool, $rowname, $tablename);
} catch (ElementNotFoundException $e) { } catch (ElementNotFoundException $e) {
throw new ExpectationException('"The tool "' . $tool . '" was not found for the row "'. $rowname. throw new ExpectationException('"The tool "' . $tool . '" was not found for the row "'. $rowname.
'" of the table ' . $tablename, $this->getSession()); '" of the table ' . $tablename, $this->getSession());
...@@ -175,10 +180,13 @@ class behat_tool_lifecycle extends behat_base { ...@@ -175,10 +180,13 @@ class behat_tool_lifecycle extends behat_base {
* @throws Exception * @throws Exception
*/ */
public function i_should_not_see_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename) { public function i_should_not_see_the_tool_in_the_row_of_the_table($tool, $rowname, $tablename) {
$this->open_or_close_action_menu($tool, $rowname, $tablename);
$xpathelement = $this->get_xpath_of_tool_in_table($tool, $rowname, $tablename); $xpathelement = $this->get_xpath_of_tool_in_table($tool, $rowname, $tablename);
try { try {
$this->find('xpath', $xpathelement); $this->find('xpath', $xpathelement);
$this->open_or_close_action_menu($tool, $rowname, $tablename);
} catch (ElementNotFoundException $e) { } catch (ElementNotFoundException $e) {
return; return;
} }
...@@ -186,6 +194,25 @@ class behat_tool_lifecycle extends behat_base { ...@@ -186,6 +194,25 @@ class behat_tool_lifecycle extends behat_base {
'" of the table ' . $tablename, $this->getSession()); '" of the table ' . $tablename, $this->getSession());
} }
/**
* If Javascript is active, this function tries to click on an action dropdown, to reveal the underlying actions.
* @param $tool string identifier of the tool
* @param $rowname string identifier of the row
* @param $tablename string identifier of the table
* @throws Exception
*/
protected function open_or_close_action_menu($tool, $rowname, $tablename) {
if ($this->running_javascript()) {
$actionelement = $this->get_xpath_of_action_menu_in_table($tool, $rowname, $tablename);
try {
$element = $this->find('xpath', $actionelement);
$element->click();
} catch (ElementNotFoundException $e) {
return;
}
}
}
/** /**
* Build the xpath to the table element with class tablename, throws exceptions if not present. * Build the xpath to the table element with class tablename, throws exceptions if not present.
...@@ -245,7 +272,7 @@ class behat_tool_lifecycle extends behat_base { ...@@ -245,7 +272,7 @@ class behat_tool_lifecycle extends behat_base {
throw new ExpectationException('"The table ' . $tablename . ' was not found.', $this->getSession()); throw new ExpectationException('"The table ' . $tablename . ' was not found.', $this->getSession());
} }
$xpathelement = $xpathelement . "//*[contains(text(),'$rowname')]/ancestor::tr"; $xpathelement = $xpathelement . "//*[text()[contains(.,'$rowname')]]/ancestor::tr";
try { try {
$this->find('xpath', $xpathelement); $this->find('xpath', $xpathelement);
...@@ -255,12 +282,43 @@ class behat_tool_lifecycle extends behat_base { ...@@ -255,12 +282,43 @@ class behat_tool_lifecycle extends behat_base {
} }
$xpathelement = $xpathelement . "//a[@title = '$tool']" . $xpathelement = $xpathelement . "//a[@title = '$tool']" .
" | " . $xpathelement. "//span[contains(text(), '$tool')]/parent::a". " | " . $xpathelement. "//span[text()[contains(., '$tool')]]/parent::a".
" | " . $xpathelement. "//button[text() = '$tool']"; " | " . $xpathelement. "//button[text() = '$tool']";
return $xpathelement; return $xpathelement;
} }
/**
* Build the xpath to the action menu and throws exceptions if either the table or the row are not present.
* @param $tool string identifier of the tool
* @param $rowname string identifier of the row
* @param $tablename string identifier of the table
* @return string xpath of the tool
* @throws ExpectationException
*/
private function get_xpath_of_action_menu_in_table($tool, $rowname, $tablename) {
$xpathelement = "//table/tbody/tr[contains(@id, '$tablename')]";
try {
$this->find('xpath', $xpathelement);
} catch (ElementNotFoundException $e) {
throw new ExpectationException('"The table ' . $tablename . ' was not found.', $this->getSession());
}
$xpathelement = $xpathelement . "//*[text()[contains(.,'$rowname')]]/ancestor::tr";
try {
$this->find('xpath', $xpathelement);
} catch (ElementNotFoundException $e) {
throw new ExpectationException('"The row "'. $rowname.
'" of the table ' . $tablename . ' was not found.', $this->getSession());
}
$xpathelement = $xpathelement . "//a[text()[contains(.,'Action')]]";
return $xpathelement;
}
/** /**
* I should not see a tool for a entry of a table. * I should not see a tool for a entry of a table.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment