You are here

class PhantomJSDriver in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/jcalderonzumba/mink-phantomjs-driver/src/PhantomJSDriver.php \Zumba\Mink\Driver\PhantomJSDriver

Class PhantomJSDriver @package Behat\Mink\Driver

Hierarchy

Expanded class hierarchy of PhantomJSDriver

File

vendor/jcalderonzumba/mink-phantomjs-driver/src/PhantomJSDriver.php, line 12

Namespace

Zumba\Mink\Driver
View source
class PhantomJSDriver extends BasePhantomJSDriver {
  use SessionTrait;
  use NavigationTrait;
  use CookieTrait;
  use HeadersTrait;
  use JavascriptTrait;
  use MouseTrait;
  use PageContentTrait;
  use KeyboardTrait;
  use FormManipulationTrait;
  use WindowTrait;

  /**
   * Sets the basic auth user and password
   * @param string $user
   * @param string $password
   */
  public function setBasicAuth($user, $password) {
    $this->browser
      ->setHttpAuth($user, $password);
  }

  /**
   * Gets the tag name of a given xpath
   * @param string $xpath
   * @return string
   * @throws DriverException
   */
  public function getTagName($xpath) {
    $elements = $this
      ->findElement($xpath, 1);
    return $this->browser
      ->tagName($elements["page_id"], $elements["ids"][0]);
  }

  /**
   * Gets the attribute value of a given element and name
   * @param string $xpath
   * @param string $name
   * @return string
   * @throws DriverException
   */
  public function getAttribute($xpath, $name) {
    $elements = $this
      ->findElement($xpath, 1);
    return $this->browser
      ->attribute($elements["page_id"], $elements["ids"][0], $name);
  }

  /**
   * Check if element given by xpath is visible or not
   * @param string $xpath
   * @return bool
   * @throws DriverException
   */
  public function isVisible($xpath) {
    $elements = $this
      ->findElement($xpath, 1);
    return $this->browser
      ->isVisible($elements["page_id"], $elements["ids"][0]);
  }

  /**
   * Drags one element to another
   * @param string $sourceXpath
   * @param string $destinationXpath
   * @throws DriverException
   */
  public function dragTo($sourceXpath, $destinationXpath) {
    $sourceElement = $this
      ->findElement($sourceXpath, 1);
    $destinationElement = $this
      ->findElement($destinationXpath, 1);
    $this->browser
      ->drag($sourceElement["page_id"], $sourceElement["ids"][0], $destinationElement["ids"][0]);
  }

  /**
   * Upload a file to the browser
   * @param string $xpath
   * @param string $path
   * @throws DriverException
   */
  public function attachFile($xpath, $path) {
    if (!file_exists($path)) {
      throw new DriverException("Wow there the file does not exist, you can not upload it");
    }
    if (($realPath = realpath($path)) === false) {
      throw new DriverException("Wow there the file does not exist, you can not upload it");
    }
    $element = $this
      ->findElement($xpath, 1);
    $tagName = $this
      ->getTagName($xpath);
    if ($tagName != "input") {
      throw new DriverException("The element is not an input element, you can not attach a file to it");
    }
    $attributes = $this
      ->getBrowser()
      ->attributes($element["page_id"], $element["ids"][0]);
    if (!isset($attributes["type"]) || $attributes["type"] != "file") {
      throw new DriverException("The element is not an input file type element, you can not attach a file to it");
    }
    $this->browser
      ->selectFile($element["page_id"], $element["ids"][0], $realPath);
  }

  /**
   * Puts the browser control inside the IFRAME
   * You own the control, make sure to go back to the parent calling this method with null
   * @param string $name
   */
  public function switchToIFrame($name = null) {

    //TODO: check response of the calls
    if ($name === null) {
      $this->browser
        ->popFrame();
      return;
    }
    else {
      $this->browser
        ->pushFrame($name);
    }
  }

  /**
   * Focus on an element
   * @param string $xpath
   * @throws DriverException
   */
  public function focus($xpath) {
    $element = $this
      ->findElement($xpath, 1);
    $this->browser
      ->trigger($element["page_id"], $element["ids"][0], "focus");
  }

  /**
   * Blur on element
   * @param string $xpath
   * @throws DriverException
   */
  public function blur($xpath) {
    $element = $this
      ->findElement($xpath, 1);
    $this->browser
      ->trigger($element["page_id"], $element["ids"][0], "blur");
  }

  /**
   * Finds elements with specified XPath query.
   * @param string $xpath
   * @return NodeElement[]
   * @throws DriverException                  When the operation cannot be done
   */
  public function find($xpath) {
    $elements = $this->browser
      ->find("xpath", $xpath);
    $nodeElements = array();
    if (!isset($elements["ids"])) {
      return null;
    }
    foreach ($elements["ids"] as $i => $elementId) {
      $nodeElements[] = new NodeElement(sprintf('(%s)[%d]', $xpath, $i + 1), $this->session);
    }
    return $nodeElements;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BasePhantomJSDriver::$browser protected property @var Browser
BasePhantomJSDriver::$phantomHost protected property @var string
BasePhantomJSDriver::$session protected property @var Session Overrides CoreDriver::$session
BasePhantomJSDriver::$templateEnv protected property @var \Twig_Environment
BasePhantomJSDriver::$templateLoader protected property @var \Twig_Loader_Filesystem
BasePhantomJSDriver::findElement protected function Helper to find a node element given an xpath
BasePhantomJSDriver::getBrowser public function
BasePhantomJSDriver::getTemplateEnv public function
BasePhantomJSDriver::javascriptTemplateRender public function Returns a javascript script via twig template engine
BasePhantomJSDriver::setSession public function Overrides CoreDriver::setSession
BasePhantomJSDriver::templateCacheSetup protected function Sets up the cache template location for the scripts we are going to create with the driver
BasePhantomJSDriver::__construct public function Instantiates the driver
CookieTrait::getCookie public function Gets a cookie by its name if exists, else it will return null
CookieTrait::setCookie public function Sets a cookie on the browser, if null value then delete it
CoreDriver::findElementXpaths protected function Finds elements with specified XPath query. 1
CoreDriver::maximizeWindow public function Maximizes the window if it is not maximized already. Overrides DriverInterface::maximizeWindow
FormManipulationTrait::boolToString protected function Helper method needed for twig and javascript stuff
FormManipulationTrait::check public function We click on the checkbox or radio when possible and needed
FormManipulationTrait::getValue public function Returns the value of a given xpath element
FormManipulationTrait::inputCheckableControl protected function Check control over an input element of radio or checkbox type
FormManipulationTrait::isChecked public function Checks if the radio or checkbox is checked
FormManipulationTrait::isSelected public function Checks if the option is selected or not
FormManipulationTrait::selectOption public function Selects an option
FormManipulationTrait::setValue public function
FormManipulationTrait::submitForm public function Submits a form given an xpath selector
FormManipulationTrait::uncheck public function We click on the checkbox or radio when possible and needed
HeadersTrait::getResponseHeaders public function Gets the current request response headers Should be called only after a request, other calls are undefined behaviour
HeadersTrait::getStatusCode public function Current request status code response
HeadersTrait::setRequestHeader public function The name say its all
JavascriptTrait::evaluateScript public function Evaluates a script and returns the result
JavascriptTrait::executeScript public function Executes a script on the browser
JavascriptTrait::wait public function Waits some time or until JS condition turns true.
KeyboardTrait::keyDown public function Send a key-down event to the browser element
KeyboardTrait::keyEventModifierControl protected function Does some control and normalization for the key event modifier
KeyboardTrait::keyPress public function
KeyboardTrait::keyUp public function Pressed up specific keyboard key.
KeyboardTrait::normalizeCharForKeyEvent protected function Does some normalization for the char we want to do keyboard events with.
MouseTrait::click public function Clicks if possible on an element given by xpath
MouseTrait::doubleClick public function Double click on element found via xpath
MouseTrait::mouseOver public function Generates a mouseover event on the given element by xpath
MouseTrait::rightClick public function Right click on element found via xpath
NavigationTrait::back public function Goes back if possible
NavigationTrait::forward public function Goes forward if possible
NavigationTrait::getCurrentUrl public function Gets the current url if any
NavigationTrait::reload public function Reloads the page if possible
NavigationTrait::visit public function Visits a given url
PageContentTrait::getContent public function
PageContentTrait::getHtml public function Returns the inner html of a given xpath
PageContentTrait::getOuterHtml public function Gets the outer html of a given xpath
PageContentTrait::getScreenshot public function Returns the binary representation of the current page we are in
PageContentTrait::getText public function Given xpath, will try to get ALL the text, visible and not visible from such xpath
PhantomJSDriver::attachFile public function Upload a file to the browser Overrides CoreDriver::attachFile
PhantomJSDriver::blur public function Blur on element Overrides CoreDriver::blur
PhantomJSDriver::dragTo public function Drags one element to another Overrides CoreDriver::dragTo
PhantomJSDriver::find public function Finds elements with specified XPath query. Overrides CoreDriver::find
PhantomJSDriver::focus public function Focus on an element Overrides CoreDriver::focus
PhantomJSDriver::getAttribute public function Gets the attribute value of a given element and name Overrides CoreDriver::getAttribute
PhantomJSDriver::getTagName public function Gets the tag name of a given xpath Overrides CoreDriver::getTagName
PhantomJSDriver::isVisible public function Check if element given by xpath is visible or not Overrides CoreDriver::isVisible
PhantomJSDriver::setBasicAuth public function Sets the basic auth user and password Overrides CoreDriver::setBasicAuth
PhantomJSDriver::switchToIFrame public function Puts the browser control inside the IFRAME You own the control, make sure to go back to the parent calling this method with null Overrides CoreDriver::switchToIFrame
SessionTrait::$started protected property @var bool
SessionTrait::isStarted public function Tells if the session is started or not
SessionTrait::reset public function Clears the cookies in the browser, all of them
SessionTrait::start public function Starts a session to be used by the driver client
SessionTrait::stop public function Stops the session completely, clean slate for the browser
WindowTrait::getWindowName public function Returns the current page window name
WindowTrait::getWindowNames public function Return all the window handles currently present in phantomjs
WindowTrait::resizeWindow public function Resizing a window with specified size
WindowTrait::switchToWindow public function Switches to window by name if possible