public function SelectorsContext::addSelectorNameForXPathSelector in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.4
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForXpathSelector()
- 8.5 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForXPathSelector()
- 8.6 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForXPathSelector()
- 8.7 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForXPathSelector()
- 9.0.x tests/features/bootstrap/SelectorsContext.php \SelectorsContext::addSelectorNameForXpathSelector()
#Selector : To add a new selector name with a XPath selector.
Exmaple 1: When I add "page title" selector for "//h1[contains(@class, 'page-header')" xpath selector Example 2: And I add "Dashboard" selector for "//*[@id='navbar-link-admin-dashboard']" xpath selector Example 3: And I add "Vertical orientation" selector for "//*[@id='navbar-item--2-tray']/div/div[2]/div/button" xpath 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<xpathSelector>[^"]*)" xpath selector$/
File
- tests/
features/ bootstrap/ SelectorsContext.php, line 198
Class
- SelectorsContext
- Defines application features from the specific context.
Code
public function addSelectorNameForXPathSelector($selectorName, $xpathSelector) {
if (!empty($selectorName) && $selectorName != '' && !empty($xpathSelector) && $xpathSelector != '') {
// Add the selector name for the XPath selector to the selectors array.
$this->xpathSelectors[$selectorName] = $xpathSelector;
// Registor the name for the XPath selecor.
$selectorHandler = $this
->getSession()
->getSelectorsHandler()
->getSelector('named');
$selectorHandler
->registerNamedXpath($selectorName, $xpathSelector);
}
else {
throw new Exception('The selector name and the XPath selector must not be empty.');
}
}