mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-57765 behat: Allow exact selectors to be used
In Blocks with boost theme selector to find block with name is partial match it might fail in some cases. It would be nice to use exact match to avoid unexpected failures
This commit is contained in:
parent
5130953c8a
commit
1dc320f140
@ -26,6 +26,8 @@
|
||||
require_once(__DIR__ . '/exact_named_selector.php');
|
||||
require_once(__DIR__ . '/partial_named_selector.php');
|
||||
|
||||
use Behat\Mink\Exception\ExpectationException as ExpectationException;
|
||||
|
||||
/**
|
||||
* Moodle selectors manager.
|
||||
*
|
||||
@ -52,8 +54,22 @@ class behat_selectors {
|
||||
$locator = $element;
|
||||
} else {
|
||||
// Named selectors uses arrays as locators including the type of named selector.
|
||||
$locator = array($selectortype, behat_context_helper::escape($element));
|
||||
$selector = 'named_partial';
|
||||
$allowedselectors = self::get_allowed_selectors();
|
||||
if (!isset($allowedselectors[$selectortype])) {
|
||||
throw new ExpectationException('The "' . $selectortype . '" selector not registered.', $session);
|
||||
}
|
||||
$locator = array($allowedselectors[$selectortype], behat_context_helper::escape($element));
|
||||
|
||||
// Get the selector which should be used.
|
||||
$allowedpartialselectors = behat_partial_named_selector::get_allowed_selectors();
|
||||
$allowedexactselectors = behat_exact_named_selector::get_allowed_selectors();
|
||||
if (isset($allowedpartialselectors[$selectortype])) {
|
||||
$selector = 'named_partial';
|
||||
} else if (isset($allowedexactselectors[$selectortype])) {
|
||||
$selector = 'named_exact';
|
||||
} else {
|
||||
throw new ExpectationException('The "' . $selectortype . '" selector not registered.', $session);
|
||||
}
|
||||
}
|
||||
|
||||
return array($selector, $locator);
|
||||
|
@ -39,7 +39,19 @@ class behat_exact_named_selector extends \Behat\Mink\Selector\ExactNamedSelector
|
||||
/**
|
||||
* @var Allowed types when using selector arguments.
|
||||
*/
|
||||
protected static $allowedselectors = [];
|
||||
protected static $allowedselectors = array(
|
||||
'button_exact' => 'button',
|
||||
'checkbox_exact' => 'checkbox',
|
||||
'field_exact' => 'field',
|
||||
'fieldset_exact' => 'fieldset',
|
||||
'link_exact' => 'link',
|
||||
'link_or_button_exact' => 'link_or_button',
|
||||
'option_exact' => 'option',
|
||||
'radio_exact' => 'radio',
|
||||
'select_exact' => 'select',
|
||||
'table_exact' => 'table',
|
||||
'text_exact' => 'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* Allowed selectors getter.
|
||||
|
@ -41,9 +41,9 @@ class behat_theme_boost_behat_blocks extends behat_blocks {
|
||||
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', get_string('addblock'));
|
||||
|
||||
if (!$this->running_javascript()) {
|
||||
$this->execute('behat_general::i_click_on_in_the', [$blockname, 'link', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
|
||||
} else {
|
||||
$this->execute('behat_general::i_click_on_in_the', [$blockname, 'link', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', '.modal-body', 'css_element']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,11 +70,11 @@ class behat_theme_boost_behat_blocks extends behat_blocks {
|
||||
|
||||
$cancelstr = get_string('cancel');
|
||||
if (!$this->running_javascript()) {
|
||||
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '#region-main', 'css_element']);
|
||||
} else {
|
||||
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link_exact', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '.modal-body', 'css_element']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,11 +83,11 @@ class behat_theme_boost_behat_blocks extends behat_blocks {
|
||||
|
||||
$cancelstr = get_string('cancel');
|
||||
if (!$this->running_javascript()) {
|
||||
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '#region-main', 'css_element']);
|
||||
} else {
|
||||
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link_exact', '.modal-body', 'css_element']);
|
||||
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '.modal-body', 'css_element']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user