Created
February 3, 2020 23:53
-
-
Save andrewnicols/a50ee7ab196f11c21a5a1bc9b5ff2b4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Facebook\WebDriver; | |
use Facebook\WebDriver\Remote\DesiredCapabilities; | |
use Facebook\WebDriver\Remote\RemoteWebDriver; | |
require_once('vendor/autoload.php'); | |
// start Chrome with 5 second timeout | |
$host = 'http://localhost:4444/wd/hub'; // this is the default | |
$capabilities = DesiredCapabilities::chrome(); | |
$driver = RemoteWebDriver::create($host, $capabilities, 5000); | |
$driver->get('http://localhost/test/'); | |
function isAlertPresent($driver){ | |
try{ | |
$driver->wait(10)->until(WebDriverExpectedCondition::alertIsPresent()); | |
$driver->switchTo()->alert()->accept(); | |
return true; | |
} catch (Exception $ex) { | |
return false; | |
} | |
} | |
$alertFound = isAlertPresent($driver); | |
// close the browser | |
$driver->quit(); | |
var_dump($alertFound); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment