navigator = $navigator; $this->dispatcher = $dispatcher; return $this; } /** * @return WebDriverDispatcher */ public function getDispatcher() { return $this->dispatcher; } /** * @param mixed $method * @return void */ protected function dispatch($method) { if (!$this->dispatcher) { return; } $arguments = func_get_args(); unset($arguments[0]); $this->dispatcher->dispatch($method, $arguments); } /** * @return WebDriverNavigation */ public function getNavigator() { return $this->navigator; } /** * @return $this * @throws WebDriverException */ public function back() { $this->dispatch( 'beforeNavigateBack', $this->getDispatcher()->getDefaultDriver() ); try { $this->navigator->back(); } catch (WebDriverException $exception) { $this->dispatchOnException($exception); } $this->dispatch( 'afterNavigateBack', $this->getDispatcher()->getDefaultDriver() ); return $this; } /** * @return $this * @throws WebDriverException */ public function forward() { $this->dispatch( 'beforeNavigateForward', $this->getDispatcher()->getDefaultDriver() ); try { $this->navigator->forward(); } catch (WebDriverException $exception) { $this->dispatchOnException($exception); } $this->dispatch( 'afterNavigateForward', $this->getDispatcher()->getDefaultDriver() ); return $this; } /** * @return $this * @throws WebDriverException */ public function refresh() { try { $this->navigator->refresh(); return $this; } catch (WebDriverException $exception) { $this->dispatchOnException($exception); } } /** * @param mixed $url * @return $this * @throws WebDriverException */ public function to($url) { $this->dispatch( 'beforeNavigateTo', $url, $this->getDispatcher()->getDefaultDriver() ); try { $this->navigator->to($url); } catch (WebDriverException $exception) { $this->dispatchOnException($exception); } $this->dispatch( 'afterNavigateTo', $url, $this->getDispatcher()->getDefaultDriver() ); return $this; } private function dispatchOnException($exception) { $this->dispatch('onException', $exception); throw $exception; } }