Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
behat_component_named_selector Class Reference

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.
 

Detailed Description

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

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

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.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

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".

Parameters
string$aliasThe '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$xpathsA list of xpaths one or more XPaths that the selector gets transformed into.
bool$istextselectorWhether this selector can also be used as a text selector.

Member Function Documentation

◆ get_alias()

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.

Parameters
string$component
Return values
string

◆ get_combined_xpath()

behat_component_named_selector::get_combined_xpath ( )

Get the list of combined xpaths.

Return values
stringThe list of xpaths combined with the xpath | (OR) operator

◆ get_name()

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.

Parameters
string$component
Return values
string

◆ is_text_selector()

behat_component_named_selector::is_text_selector ( )

Whether this is a text selector.

Return values
bool

The documentation for this class was generated from the following file: