Minor dependency updates
[yaffs-website] / vendor / jcalderonzumba / mink-phantomjs-driver / src / WindowTrait.php
1 <?php
2
3 namespace Zumba\Mink\Driver;
4
5 use Behat\Mink\Exception\DriverException;
6
7 /**
8  * Class WindowTrait
9  * @package Zumba\Mink\Driver
10  */
11 trait WindowTrait {
12   /**
13    * Returns the current page window name
14    * @return string
15    */
16   public function getWindowName() {
17     return $this->browser->windowName();
18   }
19
20   /**
21    * Return all the window handles currently present in phantomjs
22    * @return array
23    */
24   public function getWindowNames() {
25     return $this->browser->windowHandles();
26   }
27
28   /**
29    * Switches to window by name if possible
30    * @param $name
31    * @throws DriverException
32    */
33   public function switchToWindow($name = null) {
34     $handles = $this->browser->windowHandles();
35     if ($name === null) {
36       //null means back to the main window
37       return $this->browser->switchToWindow($handles[0]);
38     }
39
40     $windowHandle = $this->browser->windowHandle($name);
41     if (!empty($windowHandle)) {
42       $this->browser->switchToWindow($windowHandle);
43     } else {
44       throw new DriverException("Could not find window handle by a given window name: $name");
45     }
46
47   }
48
49   /**
50    * Resizing a window with specified size
51    * @param int    $width
52    * @param int    $height
53    * @param string $name
54    * @throws DriverException
55    */
56   public function resizeWindow($width, $height, $name = null) {
57     if ($name !== null) {
58       //TODO: add this on the phantomjs stuff
59       throw new DriverException("Resizing other window than the main one is not supported yet");
60     }
61     $this->browser->resize($width, $height);
62   }
63
64 }