Selenium Synchronization in php

Below example shows how to add synchronization 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 testSynchronization()
{

$this->driver->manage()->timeouts()->implicitlyWait(20);
$this->driver->manage()->timeouts()->setScriptTimeout(10);
$this->driver->manage()->timeouts()->pageLoadTimeout(60);

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

//Now let us see what is explicit timeouts
//We can provide specific condition in explicit wait
//Below code will wait for maximum 20 seconds checking the title of page.
//If title does not become the expected one after 20 seconds, Timeout exception is thrown
$this->driver->wait(20, 100)->until
(WebDriverExpectedCondition::titleIs(‘Selenium Test Page | Free Software Tutorials’));

//Below statement will force the driver to wait until link is visible.
$this->driver->wait(20, 100)->until
(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::linkText(‘Selenium in Java’)));

//You can use many conditions as mentioned below.
//titleContains(), presenceOfElementLocated(), visibilityOfElementLocated()
//visibilityOf(), presenceOfAllElementsLocatedBy(), textToBePresentInElement()
//textToBePresentInElementValue(), frameToBeAvailableAndSwitchToIt(), invisibilityOfElementLocated()
//invisibilityOfElementWithText(), elementToBeClickable(), stalenessOf(), refreshed()
//elementToBeSelected(), elementSelectionStateToBe(), alertIsPresent()
}

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

Web development and Automation testing

solutions delivered!!