Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Container.php

class Container

Same name in this branch
  1. 11.1.x vendor/symfony/dependency-injection/Container.php \Symfony\Component\DependencyInjection\Container
  2. 11.1.x core/lib/Drupal/Core/Render/Element/Container.php \Drupal\Core\Render\Element\Container
  3. 11.1.x core/lib/Drupal/Core/DependencyInjection/Container.php \Drupal\Core\DependencyInjection\Container
  4. 11.1.x core/lib/Drupal/Component/DependencyInjection/Container.php \Drupal\Component\DependencyInjection\Container

Abstract WebDriver\Container class

@package WebDriver

Hierarchy

  • class \WebDriver\AbstractWebDriver
    • class \WebDriver\Container extends \WebDriver\AbstractWebDriver

Expanded class hierarchy of Container

38 string references to 'Container'
AbstractRecursivePass::processValue in vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php
Processes a value found in a definition tree.
Actions::getInfo in core/lib/Drupal/Core/Render/Element/Actions.php
Returns the element properties for this element.
AddHandler::buildForm in core/modules/views_ui/src/Form/Ajax/AddHandler.php
Form constructor.
ArgumentPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
Provide a form to edit options for this plugin.
ChooseBlockController::build in core/modules/layout_builder/src/Controller/ChooseBlockController.php
Provides the UI for choosing a new block.

... See full list

File

vendor/lullabot/php-webdriver/lib/WebDriver/Container.php, line 21

Namespace

WebDriver
View source
abstract class Container extends AbstractWebDriver {
    
    /**
     * @var array
     */
    private $strategies;
    
    /**
     * {@inheritdoc}
     */
    public function __construct($url) {
        parent::__construct($url);
        $locatorStrategy = new \ReflectionClass('WebDriver\\LocatorStrategy');
        $this->strategies = $locatorStrategy->getConstants();
    }
    
    /**
     * Find element: /session/:sessionId/element (POST)
     * Find child element: /session/:sessionId/element/:id/element (POST)
     * Search for element on page, starting from the document root.
     *
     * @param string $using the locator strategy to use
     * @param string $value the search target
     *
     * @return \WebDriver\Element
     *
     * @throws \WebDriver\Exception if element not found, or invalid XPath
     */
    public function element($using = null, $value = null) {
        $locatorJson = $this->parseArgs('element', func_get_args());
        try {
            $result = $this->curl('POST', '/element', $locatorJson);
        } catch (WebDriverException\NoSuchElement $e) {
            throw WebDriverException::factory(WebDriverException::NO_SUCH_ELEMENT, sprintf("Element not found with %s, %s\n\n%s", $locatorJson['using'], $locatorJson['value'], $e->getMessage()), $e);
        }
        $element = $this->makeElement($result['value']);
        if ($element === null) {
            throw WebDriverException::factory(WebDriverException::NO_SUCH_ELEMENT, sprintf("Element not found with %s, %s\n", $locatorJson['using'], $locatorJson['value']));
        }
        return $element;
    }
    
    /**
     * Find elements: /session/:sessionId/elements (POST)
     * Find child elements: /session/:sessionId/element/:id/elements (POST)
     * Search for multiple elements on page, starting from the document root.
     *
     * @param string $using the locator strategy to use
     * @param string $value the search target
     *
     * @return array
     *
     * @throws \WebDriver\Exception if invalid XPath
     */
    public function elements($using = null, $value = null) {
        $locatorJson = $this->parseArgs('elements', func_get_args());
        $result = $this->curl('POST', '/elements', $locatorJson);
        if (!is_array($result['value'])) {
            return array();
        }
        return array_filter(array_map(array(
            $this,
            'makeElement',
        ), $result['value']));
    }
    
    /**
     * Parse arguments allowing either separate $using and $value parameters, or
     * as an array containing the JSON parameters
     *
     * @param string $method method name
     * @param array  $argv   arguments
     *
     * @return array
     *
     * @throws \WebDriver\Exception if invalid number of arguments to the called method
     */
    private function parseArgs($method, $argv) {
        $argc = count($argv);
        switch ($argc) {
            case 2:
                $using = $argv[0];
                $value = $argv[1];
                break;
            case 1:
                $arg = $argv[0];
                if (is_array($arg)) {
                    $using = $arg['using'];
                    $value = $arg['value'];
                    break;
                }
            // fall through
            default:
                throw WebDriverException::factory(WebDriverException::JSON_PARAMETERS_EXPECTED, sprintf('Invalid arguments to %s method: %s', $method, print_r($argv, true)));
        }
        return $this->locate($using, $value);
    }
    
    /**
     * Return JSON parameter for element / elements command
     *
     * @param string $using locator strategy
     * @param string $value search target
     *
     * @return array
     *
     * @throws \WebDriver\Exception if invalid locator strategy
     */
    public function locate($using, $value) {
        if (!in_array($using, $this->strategies)) {
            throw WebDriverException::factory(WebDriverException::UNKNOWN_LOCATOR_STRATEGY, sprintf('Invalid locator strategy %s', $using));
        }
        return array(
            'using' => $using,
            'value' => $value,
        );
    }
    
    /**
     * Factory method for elements
     *
     * @param mixed $value
     *
     * @return \WebDriver\Element|null
     */
    protected function makeElement($value) {
        if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, (array) $value)) {
            $identifier = $value[LegacyElement::LEGACY_ELEMENT_ID];
            return new LegacyElement($this->getIdentifierPath($identifier), $identifier);
        }
        if (array_key_exists(Element::WEB_ELEMENT_ID, (array) $value)) {
            $identifier = $value[Element::WEB_ELEMENT_ID];
            return new Element($this->getIdentifierPath($identifier), $identifier);
        }
        return null;
    }
    
    /**
     * {@inheritdoc}
     */
    public function __call($name, $arguments) {
        if (count($arguments) === 1 && in_array(str_replace('_', ' ', $name), $this->strategies)) {
            return $this->locate($name, $arguments[0]);
        }
        // fallback to executing WebDriver commands
        return parent::__call($name, $arguments);
    }
    
    /**
     * Get wire protocol URL for an identifier
     *
     * @param string $identifier
     *
     * @return string
     */
    protected abstract function getIdentifierPath($identifier);

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AbstractWebDriver::$curlService private property Curl service
AbstractWebDriver::$transientOptions private property Transient options
AbstractWebDriver::$url protected property URL
AbstractWebDriver::assertSerializable private function Sanity check
AbstractWebDriver::curl protected function Curl request to webdriver server.
AbstractWebDriver::getCurlService public function Get curl service
AbstractWebDriver::getRequestMethod private function Get default HTTP request method for a given WebDriver command
AbstractWebDriver::getTransientOptions public function
AbstractWebDriver::getURL public function Returns URL to Selenium server
AbstractWebDriver::methods abstract protected function Return array of supported method names and corresponding HTTP request methods 15
AbstractWebDriver::obsoleteMethods protected function Return array of obsolete method names and corresponding HTTP request methods 4
AbstractWebDriver::offsetGet private function Extract value from result
AbstractWebDriver::setCurlService public function Set curl service
AbstractWebDriver::setTransientOptions public function Set transient options
AbstractWebDriver::__toString public function Magic method which returns URL to Selenium server
Container::$strategies private property
Container::element public function Find element: /session/:sessionId/element (POST)
Find child element: /session/:sessionId/element/:id/element (POST)
Search for element on page, starting from the document root.
Container::elements public function Find elements: /session/:sessionId/elements (POST)
Find child elements: /session/:sessionId/element/:id/elements (POST)
Search for multiple elements on page, starting from the document root.
Container::getIdentifierPath abstract protected function Get wire protocol URL for an identifier 3
Container::locate public function Return JSON parameter for element / elements command
Container::makeElement protected function Factory method for elements
Container::parseArgs private function Parse arguments allowing either separate $using and $value parameters, or
as an array containing the JSON parameters
Container::__call public function Magic method that maps calls to class methods to execute WebDriver commands Overrides AbstractWebDriver::__call 1
Container::__construct public function Constructor Overrides AbstractWebDriver::__construct 3

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal