for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zumba\Mink\Driver;
use Behat\Mink\Exception\DriverException;
/**
* Class WindowTrait
* @package Zumba\Mink\Driver
*/
trait WindowTrait {
* Returns the current page window name
* @return string
public function getWindowName() {
return $this->browser->windowName();
browser
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* 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
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);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: