Selenium + PHP
Introduction to Selenium Webdriver Installation and Environment set up Chrome Chrome with options Chrome in Mobile Emulation IE Firefox Element identification methods Assertions in Selenium in PHP Interacting with elements in Selenium in PHP Basic Browser window automation Sending keys in Selenium in PHP Synchronization in Selenium Check if Element exists Working with Tables using Selenium Performing advanced actions using Selenium in PHP Executing JavaScript in Selenium in PHP Working with multiple Browser Windows or tabs Working with multiple frames Handling alerts Taking a screenshot in selenium Integration with BDD framework like behatWorking 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!!