class SocialMinkContext in Open Social 8
Same name and namespace in other branches
- 8.2 tests/behat/features/bootstrap/SocialMinkContext.php \SocialMinkContext
Defines application features from the specific context.
Hierarchy
- class \SocialMinkContext extends \Drupal\DrupalExtension\Context\MinkContext
Expanded class hierarchy of SocialMinkContext
1 string reference to 'SocialMinkContext'
File
- tests/
behat/ features/ bootstrap/ SocialMinkContext.php, line 19
View source
class SocialMinkContext extends MinkContext {
/**
* @override MinkContext::assertRegionHeading()
*
* Makes the step case insensitive.
*/
public function assertRegionHeading($heading, $region) {
$regionObj = $this
->getRegion($region);
foreach (array(
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
) as $tag) {
$elements = $regionObj
->findAll('css', $tag);
if (!empty($elements)) {
foreach ($elements as $element) {
if (trim(strtolower($element
->getText())) === strtolower($heading)) {
return;
}
}
}
}
throw new \Exception(sprintf('The heading "%s" was not found in the "%s" region on the page %s', $heading, $region, $this
->getSession()
->getCurrentUrl()));
}
/**
* @Given /^I make a screenshot$/
*/
public function iMakeAScreenshot() {
$this
->iMakeAScreenshotWithFileName('screenshot');
}
/**
* @Given /^I make a screenshot with the name "([^"]*)"$/
*/
public function iMakeAScreenshotWithFileName($filename) {
$screenshot = $this
->getSession()
->getDriver()
->getScreenshot();
$file_and_path = '/var/www/travis_artifacts/' . $filename . '.jpg';
file_put_contents($file_and_path, $screenshot);
}
/**
* @AfterStep
*/
public function takeScreenShotAfterFailedStep(AfterStepScope $scope) {
if (99 === $scope
->getTestResult()
->getResultCode()) {
$driver = $this
->getSession()
->getDriver();
if (!$driver instanceof Selenium2Driver) {
return;
}
$feature = $scope
->getFeature();
$title = $feature
->getTitle();
$filename = date("Ymd-H_i_s");
if (!empty($title)) {
$filename .= '-' . str_replace(' ', '-', strtolower($title));
}
$filename .= '-error';
$this
->iMakeAScreenshotWithFileName($filename);
}
}
/**
* Attaches file to field with specified name.
*
* @When /^(?:|I )attach the file "(?P<path>[^"]*)" to hidden field "(?P<field>(?:[^"]|\\")*)"$/
*/
public function attachFileToHiddenField($field, $path) {
$field = $this
->fixStepArgument($field);
$javascript = "jQuery('#" . $field . "').parent().removeClass('hidden')";
$this
->getSession()
->executeScript($javascript);
$this
->attachFileToField($field, $path);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialMinkContext:: |
public | function | @override MinkContext::assertRegionHeading() | |
SocialMinkContext:: |
public | function | Attaches file to field with specified name. | |
SocialMinkContext:: |
public | function | @Given /^I make a screenshot$/ | |
SocialMinkContext:: |
public | function | @Given /^I make a screenshot with the name "([^"]*)"$/ | |
SocialMinkContext:: |
public | function | @AfterStep |