public function SelectorsContext::IAddSelectorsFromFile in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.7
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::iAddSelectorsFromFile()
- 8.4 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::IAddSelectorsFromFile()
- 8.5 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::IAddSelectorsFromFile()
- 8.6 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::IAddSelectorsFromFile()
- 9.0.x tests/features/bootstrap/SelectorsContext.php \SelectorsContext::iAddSelectorsFromFile()
#Selector : To add a new selector name with a css selector.
Exmaple 1: When I load selectors from "" file 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.
@When /^I add selectors from "(?P<fileName>[^"]*)" file$/
File
- tests/
features/ bootstrap/ SelectorsContext.php, line 221
Class
- SelectorsContext
- Defines application features from the specific context.
Code
public function IAddSelectorsFromFile($fileName) {
if (!empty($fileName) && $fileName != '' && isset($this->filesPath) && $this->filesPath != '') {
// Get the content of the file.
$fileContent = file_get_contents($this->filesPath . $fileName);
if (!empty($fileContent) && $fileContent != '') {
$fileSelectors = Yaml::parse($fileContent);
// Register all CSS selectors in the file.
if (isset($fileSelectors['css']) && count($fileSelectors['css'])) {
foreach ($fileSelectors['css'] as $selectorName => $cssSelecter) {
// Add the css selector to the css selector array.
$this->cssSelectors[$selectorName] = $cssSelecter;
// Translate the CSS selector to XPath selector.
$css = new CssSelector();
$xpathSelector = $css
->translateToXPath($cssSelecter);
// Registor the name for the CSS selecor.
$selectorHandler = $this
->getSession()
->getSelectorsHandler()
->getSelector('named');
$selectorHandler
->registerNamedXpath($selectorName, $xpathSelector);
}
}
// Register all XPath selectors in the file.
if (isset($fileSelectors['xpath']) && count($fileSelectors['xpath'])) {
foreach ($fileSelectors['xpath'] as $selectorName => $xpathSelector) {
// Add the selector name for the XPath selector to the xpath 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 file "' . $this->filesPath . $fileName . '" is empty or does not exist under SelectorsContext');
}
}
else {
throw new Exception('No file name or the file_path parameter is not right in the behat.yml file');
}
}