use Behat\Mink\Element\Element;
use Behat\Mink\Session;
+require_once(__DIR__ . '/classes/component_named_selector.php');
+require_once(__DIR__ . '/classes/component_named_replacement.php');
+
/**
* Steps definitions base class.
*
$selector = 'xpath';
}
- // Convert to named_partial where the selector type is not named_partial, named_exact, xpath, or css.
+ // Convert to a named selector where the selector type is not a known selector.
$converttonamed = !$this->getSession()->getSelectorsHandler()->isSelectorRegistered($selector);
$converttonamed = $converttonamed && 'xpath' !== $selector;
if ($converttonamed) {
+ if (behat_partial_named_selector::is_deprecated_selector($selector)) {
+ if ($replacement = behat_partial_named_selector::get_deprecated_replacement($selector)) {
+ error_log("The '{$selector}' selector has been replaced with {$replacement}");
+ $selector = $replacement;
+ }
+ } else if (behat_exact_named_selector::is_deprecated_selector($selector)) {
+ if ($replacement = behat_exact_named_selector::get_deprecated_replacement($selector)) {
+ error_log("The '{$selector}' selector has been replaced with {$replacement}");
+ $selector = $replacement;
+ }
+ }
+
$allowedpartialselectors = behat_partial_named_selector::get_allowed_selectors();
$allowedexactselectors = behat_exact_named_selector::get_allowed_selectors();
if (isset($allowedpartialselectors[$selector])) {
$locator = behat_selectors::normalise_named_selector($allowedexactselectors[$selector], $locator);
$selector = 'named_exact';
} else {
- throw new ExpectationException("The '{$selector}' selector type is not registered.", $this);
+ throw new ExpectationException("The '{$selector}' selector type is not registered.", $this->getSession()->getDriver());
}
}
public static function get_extended_timeout() : int {
return self::get_real_timeout(10);
}
+
+ /**
+ * Return a list of the exact named selectors for the component.
+ *
+ * Named selectors are what make Behat steps like
+ * Then I should see "Useful text" in the "General" "fieldset"
+ * work. Here, "fieldset" is the named selector, and "General" is the locator.
+ *
+ * If you override this method in your plugin (e.g. mod_mymod), to define
+ * new selectors specific to your plugin. For example, if you returned
+ * new behat_component_named_selector('Thingy',
+ * [".//some/xpath//img[contains(@alt, %locator%)]/.."])
+ * then
+ * Then I should see "Useful text" in the "Whatever" "mod_mymod > Thingy"
+ * would work.
+ *
+ * This method should return a list of {@link behat_component_named_selector} and
+ * the docs on that class explain how it works.
+ *
+ * @return behat_component_named_selector[]
+ */
+ public static function get_exact_named_selectors(): array {
+ return [];
+ }
+
+ /**
+ * Return a list of the partial named selectors for the component.
+ *
+ * Like the exact named selectors above, but the locator only
+ * needs to match part of the text. For example, the standard
+ * "button" is a partial selector, so:
+ * When I click "Save" "button"
+ * will activate "Save changes".
+ *
+ * @return behat_component_named_selector[]
+ */
+ public static function get_partial_named_selectors(): array {
+ return [];
+ }
+
+ /**
+ * Return a list of the Mink named replacements for the component.
+ *
+ * Named replacements allow you to define parts of an xpath that can be reused multiple times, or in multiple
+ * xpaths.
+ *
+ * This method should return a list of {@link behat_component_named_replacement} and the docs on that class explain
+ * how it works.
+ *
+ * @return behat_component_named_replacement[]
+ */
+ public static function get_named_replacements(): array {
+ return [];
+ }
}