Working with multiple windows in Selenium in php

Below example shows how to Work with multiple Browser Windows or tabs in Selenium in PHP.
 
<?php
class MyTest extends PHPUnit_Framework_TestCase {

protected $driver;

public function setUp()
{
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => ‘chrome’);
$this->driver = RemoteWebDriver::create(‘https://localhost:4444/wd/hub’, $capabilities);
$this->driver->manage()->window()->maximize();
}

public function testBrowserWindows()
{
$this->driver->get(“https://www.softpost.org/selenium-test-page”);

$mainHandle = $this->driver->getWindowHandle();
echo (“
 Main window handle -> ” . $mainHandle );

$this->driver->findElement(WebDriverBy::linkText(“Selenium in Java”))->click();

$HandleSet = $this->driver->getWindowHandles();

echo (“
 Total count of window handles -> ” . sizeof($HandleSet) );
//Switching to the popup window.

foreach( $HandleSet as $handle)
{
if($handle!=$mainHandle)
{
//Switch to newly created window
echo (“
 window handle of new window -> ” . $handle );

$this->driver->switchTo()->window($handle);
echo (“
 Title of new window -> ” . $this->driver->getTitle() );
}
}

}

public function tearDown()
{
//Quit the driver
$this->driver->quit();
}
}
?>   

Web development and Automation testing

solutions delivered!!