Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Class representing a named selector that can be used in Behat tests.

Copyright: 2019 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 124 lines (5 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

behat_component_named_selector:: (5 methods):
  __construct()
  is_text_selector()
  get_name()
  get_alias()
  get_combined_xpath()


Class: behat_component_named_selector  - X-Ref

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.

__construct(string $alias, array $xpaths, bool $istextselector = true)   X-Ref
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 one or more XPaths that the selector gets transformed into.
param: bool $istextselector Whether this selector can also be used as a text selector.

is_text_selector()   X-Ref
Whether this is a text selector.

return: bool

get_name(string $component)   X-Ref
Get the name of the selector.
This is a back-end feature and contains a namespaced md5 of the human-readable name.

param: string $component
return: string

get_alias(string $component)   X-Ref
Get the alias of the selector.
This is the human-readable name that you would typically interact with.

param: string $component
return: string

get_combined_xpath()   X-Ref
Get the list of combined xpaths.

return: string The list of xpaths combined with the xpath | (OR) operator