mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-76169 behat: Add improved steps for using action menus
This commit adds new steps related to action menus to support: * Choosing an item in a named action menu * Choosing an item in a named action menu within a container * Confirming that an action menu item does or does not exist in a named action menu * Confirming that an action menu item does or does not exist in a named action menu within a container The existing action menu steps were insufficient as they assume that there is only one action menu within he container, which is not necessarily the case. The existing action menu steps are not non-JS friendly and will error if JS is disabled, without providing any fallback when one is easily available. Unfortunately these steps cannot be used to replace the existing steps without manual intervention.
This commit is contained in:
parent
720bd60fc6
commit
232ebac338
3 changed files with 159 additions and 29 deletions
|
@ -86,6 +86,7 @@ class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSele
|
||||||
*/
|
*/
|
||||||
protected static $allowedselectors = array(
|
protected static $allowedselectors = array(
|
||||||
'activity' => 'activity',
|
'activity' => 'activity',
|
||||||
|
'actionmenu' => 'actionmenu',
|
||||||
'badge' => 'badge',
|
'badge' => 'badge',
|
||||||
'block' => 'block',
|
'block' => 'block',
|
||||||
'button' => 'button',
|
'button' => 'button',
|
||||||
|
@ -138,6 +139,17 @@ class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSele
|
||||||
protected static $moodleselectors = array(
|
protected static $moodleselectors = array(
|
||||||
'activity' => <<<XPATH
|
'activity' => <<<XPATH
|
||||||
.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][descendant::*[contains(normalize-space(.), %locator%)]]
|
.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][descendant::*[contains(normalize-space(.), %locator%)]]
|
||||||
|
XPATH
|
||||||
|
, 'actionmenu' => <<<XPATH
|
||||||
|
.//*[
|
||||||
|
contains(concat(' ', normalize-space(@class), ' '), ' action-menu ')
|
||||||
|
and
|
||||||
|
descendant::*[
|
||||||
|
contains(concat(' ', normalize-space(@class), ' '), ' dropdown-toggle ')
|
||||||
|
and
|
||||||
|
contains(normalize-space(.), %locator%)
|
||||||
|
]
|
||||||
|
]
|
||||||
XPATH
|
XPATH
|
||||||
, 'badge' => <<<XPATH
|
, 'badge' => <<<XPATH
|
||||||
.//span[(contains(@class, 'badge')) and text()[contains(., %locator%)]]
|
.//span[(contains(@class, 'badge')) and text()[contains(., %locator%)]]
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
|
|
||||||
require_once(__DIR__ . '/../../behat/behat_base.php');
|
require_once(__DIR__ . '/../../behat/behat_base.php');
|
||||||
|
|
||||||
use Behat\Mink\Exception\ExpectationException as ExpectationException;
|
use Behat\Mink\Element\NodeElement;
|
||||||
use Behat\Mink\Exception\DriverException as DriverException;
|
use Behat\Mink\Exception\DriverException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Steps definitions to open and close action menus.
|
* Steps definitions to open and close action menus.
|
||||||
|
@ -83,4 +83,122 @@ class behat_action_menu extends behat_base {
|
||||||
$this->ensure_node_is_visible($node);
|
$this->ensure_node_is_visible($node);
|
||||||
$node->click();
|
$node->click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select a specific item in an action menu.
|
||||||
|
*
|
||||||
|
* @When /^I choose the "(?P<item_string>(?:[^"]|\\")*)" item in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu$/
|
||||||
|
* @param string $item The item to choose
|
||||||
|
* @param string $actionmenu The text used in the description of the action menu
|
||||||
|
*/
|
||||||
|
public function i_choose_in_the_named_menu(string $item, string $actionmenu): void {
|
||||||
|
$menu = $this->find('actionmenu', $actionmenu);
|
||||||
|
$this->select_item_in_action_menu($item, $menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select a specific item in an action menu within a container.
|
||||||
|
*
|
||||||
|
* @When /^I choose the "(?P<item_string>(?:[^"]|\\")*)" item in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu of the "(?P<locator_string>(?:[^"]|\\")*)" "(?P<type_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @param string $item The item to choose
|
||||||
|
* @param string $actionmenu The text used in the description of the action menu
|
||||||
|
* @param string|NodeElement $locator The identifer used for the container
|
||||||
|
* @param string $selector The type of container to locate
|
||||||
|
*/
|
||||||
|
public function i_choose_in_the_named_menu_in_container(string $item, string $actionmenu, $locator, $selector): void {
|
||||||
|
$container = $this->find($selector, $locator);
|
||||||
|
$menu = $this->find('actionmenu', $actionmenu, false, $container);
|
||||||
|
$this->select_item_in_action_menu($item, $menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select an item in the specified menu.
|
||||||
|
*
|
||||||
|
* Note: This step does work both with, and without, JavaScript.
|
||||||
|
*
|
||||||
|
* @param string $item Item string value
|
||||||
|
* @param NodeElement $menu The menu NodeElement to select from
|
||||||
|
*/
|
||||||
|
protected function select_item_in_action_menu(string $item, NodeElement $menu): void {
|
||||||
|
if ($this->running_javascript()) {
|
||||||
|
// Open the menu by clicking on the trigger.
|
||||||
|
$this->execute(
|
||||||
|
'behat_general::i_click_on',
|
||||||
|
[$menu, "NodeElement"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select the menu item.
|
||||||
|
$this->execute(
|
||||||
|
'behat_general::i_click_on_in_the',
|
||||||
|
[$item, "link", $menu, "NodeElement"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action menu item should not exist.
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should not exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu$/
|
||||||
|
* @param string $item The item to check
|
||||||
|
* @param string $actionmenu The text used in the description of the action menu
|
||||||
|
*/
|
||||||
|
public function item_should_not_exist(string $item, string $actionmenu): void {
|
||||||
|
$menu = $this->find('actionmenu', $actionmenu);
|
||||||
|
$this->execute('behat_general::should_not_exist_in_the', [
|
||||||
|
$item, 'link',
|
||||||
|
$menu, 'NodeElement'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action menu item should not exist within a container.
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should not exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu of the "(?P<locator_string>(?:[^"]|\\")*)" "(?P<type_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @param string $item The item to check
|
||||||
|
* @param string $actionmenu The text used in the description of the action menu
|
||||||
|
* @param string|NodeElement $locator The identifer used for the container
|
||||||
|
* @param string $selector The type of container to locate
|
||||||
|
*/
|
||||||
|
public function item_should_not_exist_in_the(string $item, string $actionmenu, $locator, $selector): void {
|
||||||
|
$container = $this->find($selector, $locator);
|
||||||
|
$menu = $this->find('actionmenu', $actionmenu, false, $container);
|
||||||
|
$this->execute('behat_general::should_not_exist_in_the', [
|
||||||
|
$item, 'link',
|
||||||
|
$menu, 'NodeElement'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action menu item should exist.
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu$/
|
||||||
|
* @param string $item The item to check
|
||||||
|
* @param string $actionmenu The text used in the description of the action menu
|
||||||
|
*/
|
||||||
|
public function item_should_exist(string $item, string $actionmenu): void {
|
||||||
|
$menu = $this->find('actionmenu', $actionmenu);
|
||||||
|
$this->execute('behat_general::should_exist_in_the', [
|
||||||
|
$item, 'link',
|
||||||
|
$menu, 'NodeElement'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action menu item should exist within a container.
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu of the "(?P<locator_string>(?:[^"]|\\")*)" "(?P<type_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @param string $item The item to check
|
||||||
|
* @param string $actionmenu The text used in the description of the action menu
|
||||||
|
* @param string|NodeElement $locator The identifer used for the container
|
||||||
|
* @param string $selector The type of container to locate
|
||||||
|
*/
|
||||||
|
public function item_should_exist_in_the(string $item, string $actionmenu, $locator, $selector): void {
|
||||||
|
$container = $this->find($selector, $locator);
|
||||||
|
$menu = $this->find('actionmenu', $actionmenu, false, $container);
|
||||||
|
$this->execute('behat_general::should_exist_in_the', [
|
||||||
|
$item, 'link',
|
||||||
|
$menu, 'NodeElement'
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue