You are here

trait WindowTrait in Zircon Profile 8

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

Class WindowTrait @package Zumba\Mink\Driver

Hierarchy

File

vendor/jcalderonzumba/mink-phantomjs-driver/src/WindowTrait.php, line 11

Namespace

Zumba\Mink\Driver
View source
trait WindowTrait {

  /**
   * Returns the current page window name
   * @return string
   */
  public function getWindowName() {
    return $this->browser
      ->windowName();
  }

  /**
   * Return all the window handles currently present in phantomjs
   * @return array
   */
  public function getWindowNames() {
    return $this->browser
      ->windowHandles();
  }

  /**
   * Switches to window by name if possible
   * @param $name
   * @throws DriverException
   */
  public function switchToWindow($name = null) {
    $handles = $this->browser
      ->windowHandles();
    if ($name === null) {

      //null means back to the main window
      return $this->browser
        ->switchToWindow($handles[0]);
    }
    $windowHandle = $this->browser
      ->windowHandle($name);
    if (!empty($windowHandle)) {
      $this->browser
        ->switchToWindow($windowHandle);
    }
    else {
      throw new DriverException("Could not find window handle by a given window name: {$name}");
    }
  }

  /**
   * Resizing a window with specified size
   * @param int    $width
   * @param int    $height
   * @param string $name
   * @throws DriverException
   */
  public function resizeWindow($width, $height, $name = null) {
    if ($name !== null) {

      //TODO: add this on the phantomjs stuff
      throw new DriverException("Resizing other window than the main one is not supported yet");
    }
    $this->browser
      ->resize($width, $height);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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