updated-packages
This commit is contained in:
406
vendor/php-webdriver/webdriver/lib/Support/Events/EventFiringWebDriver.php
vendored
Normal file
406
vendor/php-webdriver/webdriver/lib/Support/Events/EventFiringWebDriver.php
vendored
Normal file
@@ -0,0 +1,406 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Support\Events;
|
||||
|
||||
use Facebook\WebDriver\Exception\UnsupportedOperationException;
|
||||
use Facebook\WebDriver\Exception\WebDriverException;
|
||||
use Facebook\WebDriver\Interactions\Touch\WebDriverTouchScreen;
|
||||
use Facebook\WebDriver\JavaScriptExecutor;
|
||||
use Facebook\WebDriver\WebDriver;
|
||||
use Facebook\WebDriver\WebDriverBy;
|
||||
use Facebook\WebDriver\WebDriverDispatcher;
|
||||
use Facebook\WebDriver\WebDriverElement;
|
||||
use Facebook\WebDriver\WebDriverOptions;
|
||||
use Facebook\WebDriver\WebDriverTargetLocator;
|
||||
use Facebook\WebDriver\WebDriverWait;
|
||||
|
||||
class EventFiringWebDriver implements WebDriver, JavaScriptExecutor
|
||||
{
|
||||
/**
|
||||
* @var WebDriver
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* @var WebDriverDispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param WebDriver $driver
|
||||
* @param WebDriverDispatcher $dispatcher
|
||||
*/
|
||||
public function __construct(WebDriver $driver, WebDriverDispatcher $dispatcher = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher ?: new WebDriverDispatcher();
|
||||
if (!$this->dispatcher->getDefaultDriver()) {
|
||||
$this->dispatcher->setDefaultDriver($this);
|
||||
}
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriverDispatcher
|
||||
*/
|
||||
public function getDispatcher()
|
||||
{
|
||||
return $this->dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriver
|
||||
*/
|
||||
public function getWebDriver()
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $url
|
||||
* @throws WebDriverException
|
||||
* @return $this
|
||||
*/
|
||||
public function get($url)
|
||||
{
|
||||
$this->dispatch('beforeNavigateTo', $url, $this);
|
||||
|
||||
try {
|
||||
$this->driver->get($url);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
$this->dispatch('afterNavigateTo', $url, $this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverBy $by
|
||||
* @throws WebDriverException
|
||||
* @return array
|
||||
*/
|
||||
public function findElements(WebDriverBy $by)
|
||||
{
|
||||
$this->dispatch('beforeFindBy', $by, null, $this);
|
||||
$elements = [];
|
||||
|
||||
try {
|
||||
foreach ($this->driver->findElements($by) as $element) {
|
||||
$elements[] = $this->newElement($element);
|
||||
}
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->dispatch('afterFindBy', $by, null, $this);
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverBy $by
|
||||
* @throws WebDriverException
|
||||
* @return EventFiringWebElement
|
||||
*/
|
||||
public function findElement(WebDriverBy $by)
|
||||
{
|
||||
$this->dispatch('beforeFindBy', $by, null, $this);
|
||||
|
||||
try {
|
||||
$element = $this->newElement($this->driver->findElement($by));
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->dispatch('afterFindBy', $by, null, $this);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $script
|
||||
* @param array $arguments
|
||||
* @throws WebDriverException
|
||||
* @return mixed
|
||||
*/
|
||||
public function executeScript($script, array $arguments = [])
|
||||
{
|
||||
if (!$this->driver instanceof JavaScriptExecutor) {
|
||||
throw new UnsupportedOperationException(
|
||||
'driver does not implement JavaScriptExecutor'
|
||||
);
|
||||
}
|
||||
|
||||
$this->dispatch('beforeScript', $script, $this);
|
||||
|
||||
try {
|
||||
$result = $this->driver->executeScript($script, $arguments);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->dispatch('afterScript', $script, $this);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $script
|
||||
* @param array $arguments
|
||||
* @throws WebDriverException
|
||||
* @return mixed
|
||||
*/
|
||||
public function executeAsyncScript($script, array $arguments = [])
|
||||
{
|
||||
if (!$this->driver instanceof JavaScriptExecutor) {
|
||||
throw new UnsupportedOperationException(
|
||||
'driver does not implement JavaScriptExecutor'
|
||||
);
|
||||
}
|
||||
|
||||
$this->dispatch('beforeScript', $script, $this);
|
||||
|
||||
try {
|
||||
$result = $this->driver->executeAsyncScript($script, $arguments);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
$this->dispatch('afterScript', $script, $this);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return $this
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
try {
|
||||
$this->driver->close();
|
||||
|
||||
return $this;
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentURL()
|
||||
{
|
||||
try {
|
||||
return $this->driver->getCurrentURL();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getPageSource()
|
||||
{
|
||||
try {
|
||||
return $this->driver->getPageSource();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
try {
|
||||
return $this->driver->getTitle();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getWindowHandle()
|
||||
{
|
||||
try {
|
||||
return $this->driver->getWindowHandle();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return array
|
||||
*/
|
||||
public function getWindowHandles()
|
||||
{
|
||||
try {
|
||||
return $this->driver->getWindowHandles();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
*/
|
||||
public function quit()
|
||||
{
|
||||
try {
|
||||
$this->driver->quit();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $save_as
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function takeScreenshot($save_as = null)
|
||||
{
|
||||
try {
|
||||
return $this->driver->takeScreenshot($save_as);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timeout_in_second
|
||||
* @param int $interval_in_millisecond
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverWait
|
||||
*/
|
||||
public function wait($timeout_in_second = 30, $interval_in_millisecond = 250)
|
||||
{
|
||||
try {
|
||||
return $this->driver->wait($timeout_in_second, $interval_in_millisecond);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverOptions
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
try {
|
||||
return $this->driver->manage();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return EventFiringWebDriverNavigation
|
||||
*/
|
||||
public function navigate()
|
||||
{
|
||||
try {
|
||||
return new EventFiringWebDriverNavigation(
|
||||
$this->driver->navigate(),
|
||||
$this->getDispatcher()
|
||||
);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverTargetLocator
|
||||
*/
|
||||
public function switchTo()
|
||||
{
|
||||
try {
|
||||
return $this->driver->switchTo();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverTouchScreen
|
||||
*/
|
||||
public function getTouch()
|
||||
{
|
||||
try {
|
||||
return $this->driver->getTouch();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
public function execute($name, $params)
|
||||
{
|
||||
try {
|
||||
return $this->driver->execute($name, $params);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverElement $element
|
||||
* @return EventFiringWebElement
|
||||
*/
|
||||
protected function newElement(WebDriverElement $element)
|
||||
{
|
||||
return new EventFiringWebElement($element, $this->getDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, $this);
|
||||
}
|
||||
}
|
142
vendor/php-webdriver/webdriver/lib/Support/Events/EventFiringWebDriverNavigation.php
vendored
Normal file
142
vendor/php-webdriver/webdriver/lib/Support/Events/EventFiringWebDriverNavigation.php
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Support\Events;
|
||||
|
||||
use Facebook\WebDriver\Exception\WebDriverException;
|
||||
use Facebook\WebDriver\WebDriverDispatcher;
|
||||
use Facebook\WebDriver\WebDriverNavigationInterface;
|
||||
|
||||
class EventFiringWebDriverNavigation implements WebDriverNavigationInterface
|
||||
{
|
||||
/**
|
||||
* @var WebDriverNavigationInterface
|
||||
*/
|
||||
protected $navigator;
|
||||
/**
|
||||
* @var WebDriverDispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param WebDriverNavigationInterface $navigator
|
||||
* @param WebDriverDispatcher $dispatcher
|
||||
*/
|
||||
public function __construct(WebDriverNavigationInterface $navigator, WebDriverDispatcher $dispatcher)
|
||||
{
|
||||
$this->navigator = $navigator;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriverDispatcher
|
||||
*/
|
||||
public function getDispatcher()
|
||||
{
|
||||
return $this->dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriverNavigationInterface
|
||||
*/
|
||||
public function getNavigator()
|
||||
{
|
||||
return $this->navigator;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
try {
|
||||
$this->navigator->refresh();
|
||||
|
||||
return $this;
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
424
vendor/php-webdriver/webdriver/lib/Support/Events/EventFiringWebElement.php
vendored
Normal file
424
vendor/php-webdriver/webdriver/lib/Support/Events/EventFiringWebElement.php
vendored
Normal file
@@ -0,0 +1,424 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Support\Events;
|
||||
|
||||
use Facebook\WebDriver\Exception\WebDriverException;
|
||||
use Facebook\WebDriver\Interactions\Internal\WebDriverCoordinates;
|
||||
use Facebook\WebDriver\Internal\WebDriverLocatable;
|
||||
use Facebook\WebDriver\WebDriverBy;
|
||||
use Facebook\WebDriver\WebDriverDimension;
|
||||
use Facebook\WebDriver\WebDriverDispatcher;
|
||||
use Facebook\WebDriver\WebDriverElement;
|
||||
use Facebook\WebDriver\WebDriverPoint;
|
||||
|
||||
class EventFiringWebElement implements WebDriverElement, WebDriverLocatable
|
||||
{
|
||||
/**
|
||||
* @var WebDriverElement
|
||||
*/
|
||||
protected $element;
|
||||
/**
|
||||
* @var WebDriverDispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param WebDriverElement $element
|
||||
* @param WebDriverDispatcher $dispatcher
|
||||
*/
|
||||
public function __construct(WebDriverElement $element, WebDriverDispatcher $dispatcher)
|
||||
{
|
||||
$this->element = $element;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriverDispatcher
|
||||
*/
|
||||
public function getDispatcher()
|
||||
{
|
||||
return $this->dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriverElement
|
||||
*/
|
||||
public function getElement()
|
||||
{
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @throws WebDriverException
|
||||
* @return $this
|
||||
*/
|
||||
public function sendKeys($value)
|
||||
{
|
||||
$this->dispatch('beforeChangeValueOf', $this);
|
||||
|
||||
try {
|
||||
$this->element->sendKeys($value);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
$this->dispatch('afterChangeValueOf', $this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return $this
|
||||
*/
|
||||
public function click()
|
||||
{
|
||||
$this->dispatch('beforeClickOn', $this);
|
||||
|
||||
try {
|
||||
$this->element->click();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
$this->dispatch('afterClickOn', $this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverBy $by
|
||||
* @throws WebDriverException
|
||||
* @return EventFiringWebElement
|
||||
*/
|
||||
public function findElement(WebDriverBy $by)
|
||||
{
|
||||
$this->dispatch(
|
||||
'beforeFindBy',
|
||||
$by,
|
||||
$this,
|
||||
$this->dispatcher->getDefaultDriver()
|
||||
);
|
||||
|
||||
try {
|
||||
$element = $this->newElement($this->element->findElement($by));
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->dispatch(
|
||||
'afterFindBy',
|
||||
$by,
|
||||
$this,
|
||||
$this->dispatcher->getDefaultDriver()
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverBy $by
|
||||
* @throws WebDriverException
|
||||
* @return array
|
||||
*/
|
||||
public function findElements(WebDriverBy $by)
|
||||
{
|
||||
$this->dispatch(
|
||||
'beforeFindBy',
|
||||
$by,
|
||||
$this,
|
||||
$this->dispatcher->getDefaultDriver()
|
||||
);
|
||||
|
||||
try {
|
||||
$elements = [];
|
||||
foreach ($this->element->findElements($by) as $element) {
|
||||
$elements[] = $this->newElement($element);
|
||||
}
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
$this->dispatch(
|
||||
'afterFindBy',
|
||||
$by,
|
||||
$this,
|
||||
$this->dispatcher->getDefaultDriver()
|
||||
);
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return $this
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
try {
|
||||
$this->element->clear();
|
||||
|
||||
return $this;
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute_name
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getAttribute($attribute_name)
|
||||
{
|
||||
try {
|
||||
return $this->element->getAttribute($attribute_name);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $css_property_name
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getCSSValue($css_property_name)
|
||||
{
|
||||
try {
|
||||
return $this->element->getCSSValue($css_property_name);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverPoint
|
||||
*/
|
||||
public function getLocation()
|
||||
{
|
||||
try {
|
||||
return $this->element->getLocation();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverPoint
|
||||
*/
|
||||
public function getLocationOnScreenOnceScrolledIntoView()
|
||||
{
|
||||
try {
|
||||
return $this->element->getLocationOnScreenOnceScrolledIntoView();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WebDriverCoordinates
|
||||
*/
|
||||
public function getCoordinates()
|
||||
{
|
||||
try {
|
||||
return $this->element->getCoordinates();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return WebDriverDimension
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
try {
|
||||
return $this->element->getSize();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getTagName()
|
||||
{
|
||||
try {
|
||||
return $this->element->getTagName();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
try {
|
||||
return $this->element->getText();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisplayed()
|
||||
{
|
||||
try {
|
||||
return $this->element->isDisplayed();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
try {
|
||||
return $this->element->isEnabled();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return bool
|
||||
*/
|
||||
public function isSelected()
|
||||
{
|
||||
try {
|
||||
return $this->element->isSelected();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return $this
|
||||
*/
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->element->submit();
|
||||
|
||||
return $this;
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function getID()
|
||||
{
|
||||
try {
|
||||
return $this->element->getID();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if two element IDs refer to the same DOM element.
|
||||
*
|
||||
* @param WebDriverElement $other
|
||||
* @return bool
|
||||
*/
|
||||
public function equals(WebDriverElement $other)
|
||||
{
|
||||
try {
|
||||
return $this->element->equals($other);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
public function takeElementScreenshot($save_as = null)
|
||||
{
|
||||
try {
|
||||
return $this->element->takeElementScreenshot($save_as);
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
public function getShadowRoot()
|
||||
{
|
||||
try {
|
||||
return $this->element->getShadowRoot();
|
||||
} catch (WebDriverException $exception) {
|
||||
$this->dispatchOnException($exception);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverException $exception
|
||||
*/
|
||||
protected function dispatchOnException(WebDriverException $exception)
|
||||
{
|
||||
$this->dispatch(
|
||||
'onException',
|
||||
$exception,
|
||||
$this->dispatcher->getDefaultDriver()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $method
|
||||
* @param mixed ...$arguments
|
||||
*/
|
||||
protected function dispatch($method, ...$arguments)
|
||||
{
|
||||
if (!$this->dispatcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatcher->dispatch($method, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebDriverElement $element
|
||||
* @return static
|
||||
*/
|
||||
protected function newElement(WebDriverElement $element)
|
||||
{
|
||||
return new static($element, $this->getDispatcher());
|
||||
}
|
||||
}
|
71
vendor/php-webdriver/webdriver/lib/Support/IsElementDisplayedAtom.php
vendored
Normal file
71
vendor/php-webdriver/webdriver/lib/Support/IsElementDisplayedAtom.php
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Support;
|
||||
|
||||
use Facebook\WebDriver\Remote\RemoteExecuteMethod;
|
||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||
use Facebook\WebDriver\Remote\RemoteWebElement;
|
||||
use Facebook\WebDriver\Remote\WebDriverBrowserType;
|
||||
|
||||
/**
|
||||
* Certain drivers have decided to not provide the endpoint which determines element displayedness, because
|
||||
* the W3C WebDriver specification no longer dictates it.
|
||||
*
|
||||
* In those instances, we determine this using a script ("atom").
|
||||
*
|
||||
* @see https://w3c.github.io/webdriver/#element-displayedness
|
||||
*
|
||||
* Also note in case more than this one atom is used, this logic here should be refactored to some AbstractAtom.
|
||||
*/
|
||||
class IsElementDisplayedAtom
|
||||
{
|
||||
/**
|
||||
* List of browsers which are known to support /displayed endpoint on their own (so they don't need this atom).
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const BROWSERS_WITH_ENDPOINT_SUPPORT = [
|
||||
WebDriverBrowserType::CHROME,
|
||||
WebDriverBrowserType::FIREFOX,
|
||||
WebDriverBrowserType::MICROSOFT_EDGE,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var RemoteWebDriver
|
||||
*/
|
||||
private $driver;
|
||||
|
||||
public function __construct(RemoteWebDriver $driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
public static function match($browserName)
|
||||
{
|
||||
return !in_array($browserName, self::BROWSERS_WITH_ENDPOINT_SUPPORT, true);
|
||||
}
|
||||
|
||||
public function execute($params)
|
||||
{
|
||||
$element = new RemoteWebElement(
|
||||
new RemoteExecuteMethod($this->driver),
|
||||
$params[':id'],
|
||||
$this->driver->isW3cCompliant()
|
||||
);
|
||||
|
||||
return $this->executeAtom('isElementDisplayed', $element);
|
||||
}
|
||||
|
||||
protected function executeAtom($atomName, ...$params)
|
||||
{
|
||||
return $this->driver->executeScript(
|
||||
sprintf('%s; return (%s).apply(null, arguments);', $this->loadAtomScript($atomName), $atomName),
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
private function loadAtomScript($atomName)
|
||||
{
|
||||
return file_get_contents(__DIR__ . '/../scripts/' . $atomName . '.js');
|
||||
}
|
||||
}
|
77
vendor/php-webdriver/webdriver/lib/Support/ScreenshotHelper.php
vendored
Normal file
77
vendor/php-webdriver/webdriver/lib/Support/ScreenshotHelper.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Support;
|
||||
|
||||
use Facebook\WebDriver\Exception\WebDriverException;
|
||||
use Facebook\WebDriver\Remote\DriverCommand;
|
||||
use Facebook\WebDriver\Remote\RemoteExecuteMethod;
|
||||
|
||||
/**
|
||||
* Helper class to handle taking, decoding and screenshots using WebDriver.
|
||||
*/
|
||||
class ScreenshotHelper
|
||||
{
|
||||
/** @var RemoteExecuteMethod */
|
||||
private $executor;
|
||||
|
||||
public function __construct(RemoteExecuteMethod $executor)
|
||||
{
|
||||
$this->executor = $executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $saveAs
|
||||
* @throws WebDriverException
|
||||
* @return string
|
||||
*/
|
||||
public function takePageScreenshot($saveAs = null)
|
||||
{
|
||||
$commandToExecute = [DriverCommand::SCREENSHOT];
|
||||
|
||||
return $this->takeScreenshot($commandToExecute, $saveAs);
|
||||
}
|
||||
|
||||
public function takeElementScreenshot($elementId, $saveAs = null)
|
||||
{
|
||||
$commandToExecute = [DriverCommand::TAKE_ELEMENT_SCREENSHOT, [':id' => $elementId]];
|
||||
|
||||
return $this->takeScreenshot($commandToExecute, $saveAs);
|
||||
}
|
||||
|
||||
private function takeScreenshot(array $commandToExecute, $saveAs = null)
|
||||
{
|
||||
$response = $this->executor->execute(...$commandToExecute);
|
||||
|
||||
if (!is_string($response)) {
|
||||
throw new WebDriverException('Error taking screenshot, no data received from the remote end');
|
||||
}
|
||||
|
||||
$screenshot = base64_decode($response, true);
|
||||
|
||||
if ($screenshot === false) {
|
||||
throw new WebDriverException('Error decoding screenshot data');
|
||||
}
|
||||
|
||||
if ($saveAs !== null) {
|
||||
$this->saveScreenshotToPath($screenshot, $saveAs);
|
||||
}
|
||||
|
||||
return $screenshot;
|
||||
}
|
||||
|
||||
private function saveScreenshotToPath($screenshot, $path)
|
||||
{
|
||||
$this->createDirectoryIfNotExists(dirname($path));
|
||||
|
||||
file_put_contents($path, $screenshot);
|
||||
}
|
||||
|
||||
private function createDirectoryIfNotExists($directoryPath)
|
||||
{
|
||||
if (!file_exists($directoryPath)) {
|
||||
if (!mkdir($directoryPath, 0777, true) && !is_dir($directoryPath)) {
|
||||
throw new WebDriverException(sprintf('Directory "%s" was not created', $directoryPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
vendor/php-webdriver/webdriver/lib/Support/XPathEscaper.php
vendored
Normal file
32
vendor/php-webdriver/webdriver/lib/Support/XPathEscaper.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Support;
|
||||
|
||||
class XPathEscaper
|
||||
{
|
||||
/**
|
||||
* Converts xpath strings with both quotes and ticks into:
|
||||
* `foo'"bar` -> `concat('foo', "'" ,'"bar')`
|
||||
*
|
||||
* @param string $xpathToEscape The xpath to be converted.
|
||||
* @return string The escaped string.
|
||||
*/
|
||||
public static function escapeQuotes($xpathToEscape)
|
||||
{
|
||||
// Single quotes not present => we can quote in them
|
||||
if (mb_strpos($xpathToEscape, "'") === false) {
|
||||
return sprintf("'%s'", $xpathToEscape);
|
||||
}
|
||||
|
||||
// Double quotes not present => we can quote in them
|
||||
if (mb_strpos($xpathToEscape, '"') === false) {
|
||||
return sprintf('"%s"', $xpathToEscape);
|
||||
}
|
||||
|
||||
// Both single and double quotes are present
|
||||
return sprintf(
|
||||
"concat('%s')",
|
||||
str_replace("'", "', \"'\" ,'", $xpathToEscape)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user