Last active
November 23, 2020 00:08
-
-
Save jeznag/e0c8c062785eb05a97ff to your computer and use it in GitHub Desktop.
Combine PhantomJS with PHPUnit
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 | |
class TestScaffold extends \PHPUnit_Extensions_Selenium2TestCase { | |
protected function setUp() { | |
$this->setBrowser( 'phantomjs' ); | |
$this->setBrowserUrl( 'http://www.example.com/' ); | |
$this->run_selenium_server(); | |
$this->run_phantom_js(); | |
} | |
protected function run_selenium_server() | |
{ | |
if($this->selenium_server_already_running()) | |
{ | |
fwrite(STDOUT, "Selenium server already running\n"); | |
} | |
else | |
{ | |
shell_exec("java -jar " . __DIR__ . "\bin\selenium-server-standalone-2.45.0.jar"); | |
} | |
} | |
protected function run_phantom_js() | |
{ | |
if ($this->phantom_js_already_running()) { | |
fwrite(STDOUT, "PhantomJS already running\n"); | |
} else { | |
fwrite(STDOUT, "Starting PhantomJS\n"); | |
shell_exec(__DIR__ . "\bin\phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444"); | |
} | |
} | |
protected function selenium_server_already_running() | |
{ | |
return fsockopen("localhost", 4444); | |
} | |
protected function phantom_js_already_running() | |
{ | |
try { | |
return fsockopen("localhost", 8080); | |
} catch (Exception $e) { | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment