123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- // Copyright 2004-present Facebook. All Rights Reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- namespace Facebook\WebDriver\Support\Events;
- use Facebook\WebDriver\Exception\WebDriverException;
- use Facebook\WebDriver\WebDriverDispatcher;
- use Facebook\WebDriver\WebDriverNavigation;
- class EventFiringWebDriverNavigation
- {
- /**
- * @var WebDriverNavigation
- */
- protected $navigator;
- /**
- * @var WebDriverDispatcher
- */
- protected $dispatcher;
- /**
- * @param WebDriverNavigation $navigator
- * @param WebDriverDispatcher $dispatcher
- */
- public function __construct(WebDriverNavigation $navigator, WebDriverDispatcher $dispatcher)
- {
- $this->navigator = $navigator;
- $this->dispatcher = $dispatcher;
- }
- /**
- * @return WebDriverDispatcher
- */
- public function getDispatcher()
- {
- return $this->dispatcher;
- }
- /**
- * @return WebDriverNavigation
- */
- public function getNavigator()
- {
- return $this->navigator;
- }
- /**
- * @throws WebDriverException
- * @return $this
- */
- 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;
- }
- /**
- * @throws WebDriverException
- * @return $this
- */
- 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;
- }
- /**
- * @throws WebDriverException
- * @return $this
- */
- public function refresh()
- {
- try {
- $this->navigator->refresh();
- return $this;
- } catch (WebDriverException $exception) {
- $this->dispatchOnException($exception);
- throw $exception;
- }
- }
- /**
- * @param mixed $url
- * @throws WebDriverException
- * @return $this
- */
- public function to($url)
- {
- $this->dispatch(
- 'beforeNavigateTo',
- $url,
- $this->getDispatcher()->getDefaultDriver()
- );
- try {
- $this->navigator->to($url);
- } catch (WebDriverException $exception) {
- $this->dispatchOnException($exception);
- throw $exception;
- }
- $this->dispatch(
- 'afterNavigateTo',
- $url,
- $this->getDispatcher()->getDefaultDriver()
- );
- return $this;
- }
- /**
- * @param mixed $method
- * @param mixed ...$arguments
- */
- protected function dispatch($method, ...$arguments)
- {
- if (!$this->dispatcher) {
- return;
- }
- $this->dispatcher->dispatch($method, $arguments);
- }
- /**
- * @param WebDriverException $exception
- */
- protected function dispatchOnException(WebDriverException $exception)
- {
- $this->dispatch('onException', $exception);
- }
- }
|