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 behatSelenium 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!!