public function SelectorsContext::__construct in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::__construct()
- 8.4 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::__construct()
- 8.6 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::__construct()
- 8.7 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::__construct()
- 9.0.x tests/features/bootstrap/SelectorsContext.php \SelectorsContext::__construct()
Initializes context.
Every scenario gets its own context instance. You can also pass arbitrary arguments to the context constructor through behat.yml.
File
- tests/
features/ bootstrap/ SelectorsContext.php, line 53
Class
- SelectorsContext
- Defines application features from the specific context.
Code
public function __construct(array $parameters) {
if (isset($parameters['selectors'])) {
if (isset($parameters['selectors']['css']) || isset($parameters['selectors']['xpath']) || isset($parameters['files_path']) && isset($parameters['files'])) {
if (isset($parameters['selectors']['css']) && count($parameters['selectors']['css'])) {
$this->cssSelectors = $parameters['selectors']['css'];
}
if (isset($parameters['selectors']['xpath']) && count($parameters['selectors']['xpath'])) {
$this->xpathSelectors = $parameters['selectors']['xpath'];
}
if (isset($parameters['files_path']) && $parameters['files_path'] != '' && isset($parameters['files']) && count($parameters['files'])) {
$this->filesPath = $parameters['files_path'];
foreach ($parameters['files'] as $selectorFile) {
// Get the content of the selector file.
$fileContent = file_get_contents($this->filesPath . $selectorFile);
if (!empty($fileContent) && $fileContent != '') {
$fileSelectors = Yaml::parse($fileContent);
// Add all list of CSS selectors to the cssSelectors Array.
if (isset($fileSelectors['css']) && count($fileSelectors['css'])) {
foreach ($fileSelectors['css'] as $selectorName => $cssSelecter) {
$this->cssSelectors[$selectorName] = $cssSelecter;
}
}
// Add all list of XPath selectors to the xpathSelectors Array.
if (isset($fileSelectors['xpath']) && count($fileSelectors['xpath'])) {
foreach ($fileSelectors['xpath'] as $selectorName => $xpathSelector) {
$this->xpathSelectors[$selectorName] = $xpathSelector;
}
}
}
else {
throw new Exception('The file "' . $this->filesPath . $selectorFile . '" is empty or does not exist under SelectorsContext');
}
}
}
}
else {
throw new Exception('behat.yml should include "selectors" with css, xpath, files_path, and files parametars. under SelectorsContext');
}
}
}