Created
February 3, 2020 23:54
-
-
Save andrewnicols/54a7eaa661ad790cf70fbd0e7167b02d to your computer and use it in GitHub Desktop.
This file contains 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(); | |
$options = new ChromeOptions(); | |
$options->addArguments(array( | |
"--headless", "window-size=1024,768", "--no-sandbox" | |
)); | |
$prefs = array( | |
'permissions.default.stylesheet' => 2, | |
'permissions.default.image' => 2 | |
); | |
$options->setExperimentalOption('prefs', $prefs); | |
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options); | |
$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