-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWebContext.php
More file actions
95 lines (84 loc) · 2.56 KB
/
WebContext.php
File metadata and controls
95 lines (84 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace AppBundle\Behat\Context;
use Behat\Mink\Exception\UnsupportedDriverActionException;
/**
*
* @author Athlan
*
*/
class WebContext extends DefaultContext
{
/**
* @When /^I go to the website root$/
*/
public function iGoToTheWebsiteRoot()
{
$this->getSession()->visit('/');
}
/**
* @Given /^I am on the "([^"]+)" page?$/
* @When /^(?:|I )go to the "([^"]+)" page?$/
*/
public function iAmOnThePage($page)
{
$this->getSession()->visit($this->generateUrl($page));
}
/**
* Checks, that current page PATH matches regular expression.
*
* @Then /^(?:|I )should be redirected to (?P<pattern>"(?:[^"]|\\")*")$/
*/
public function iAmRedirectedToUrl($pattern)
{
$this->assertSession()->addressMatches($this->fixStepArgument($pattern));
}
/**
* @Then /^(?:|I )should be on the "([^"]+)" (page)$/
* @Then /^(?:|I )should be redirected to the "([^"]+)" (page)$/
* @Then /^(?:|I )should still be on the "([^"]+)" (page)$/
*/
public function iShouldBeOnThePage($page)
{
$this->assertSession()->addressEquals($this->generateUrl($page));
try {
$this->assertSession()->statusCodeEquals(200);
} catch (UnsupportedDriverActionException $e) {
}
}
/**
* @When /^(?:|I )click into "([^"]+)" link?$/
* @When /^(?:|I )click "([^"]+)" link?$/
*/
public function iClickLink($link)
{
$this->clickLink($link);
}
/**
* @When /^Print page content$/
*/
public function printPageContent()
{
echo $this->getSession()->getPage()->getContent();
}
/**
* @Then /^(?:|I )should see "([^"]+)" (heading|headline)$/
*/
public function iShouldSeeHeading($heading)
{
$this->assertSession()->elementTextContains('xpath', '//h1 | //h2', $this->fixStepArgument($heading));
}
/**
* @Then /^(?:|I )should see (?P<type>[(error|success|info|warning)]+) message "(?P<message>[^"]+)"$/
*/
public function iShouldSeeMessage($type, $message)
{
$classesMap = [
'success' => 'success',
'error' => 'danger',
'info' => 'info',
'warning' => 'warning',
];
$class = $classesMap[$type];
$this->assertSession()->elementTextContains('xpath', '//div[@class="alert alert-' . $class . '"]', $this->fixStepArgument($message));
}
}