1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Tests\Features\Context; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
7
|
|
|
use Behat\Behat\Hook\Scope\AfterStepScope; |
8
|
|
|
use Behat\Mink\Driver\Selenium2Driver; |
9
|
|
|
use Behat\Mink\Element\Element; |
10
|
|
|
use Behat\Mink\Exception\UnsupportedDriverActionException; |
11
|
|
|
use Behat\Symfony2Extension\Context\KernelAwareContext; |
12
|
|
|
use Behat\Symfony2Extension\Context\KernelDictionary; |
13
|
|
|
use Behat\Symfony2Extension\Driver\KernelDriver; |
14
|
|
|
use Knp\FriendlyContexts\Context\RawMinkContext; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Feature context. |
18
|
|
|
*/ |
19
|
|
|
class FeatureContext extends RawMinkContext implements Context, SnippetAcceptingContext, KernelAwareContext |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
use KernelDictionary; |
22
|
|
|
|
23
|
|
|
/** |
|
|
|
|
24
|
|
|
* @Given /^I wait (\d+) second$/ |
25
|
|
|
* @Given /^I wait (\d+) seconds$/ |
26
|
|
|
*/ |
27
|
|
|
public function iWaitSeconds($nbr) |
28
|
|
|
{ |
29
|
|
|
$this->getSession()->wait($nbr * 1000); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getSymfonyProfile() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$driver = $this->getSession()->getDriver(); |
35
|
|
|
if (!$driver instanceof KernelDriver) { |
36
|
|
|
throw new UnsupportedDriverActionException( |
37
|
|
|
'You need to tag the scenario with '. |
|
|
|
|
38
|
|
|
'"@mink:symfony2". Using the profiler is not '. |
|
|
|
|
39
|
|
|
'supported by %s', $driver |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$profile = $driver->getClient()->getProfile(); |
|
|
|
|
44
|
|
|
if (false === $profile) { |
45
|
|
|
throw new \RuntimeException( |
46
|
|
|
'The profiler is disabled. Activate it by setting '. |
|
|
|
|
47
|
|
|
'framework.profiler.only_exceptions to false in '. |
|
|
|
|
48
|
|
|
'your config' |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $profile; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
|
|
|
|
56
|
|
|
* @Then /^I should see the css property "(.+)" of "(.+)" with "(.+)"$/ |
57
|
|
|
* |
58
|
|
|
* @param string $property |
59
|
|
|
* @param string $value |
|
|
|
|
60
|
|
|
*/ |
61
|
|
|
public function iShouldSeeCssOfWith($property, $elementId, $value) |
62
|
|
|
{ |
63
|
|
|
$script = "return $('#".$elementId."').css('".$property."') === '".$value."';"; |
64
|
|
|
$evaluated = $this->getSession()->evaluateScript($script); |
65
|
|
|
if (!$evaluated) { |
66
|
|
|
throw new \RuntimeException('The element with id "'.$elementId.'" and css property "'.$property.': '.$value.';" not found.'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
|
|
|
|
71
|
|
|
* @Then I should see background-image of :id with relative url :url |
72
|
|
|
*/ |
73
|
|
|
public function iShouldSeeBackgroundImageWithRelativeUrl($id, $url) |
74
|
|
|
{ |
75
|
|
|
$session = $this->getSession(); |
76
|
|
|
$base_url = $session->getCurrentUrl(); |
|
|
|
|
77
|
|
|
$parse_url = parse_url($base_url); |
|
|
|
|
78
|
|
|
$base_url = rtrim($base_url, $parse_url['path']); |
|
|
|
|
79
|
|
|
$url = rtrim($base_url, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($url, DIRECTORY_SEPARATOR); |
|
|
|
|
80
|
|
|
$this->iShouldSeeCssOfWith('background-image', $id, 'url("'.$url.'")'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
|
|
|
|
84
|
|
|
* @Then the title should be :title |
85
|
|
|
*/ |
86
|
|
|
public function theTitleShouldBe($title) |
87
|
|
|
{ |
88
|
|
|
$element = $this->getSession()->getPage()->find( |
89
|
|
|
'xpath', |
90
|
|
|
sprintf('//title[normalize-space(text()) = "%s"]', $title) |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
if (null === $element) { |
94
|
|
|
$message = sprintf('"%s" is not the title of the page', $title); |
95
|
|
|
throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
|
|
|
|
100
|
|
|
* @AfterStep |
101
|
|
|
*/ |
102
|
|
|
public function printLastResponseOnError(AfterStepScope $event) |
103
|
|
|
{ |
104
|
|
|
if (!$event->getTestResult()->isPassed()) { |
105
|
|
|
$this->saveDebugScreenshot(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @Then /^save screenshot$/ |
111
|
|
|
*/ |
112
|
|
|
public function saveDebugScreenshot() |
113
|
|
|
{ |
114
|
|
|
$driver = $this->getSession()->getDriver(); |
115
|
|
|
|
116
|
|
|
if (!$driver instanceof Selenium2Driver) { |
117
|
|
|
return; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if (!getenv('BEHAT_SCREENSHOTS')) { |
121
|
|
|
return; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$filename = microtime(true).'.png'; |
125
|
|
|
$path = $this->getContainer() |
126
|
|
|
->getParameter('kernel.root_dir').'/../behat_screenshots'; |
127
|
|
|
|
128
|
|
|
if (!file_exists($path)) { |
129
|
|
|
mkdir($path); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$this->saveScreenshot($filename, $path); |
|
|
|
|
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.