Completed
Push — master ( a83b14...54219d )
by Yaroslav
18:18
created

takeScreenShotAfterFailedStep()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
use Behat\Behat\Hook\Scope\AfterStepScope;
4
use Behat\Mink\Driver\Selenium2Driver;
5
use Behat\MinkExtension\Context\RawMinkContext;
6
use Behat\Testwork\Tester\Result\TestResult;
7
8
class ScreenShotAfterFailContext extends RawMinkContext
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * @AfterStep
12
     * @param AfterStepScope $scope
13
     */
14
    public function takeScreenShotAfterFailedStep(AfterStepScope $scope)
15
    {
16
        if ($scope->getTestResult()->getResultCode() !== TestResult::FAILED) {
17
            return;
18
        }
19
20
        $driver = $this->getSession()->getDriver();
21
22
        if (!($driver instanceof Selenium2Driver)) {
23
            return;
24
        }
25
26
        $fileName = basename($scope->getFeature()->getFile()) . '_' . $scope->getStep()->getLine();
27
        file_put_contents($this->getScreenShotDir() . $fileName . '.png', $this->getSession()->getDriver()->getScreenshot());
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    private function getScreenShotDir()
34
    {
35
        return '/app/tests/app/var/screens/';
36
    }
37
}
38