Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BaseExtension.php
Go to the documentation of this file.
1 <?php
8 
9 use Codeception\Events;
10 use Codeception\Exception\ModuleRequireException;
11 use Codeception\Extension;
12 use Codeception\Module\WebDriver;
13 
17 class BaseExtension extends Extension
18 {
24  public static $events = [
25  Events::TEST_BEFORE => 'beforeTest',
26  Events::STEP_BEFORE => 'beforeStep'
27  ];
28 
34  private $uri;
35 
45  public function beforeTest(\Codeception\Event\TestEvent $e)
46  {
47  $this->uri = null;
48  }
49 
59  public function beforeStep(\Codeception\Event\StepEvent $e)
60  {
61  $this->pageChanged();
62  }
63 
70  public function getDriver()
71  {
72  return $this->getModule($this->config['driver']);
73  }
74 
80  public function getUri()
81  {
82  return $this->uri;
83  }
84 
90  protected function pageChanged()
91  {
92  try {
93  if ($this->getDriver() === null) {
94  return false;
95  }
96  $currentUri = $this->getDriver()->_getCurrentUri();
97 
98  if ($this->uri !== $currentUri) {
99  $this->uri = $currentUri;
100  return true;
101  }
102  } catch (\Exception $e) {
103  // just fall through and return false
104  }
105  return false;
106  }
107 }