mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-55713-master-3' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
b976e22a7e
6 changed files with 306 additions and 168 deletions
|
@ -51,19 +51,8 @@ class behat_field_manager {
|
||||||
|
|
||||||
// There are moodle form elements that are not directly related with
|
// There are moodle form elements that are not directly related with
|
||||||
// a basic HTML form field, we should also take care of them.
|
// a basic HTML form field, we should also take care of them.
|
||||||
try {
|
|
||||||
// The DOM node.
|
// The DOM node.
|
||||||
$fieldnode = $context->find_field($label);
|
$fieldnode = $context->find_field($label);
|
||||||
} catch (ElementNotFoundException $fieldexception) {
|
|
||||||
|
|
||||||
// Looking for labels that points to filemanagers.
|
|
||||||
try {
|
|
||||||
$fieldnode = $context->find_filemanager($label);
|
|
||||||
} catch (ElementNotFoundException $filemanagerexception) {
|
|
||||||
// We want the generic 'field' exception.
|
|
||||||
throw $fieldexception;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The behat field manager.
|
// The behat field manager.
|
||||||
return self::get_form_field($fieldnode, $context->getSession());
|
return self::get_form_field($fieldnode, $context->getSession());
|
||||||
|
|
|
@ -482,12 +482,16 @@ class behat_config_util {
|
||||||
|
|
||||||
// Remove selectors from step definitions.
|
// Remove selectors from step definitions.
|
||||||
$themes = $this->get_list_of_themes();
|
$themes = $this->get_list_of_themes();
|
||||||
|
$selectortypes = ['partial', 'exact'];
|
||||||
foreach ($themes as $theme) {
|
foreach ($themes as $theme) {
|
||||||
$selectorclass = self::get_behat_theme_selector_override_classname($theme);
|
foreach ($selectortypes as $selectortype) {
|
||||||
|
// Don't include selector classes.
|
||||||
|
$selectorclass = self::get_behat_theme_selector_override_classname($theme, $selectortype);
|
||||||
if (isset($allcontexts[$selectorclass])) {
|
if (isset($allcontexts[$selectorclass])) {
|
||||||
unset($allcontexts[$selectorclass]);
|
unset($allcontexts[$selectorclass]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comments use black color, so failure path is not visible. Using color other then black/white is safer.
|
// Comments use black color, so failure path is not visible. Using color other then black/white is safer.
|
||||||
// https://github.com/Behat/Behat/pull/628.
|
// https://github.com/Behat/Behat/pull/628.
|
||||||
|
@ -865,13 +869,18 @@ class behat_config_util {
|
||||||
* Return context name of behat_theme selector to use.
|
* Return context name of behat_theme selector to use.
|
||||||
*
|
*
|
||||||
* @param string $themename name of the theme.
|
* @param string $themename name of the theme.
|
||||||
|
* @param string $selectortype The type of selector (partial or exact at this stage)
|
||||||
* @param bool $includeclass if class should be included.
|
* @param bool $includeclass if class should be included.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static final function get_behat_theme_selector_override_classname($themename, $includeclass = false) {
|
public static final function get_behat_theme_selector_override_classname($themename, $selectortype, $includeclass = false) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
$overridebehatclassname = 'behat_theme_'.$themename.'_behat_selectors';
|
if ($selectortype !== 'partial' && $selectortype !== 'exact') {
|
||||||
|
throw new coding_exception("Unknown selector override type '{$selectortype}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
$overridebehatclassname = "behat_theme_{$themename}_behat_{$selectortype}_selectors";
|
||||||
|
|
||||||
if ($includeclass) {
|
if ($includeclass) {
|
||||||
$themeoverrideselector = $CFG->dirroot . DIRECTORY_SEPARATOR . 'theme' . DIRECTORY_SEPARATOR . $themename .
|
$themeoverrideselector = $CFG->dirroot . DIRECTORY_SEPARATOR . 'theme' . DIRECTORY_SEPARATOR . $themename .
|
||||||
|
@ -1290,12 +1299,15 @@ class behat_config_util {
|
||||||
$this->overriddenthemescontexts[$context] = $path;
|
$this->overriddenthemescontexts[$context] = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't include behat_selectors.
|
$selectortypes = ['partial', 'exact'];
|
||||||
if ($context === self::get_behat_theme_selector_override_classname($theme)) {
|
foreach ($selectortypes as $selectortype) {
|
||||||
|
// Don't include selector classes.
|
||||||
|
if ($context === self::get_behat_theme_selector_override_classname($theme, $selectortype)) {
|
||||||
unset($this->contexts[$context]);
|
unset($this->contexts[$context]);
|
||||||
unset($themesuitecontexts[$context]);
|
unset($themesuitecontexts[$context]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add theme specific contexts with suffix to steps definitions.
|
// Add theme specific contexts with suffix to steps definitions.
|
||||||
$themesuitecontexts[$context] = $path;
|
$themesuitecontexts[$context] = $path;
|
||||||
|
|
|
@ -34,116 +34,6 @@
|
||||||
*/
|
*/
|
||||||
class behat_selectors {
|
class behat_selectors {
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Allowed types when using text selectors arguments.
|
|
||||||
*/
|
|
||||||
protected static $allowedtextselectors = array(
|
|
||||||
'activity' => 'activity',
|
|
||||||
'block' => 'block',
|
|
||||||
'css_element' => 'css_element',
|
|
||||||
'dialogue' => 'dialogue',
|
|
||||||
'fieldset' => 'fieldset',
|
|
||||||
'list_item' => 'list_item',
|
|
||||||
'question' => 'question',
|
|
||||||
'region' => 'region',
|
|
||||||
'section' => 'section',
|
|
||||||
'table' => 'table',
|
|
||||||
'table_row' => 'table_row',
|
|
||||||
'xpath_element' => 'xpath_element',
|
|
||||||
'form_row' => 'form_row'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Allowed types when using selector arguments.
|
|
||||||
*/
|
|
||||||
protected static $allowedselectors = array(
|
|
||||||
'activity' => 'activity',
|
|
||||||
'block' => 'block',
|
|
||||||
'button' => 'button',
|
|
||||||
'checkbox' => 'checkbox',
|
|
||||||
'css_element' => 'css_element',
|
|
||||||
'dialogue' => 'dialogue',
|
|
||||||
'field' => 'field',
|
|
||||||
'fieldset' => 'fieldset',
|
|
||||||
'file' => 'file',
|
|
||||||
'filemanager' => 'filemanager',
|
|
||||||
'link' => 'link',
|
|
||||||
'link_or_button' => 'link_or_button',
|
|
||||||
'list_item' => 'list_item',
|
|
||||||
'optgroup' => 'optgroup',
|
|
||||||
'option' => 'option',
|
|
||||||
'question' => 'question',
|
|
||||||
'radio' => 'radio',
|
|
||||||
'region' => 'region',
|
|
||||||
'section' => 'section',
|
|
||||||
'select' => 'select',
|
|
||||||
'table' => 'table',
|
|
||||||
'table_row' => 'table_row',
|
|
||||||
'text' => 'text',
|
|
||||||
'xpath_element' => 'xpath_element',
|
|
||||||
'form_row' => 'form_row'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Behat by default comes with XPath, CSS and named selectors,
|
|
||||||
* named selectors are a mapping between names (like button) and
|
|
||||||
* xpaths that represents that names and includes a placeholder that
|
|
||||||
* will be replaced by the locator. These are Moodle's own xpaths.
|
|
||||||
*
|
|
||||||
* @var XPaths for moodle elements.
|
|
||||||
*/
|
|
||||||
protected static $moodleselectors = array(
|
|
||||||
'activity' => <<<XPATH
|
|
||||||
.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][normalize-space(.) = %locator% ]
|
|
||||||
XPATH
|
|
||||||
, 'block' => <<<XPATH
|
|
||||||
.//*[@data-block][contains(concat(' ', normalize-space(@class), ' '), concat(' ', %locator%, ' ')) or
|
|
||||||
descendant::*[self::h2|self::h3][normalize-space(.) = %locator%] or
|
|
||||||
@aria-label = %locator%]
|
|
||||||
XPATH
|
|
||||||
, 'dialogue' => <<<XPATH
|
|
||||||
.//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue ') and
|
|
||||||
normalize-space(descendant::div[
|
|
||||||
contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hd ')
|
|
||||||
]) = %locator%] |
|
|
||||||
.//div[contains(concat(' ', normalize-space(@class), ' '), ' yui-dialog ') and
|
|
||||||
normalize-space(descendant::div[@class='hd']) = %locator%]
|
|
||||||
XPATH
|
|
||||||
, 'filemanager' => <<<XPATH
|
|
||||||
.//*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']
|
|
||||||
/descendant::input[@id = //label[contains(normalize-space(string(.)), %locator%)]/@for]
|
|
||||||
XPATH
|
|
||||||
, 'list_item' => <<<XPATH
|
|
||||||
.//li[contains(normalize-space(.), %locator%) and not(.//li[contains(normalize-space(.), %locator%)])]
|
|
||||||
XPATH
|
|
||||||
, 'question' => <<<XPATH
|
|
||||||
.//div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]
|
|
||||||
[contains(div[@class='content']/div[contains(concat(' ', normalize-space(@class), ' '), ' formulation ')], %locator%)]
|
|
||||||
XPATH
|
|
||||||
, 'region' => <<<XPATH
|
|
||||||
.//*[self::div | self::section | self::aside | self::header | self::footer][./@id = %locator%]
|
|
||||||
XPATH
|
|
||||||
, 'section' => <<<XPATH
|
|
||||||
.//li[contains(concat(' ', normalize-space(@class), ' '), ' section ')][./descendant::*[self::h3]
|
|
||||||
[normalize-space(.) = %locator%][contains(concat(' ', normalize-space(@class), ' '), ' sectionname ') or
|
|
||||||
contains(concat(' ', normalize-space(@class), ' '), ' section-title ')]] |
|
|
||||||
.//div[contains(concat(' ', normalize-space(@class), ' '), ' sitetopic ')]
|
|
||||||
[./descendant::*[self::h2][normalize-space(.) = %locator%] or %locator% = 'frontpage']
|
|
||||||
XPATH
|
|
||||||
, 'table' => <<<XPATH
|
|
||||||
.//table[(./@id = %locator% or contains(.//caption, %locator%) or contains(.//th, %locator%) or contains(concat(' ', normalize-space(@class), ' '), %locator% ))]
|
|
||||||
XPATH
|
|
||||||
, 'table_row' => <<<XPATH
|
|
||||||
.//tr[contains(normalize-space(.), %locator%) and not(.//tr[contains(normalize-space(.), %locator%)])]
|
|
||||||
XPATH
|
|
||||||
, 'text' => <<<XPATH
|
|
||||||
.//*[contains(., %locator%) and not(.//*[contains(., %locator%)])]
|
|
||||||
XPATH
|
|
||||||
, 'form_row' => <<<XPATH
|
|
||||||
.//*[self::label or self::div[contains(concat(' ', @class, ' '), ' fstaticlabel ')]][contains(., %locator%)]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
|
|
||||||
XPATH
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the behat selector and locator for a given moodle selector and locator
|
* Returns the behat selector and locator for a given moodle selector and locator
|
||||||
*
|
*
|
||||||
|
@ -167,26 +57,16 @@ XPATH
|
||||||
return array($selector, $locator);
|
return array($selector, $locator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds moodle selectors as behat named selectors.
|
|
||||||
*
|
|
||||||
* @param Session $session The mink session
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function register_moodle_selectors(Behat\Mink\Session $session) {
|
|
||||||
|
|
||||||
foreach (self::get_moodle_selectors() as $name => $xpath) {
|
|
||||||
$session->getSelectorsHandler()->getSelector('named_partial')->registerNamedXpath($name, $xpath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allowed selectors getter.
|
* Allowed selectors getter.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function get_allowed_selectors() {
|
public static function get_allowed_selectors() {
|
||||||
return self::$allowedselectors;
|
return array_merge(
|
||||||
|
behat_partial_named_selector::get_allowed_selectors(),
|
||||||
|
behat_exact_named_selector::get_allowed_selectors()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,15 +75,9 @@ XPATH
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function get_allowed_text_selectors() {
|
public static function get_allowed_text_selectors() {
|
||||||
return self::$allowedtextselectors;
|
return array_merge(
|
||||||
}
|
behat_partial_named_selector::get_allowed_text_selectors(),
|
||||||
|
behat_exact_named_selector::get_allowed_text_selectors()
|
||||||
/**
|
);
|
||||||
* Moodle selectors attribute accessor.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected static function get_moodle_selectors() {
|
|
||||||
return self::$moodleselectors;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
61
lib/behat/classes/exact_named_selector.php
Normal file
61
lib/behat/classes/exact_named_selector.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moodle-specific named exact selectors.
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @category test
|
||||||
|
* @copyright 2016 Andrew Nicols
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moodle selectors manager.
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @copyright 2016 Andrew Nicols
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class behat_exact_named_selector extends \Behat\Mink\Selector\ExactNamedSelector {
|
||||||
|
/**
|
||||||
|
* @var Allowed types when using text selectors arguments.
|
||||||
|
*/
|
||||||
|
protected static $allowedtextselectors = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Allowed types when using selector arguments.
|
||||||
|
*/
|
||||||
|
protected static $allowedselectors = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed selectors getter.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_allowed_selectors() {
|
||||||
|
return static::$allowedselectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed text selectors getter.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_allowed_text_selectors() {
|
||||||
|
return static::$allowedtextselectors;
|
||||||
|
}
|
||||||
|
}
|
195
lib/behat/classes/partial_named_selector.php
Normal file
195
lib/behat/classes/partial_named_selector.php
Normal file
|
@ -0,0 +1,195 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moodle-specific selectors.
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @category test
|
||||||
|
* @copyright 2013 David Monllaó
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moodle selectors manager.
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @category test
|
||||||
|
* @copyright 2013 David Monllaó
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSelector {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates selector instance.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
foreach (self::$customselectors as $alias => $selectors) {
|
||||||
|
$this->registerNamedXpath($alias, implode(' | ', $selectors));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (static::$moodleselectors as $name => $xpath) {
|
||||||
|
$this->registerNamedXpath($name, $xpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the constructor after adding any new selector or replacement values.
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Allowed types when using text selectors arguments.
|
||||||
|
*/
|
||||||
|
protected static $allowedtextselectors = array(
|
||||||
|
'activity' => 'activity',
|
||||||
|
'block' => 'block',
|
||||||
|
'css_element' => 'css_element',
|
||||||
|
'dialogue' => 'dialogue',
|
||||||
|
'fieldset' => 'fieldset',
|
||||||
|
'list_item' => 'list_item',
|
||||||
|
'question' => 'question',
|
||||||
|
'region' => 'region',
|
||||||
|
'section' => 'section',
|
||||||
|
'table' => 'table',
|
||||||
|
'table_row' => 'table_row',
|
||||||
|
'xpath_element' => 'xpath_element',
|
||||||
|
'form_row' => 'form_row',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Allowed types when using selector arguments.
|
||||||
|
*/
|
||||||
|
protected static $allowedselectors = array(
|
||||||
|
'activity' => 'activity',
|
||||||
|
'block' => 'block',
|
||||||
|
'button' => 'button',
|
||||||
|
'checkbox' => 'checkbox',
|
||||||
|
'css_element' => 'css_element',
|
||||||
|
'dialogue' => 'dialogue',
|
||||||
|
'field' => 'field',
|
||||||
|
'fieldset' => 'fieldset',
|
||||||
|
'file' => 'file',
|
||||||
|
'filemanager' => 'filemanager',
|
||||||
|
'link' => 'link',
|
||||||
|
'link_or_button' => 'link_or_button',
|
||||||
|
'list_item' => 'list_item',
|
||||||
|
'optgroup' => 'optgroup',
|
||||||
|
'option' => 'option',
|
||||||
|
'question' => 'question',
|
||||||
|
'radio' => 'radio',
|
||||||
|
'region' => 'region',
|
||||||
|
'section' => 'section',
|
||||||
|
'select' => 'select',
|
||||||
|
'table' => 'table',
|
||||||
|
'table_row' => 'table_row',
|
||||||
|
'text' => 'text',
|
||||||
|
'xpath_element' => 'xpath_element',
|
||||||
|
'form_row' => 'form_row',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behat by default comes with XPath, CSS and named selectors,
|
||||||
|
* named selectors are a mapping between names (like button) and
|
||||||
|
* xpaths that represents that names and includes a placeholder that
|
||||||
|
* will be replaced by the locator. These are Moodle's own xpaths.
|
||||||
|
*
|
||||||
|
* @var XPaths for moodle elements.
|
||||||
|
*/
|
||||||
|
protected static $moodleselectors = array(
|
||||||
|
'activity' => <<<XPATH
|
||||||
|
.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][normalize-space(.) = %locator% ]
|
||||||
|
XPATH
|
||||||
|
, 'block' => <<<XPATH
|
||||||
|
.//*[@data-block][contains(concat(' ', normalize-space(@class), ' '), concat(' ', %locator%, ' ')) or
|
||||||
|
descendant::*[self::h2|self::h3][normalize-space(.) = %locator%] or
|
||||||
|
@aria-label = %locator%]
|
||||||
|
XPATH
|
||||||
|
, 'dialogue' => <<<XPATH
|
||||||
|
.//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue ') and
|
||||||
|
normalize-space(descendant::div[
|
||||||
|
contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hd ')
|
||||||
|
]) = %locator%] |
|
||||||
|
.//div[contains(concat(' ', normalize-space(@class), ' '), ' yui-dialog ') and
|
||||||
|
normalize-space(descendant::div[@class='hd']) = %locator%]
|
||||||
|
XPATH
|
||||||
|
, 'list_item' => <<<XPATH
|
||||||
|
.//li[contains(normalize-space(.), %locator%) and not(.//li[contains(normalize-space(.), %locator%)])]
|
||||||
|
XPATH
|
||||||
|
, 'question' => <<<XPATH
|
||||||
|
.//div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]
|
||||||
|
[contains(div[@class='content']/div[contains(concat(' ', normalize-space(@class), ' '), ' formulation ')], %locator%)]
|
||||||
|
XPATH
|
||||||
|
, 'region' => <<<XPATH
|
||||||
|
.//*[self::div | self::section | self::aside | self::header | self::footer][./@id = %locator%]
|
||||||
|
XPATH
|
||||||
|
, 'section' => <<<XPATH
|
||||||
|
.//li[contains(concat(' ', normalize-space(@class), ' '), ' section ')][./descendant::*[self::h3]
|
||||||
|
[normalize-space(.) = %locator%][contains(concat(' ', normalize-space(@class), ' '), ' sectionname ') or
|
||||||
|
contains(concat(' ', normalize-space(@class), ' '), ' section-title ')]] |
|
||||||
|
.//div[contains(concat(' ', normalize-space(@class), ' '), ' sitetopic ')]
|
||||||
|
[./descendant::*[self::h2][normalize-space(.) = %locator%] or %locator% = 'frontpage']
|
||||||
|
XPATH
|
||||||
|
, 'table' => <<<XPATH
|
||||||
|
.//table[(./@id = %locator% or contains(.//caption, %locator%) or contains(.//th, %locator%) or contains(concat(' ', normalize-space(@class), ' '), %locator% ))]
|
||||||
|
XPATH
|
||||||
|
, 'table_row' => <<<XPATH
|
||||||
|
.//tr[contains(normalize-space(.), %locator%) and not(.//tr[contains(normalize-space(.), %locator%)])]
|
||||||
|
XPATH
|
||||||
|
, 'text' => <<<XPATH
|
||||||
|
.//*[contains(., %locator%) and not(.//*[contains(., %locator%)])]
|
||||||
|
XPATH
|
||||||
|
, 'form_row' => <<<XPATH
|
||||||
|
.//*[self::label or self::div[contains(concat(' ', @class, ' '), ' fstaticlabel ')]][contains(., %locator%)]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
|
||||||
|
XPATH
|
||||||
|
);
|
||||||
|
|
||||||
|
protected static $customselectors = [
|
||||||
|
'field' => [
|
||||||
|
'upstream' => <<<XPATH
|
||||||
|
.//*
|
||||||
|
[%fieldFilterWithPlaceholder%][%notFieldTypeFilter%][%fieldMatchWithPlaceholder%]
|
||||||
|
|
|
||||||
|
.//label[%tagTextMatch%]//.//*[%fieldFilterWithPlaceholder%][%notFieldTypeFilter%]
|
||||||
|
|
|
||||||
|
.//*
|
||||||
|
[%fieldFilterWithoutPlaceholder%][%notFieldTypeFilter%][%fieldMatchWithoutPlaceholder%]
|
||||||
|
|
|
||||||
|
.//label[%tagTextMatch%]//.//*[%fieldFilterWithoutPlaceholder%][%notFieldTypeFilter%]
|
||||||
|
XPATH
|
||||||
|
,
|
||||||
|
'filemanager' => <<<XPATH
|
||||||
|
+.//*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']
|
||||||
|
XPATH
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed selectors getter.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_allowed_selectors() {
|
||||||
|
return static::$allowedselectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed text selectors getter.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_allowed_text_selectors() {
|
||||||
|
return static::$allowedtextselectors;
|
||||||
|
}
|
||||||
|
}
|
|
@ -154,6 +154,8 @@ class behat_hooks extends behat_base {
|
||||||
// Now that we are MOODLE_INTERNAL.
|
// Now that we are MOODLE_INTERNAL.
|
||||||
require_once(__DIR__ . '/../../behat/classes/behat_command.php');
|
require_once(__DIR__ . '/../../behat/classes/behat_command.php');
|
||||||
require_once(__DIR__ . '/../../behat/classes/behat_selectors.php');
|
require_once(__DIR__ . '/../../behat/classes/behat_selectors.php');
|
||||||
|
require_once(__DIR__ . '/../../behat/classes/partial_named_selector.php');
|
||||||
|
require_once(__DIR__ . '/../../behat/classes/exact_named_selector.php');
|
||||||
require_once(__DIR__ . '/../../behat/classes/behat_context_helper.php');
|
require_once(__DIR__ . '/../../behat/classes/behat_context_helper.php');
|
||||||
require_once(__DIR__ . '/../../behat/classes/util.php');
|
require_once(__DIR__ . '/../../behat/classes/util.php');
|
||||||
require_once(__DIR__ . '/../../testing/classes/test_lock.php');
|
require_once(__DIR__ . '/../../testing/classes/test_lock.php');
|
||||||
|
@ -314,18 +316,24 @@ class behat_hooks extends behat_base {
|
||||||
behat_context_helper::set_environment($scope->getEnvironment());
|
behat_context_helper::set_environment($scope->getEnvironment());
|
||||||
|
|
||||||
// We need the Mink session to do it and we do it only before the first scenario.
|
// We need the Mink session to do it and we do it only before the first scenario.
|
||||||
$behatselectorclass = 'behat_selectors';
|
$namedpartialclass = 'behat_partial_named_selector';
|
||||||
|
$namedexactclass = 'behat_exact_named_selector';
|
||||||
|
|
||||||
if ($suitename !== 'default') {
|
if ($suitename !== 'default') {
|
||||||
$overriddenselectorclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, true);
|
// If override selector exist, then set it as default behat selectors class.
|
||||||
|
$overrideclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, 'named_partial', true);
|
||||||
// If override slector exist, then set it as default behat selectors class.
|
if (class_exists($overrideclass)) {
|
||||||
if (class_exists($overriddenselectorclass)) {
|
$namedpartialclass = $overrideclass;
|
||||||
$behatselectorclass = $overriddenselectorclass;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$behatselectorclass = new $behatselectorclass();
|
// If override selector exist, then set it as default behat selectors class.
|
||||||
$behatselectorclass::register_moodle_selectors($session);
|
$overrideclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, 'named_exact', true);
|
||||||
|
if (class_exists($overrideclass)) {
|
||||||
|
$namedexactclass = $overrideclass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->getSession()->getSelectorsHandler()->registerSelector('named_partial', new $namedpartialclass());
|
||||||
|
$this->getSession()->getSelectorsHandler()->registerSelector('named_exact', new $namedexactclass());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset mink session between the scenarios.
|
// Reset mink session between the scenarios.
|
||||||
|
@ -619,4 +627,3 @@ class behat_hooks extends behat_base {
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class behat_stop_exception extends \Exception {
|
class behat_stop_exception extends \Exception {
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue