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