MDL-66559 behat: Documentation for component selectors

This commit is contained in:
Tim Hunt 2019-10-05 13:50:43 +01:00 committed by Andrew Nicols
parent 5c783f140e
commit 33da028c27
5 changed files with 99 additions and 9 deletions

View file

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle-specific selectors.
* Class representing a named selector that can be used in Behat tests.
*
* @package core
* @category test
@ -24,7 +24,21 @@
*/
/**
* Moodle-specific selectors.
* Class representing a named selector that can be used in Behat tests.
*
* Named selectors are what make Behat steps like
* Then I should see "Useful text" in the "General" "fieldset"
* Here, "fieldset" is the named selector, and "General" is the locator.
*
* Selectors can either be exact, in which case the locator needs to
* match exactly, or can be partial, for example the way
* When I click "Save" "button"
* will trigger a "Save changes" button.
*
* Instances of this class get returned by the get_exact_named_selectors()
* and get_partial_named_selectors() methods in classes like behat_mod_mymod.
* The code that makes the magic work is in the trait behat_named_selector
* used by both behat_exact_named_selector and behat_partial_named_selector.
*
* @package core
* @category test
@ -44,8 +58,22 @@ class behat_component_named_selector {
/**
* Create the selector definition.
*
* As an example, if you define
* new behat_component_named_selector('Message',
* [".//*[@data-conversation-id]//img[contains(@alt, %locator%)]/.."])
* in get_partial_named_selectors in behat_message in
* message/tests/behat/behat_message.php, then steps like
* When "Group 1" "core_message > Message" should exist
* will work.
*
* Text selectors are things that contain other things (e.g. some particular text), e.g.
* Then I can see "Some text" in the "Whatever" "text_selector"
* whereas non-text selectors are atomic things, like
* When I click the "Whatever" "widget".
*
* @param string $alias The 'friendly' name of the thing. This will be prefixed with the component name.
* @param array $xpaths A list of xpaths
* For example, if the mod_mymod plugin, says 'Thingy', then "mod_mymod > Thingy" becomes a selector.
* @param array $xpaths A list of xpaths one or more XPaths that the selector gets transformed into.
* @param bool $istextselector Whether this selector can also be used as a text selector.
*/
public function __construct(string $alias, array $xpaths, bool $istextselector = true) {