Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Class representing a named selector that can be used in Behat tests. More...
Public Member Functions | |
__construct (string $alias, array $xpaths, bool $istextselector=true) | |
Create the selector definition. | |
get_alias (string $component) | |
Get the alias of the selector. | |
get_combined_xpath () | |
Get the list of combined xpaths. | |
get_name (string $component) | |
Get the name of the selector. | |
is_text_selector () | |
Whether this is a text selector. | |
Protected Attributes | |
string | $alias |
string | $istextselector |
array | $xpaths |
List of xpaths. | |
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.
behat_component_named_selector::__construct | ( | string | $alias, |
array | $xpaths, | ||
bool | $istextselector = true ) |
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".
string | $alias | The 'friendly' name of the thing. This will be prefixed with the component name. For example, if the mod_mymod plugin, says 'Thingy', then "mod_mymod > Thingy" becomes a selector. |
array | $xpaths | A list of xpaths one or more XPaths that the selector gets transformed into. |
bool | $istextselector | Whether this selector can also be used as a text selector. |
behat_component_named_selector::get_alias | ( | string | $component | ) |
Get the alias of the selector.
This is the human-readable name that you would typically interact with.
string | $component |
string |
behat_component_named_selector::get_combined_xpath | ( | ) |
Get the list of combined xpaths.
string | The list of xpaths combined with the xpath | (OR) operator |
behat_component_named_selector::get_name | ( | string | $component | ) |
Get the name of the selector.
This is a back-end feature and contains a namespaced md5 of the human-readable name.
string | $component |
string |
behat_component_named_selector::is_text_selector | ( | ) |
Whether this is a text selector.
bool |