public function SelectorsContext::addSelectorNameForCssSelector in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.8
Same name and namespace in other branches
- 8.4 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForCssSelector()
- 8.5 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForCssSelector()
- 8.6 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForCssSelector()
- 8.7 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForCssSelector()
- 9.0.x tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForCssSelector()
Selector : To add a new selector name with a css selector.
Example 1: When I add "mobile logo" selector for "header img#logo" css selector Example 2: And I add "breadcrumb" selector for ".breadcrumb" css selector Example 3: And I add "breadcrumb first link" selector for ".breadcrumb li:nth-child(1) a" css selector.
You could add in the behat.yml file so that you do not need to add the most general selectors in your features. default: suites: default: contexts:
- SelectorsContext: parameters: selectors: css: breadcrumb first link: ".breadcrumb li:nth-child(1) a" xpath: page title: "//h1[contains(@class, 'page-header')"
@When /^I add "(?P<selectorName>[^"]*)" selector for "(?P<cssSelecter>[^"]*)" css selector$/
File
- tests/
features/ bootstrap/ SelectorsContext.php, line 145
Class
- SelectorsContext
- Defines application features from the specific context.
Code
public function addSelectorNameForCssSelector($selectorName, $cssSelecter) {
if (!empty($selectorName) && $selectorName != '' && !empty($cssSelecter) && $cssSelecter != '') {
// Add the selector name for the css selector to the selectors array.
$this->cssSelectors[$selectorName] = $cssSelecter;
// Translate the CSS selector to XPath selector.
$css = new CssSelector();
$xpathSelector = $css
->translateToXPath($cssSelecter);
// Registor the name for the XPath selector.
$selectorHandler = $this
->getSession()
->getSelectorsHandler()
->getSelector('named');
$selectorHandler
->registerNamedXpath($selectorName, $xpathSelector);
}
else {
throw new \Exception('The selector name and the CSS selector must not be empty.');
}
}