-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathBaseExtension.php
107 lines (97 loc) · 2.31 KB
/
BaseExtension.php
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
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Extension;
use Codeception\Events;
use Codeception\Exception\ModuleRequireException;
use Codeception\Extension;
use Codeception\Module\WebDriver;
/**
* Class BaseExtension
*/
class BaseExtension extends Extension
{
/**
* Codeception Events Mapping to methods
*
* @var array
*/
public static $events = [
Events::TEST_BEFORE => 'beforeTest',
Events::STEP_BEFORE => 'beforeStep'
];
/**
* The current URI of the active page
*
* @var string
*/
private $uri;
/**
* Codeception event listener function - initialize uri before test
*
* @param \Codeception\Event\TestEvent $e
* @return void
* @throws \Exception
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeTest(\Codeception\Event\TestEvent $e)
{
$this->uri = null;
}
/**
* Codeception event listener function - check for page uri change before step
*
* @param \Codeception\Event\StepEvent $e
* @return void
* @throws \Exception
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeStep(\Codeception\Event\StepEvent $e)
{
$this->pageChanged();
}
/**
* WebDriver instance for execution
*
* @return WebDriver
* @throws ModuleRequireException
*/
public function getDriver()
{
return $this->getModule($this->config['driver']);
}
/**
* Gets the active page URI from the start of the most recent step
*
* @return string
*/
public function getUri()
{
return $this->uri;
}
/**
* Check if page uri has changed
*
* @return boolean
*/
protected function pageChanged()
{
try {
if ($this->getDriver() === null) {
return false;
}
$currentUri = $this->getDriver()->_getCurrentUri();
if ($this->uri !== $currentUri) {
$this->uri = $currentUri;
return true;
}
} catch (\Exception $e) {
// just fall through and return false
}
return false;
}
}