private $SeleniumServerExecPath;
public function __construct( $startServer,
- $serverPort,
- $serverExecPath ) {
+ $serverPort,
+ $serverExecPath ) {
$this->OS = (string) PHP_OS;
if ( isset( $startServer ) )
$this->SeleniumStartServer = $startServer;
switch ( $this->OS ) {
case "Linux":
# case' CYGWIN_NT-5.1':
-# case 'Darwin':
+ case 'Darwin':
# case 'FreeBSD':
# case 'HP-UX':
# case 'IRIX64':
switch ( $this->OS ) {
case "Linux":
# case' CYGWIN_NT-5.1':
-# case 'Darwin':
+ case 'Darwin':
# case 'FreeBSD':
# case 'HP-UX':
# case 'IRIX64':
private function startServerOnUnix() {
$output = array();
- $user = $_ENV['USER'];
- exec("ps -U " . $user . " w | grep -i selenium-server", $output);
+ $user = $_ENV['USER'];
+ // @fixme this should be a little more generalized :)
+ if (PHP_OS == 'Darwin') {
+ // Mac OS X's ps barfs on the 'w' param, but doesn't need it.
+ $ps = "ps -U %s";
+ } else {
+ // Good on Linux
+ $ps = "ps -U %s w";
+ }
+ $psCommand = sprintf($ps, escapeshellarg($user));
+ exec($psCommand . " | grep -i selenium-server", $output);
// Start server. If there is already a server running,
// return running.
$commandSuffix = ' > /dev/null 2>&1'. ' & echo $!';
$portText = ' -port ' . $this->SeleniumServerPort;
- $command = "java -jar " .
- $this->SeleniumServerExecPath .
+ $command = "java -jar " .
+ escapeshellarg($this->SeleniumServerExecPath) .
$portText . $commandSuffix;
- exec($command ,$op);
- $pid = (int)$op[0];
+ exec($command ,$op);
+ $pid = (int)$op[0];
if ( $pid != "" )
$this->SeleniumServerPid = $pid;
else {
// on its port. Note: this solution kinda
// stinks, since it uses a wait loop - dnessett
+ wfSuppressWarnings();
for ( $cnt = 1;
- $cnt <= $this->SeleniumServerStartTimeout;
- $cnt++ ) {
- $fp = @fsockopen ( 'localhost',
+ $cnt <= $this->SeleniumServerStartTimeout;
+ $cnt++ ) {
+ $fp = fsockopen ( 'localhost',
$this->SeleniumServerPort,
- &$errno, &$errstr, 0 );
+ $errno, $errstr, 0 );
if ( !$fp ) {
sleep( 1 );
continue;
return 'started';
}
}
+ wfRestoreWarnings();
echo ( "Starting Selenium server timed out.\n" );
return 'failed';
}
else return 'running';
}
- // No Server execution path defined.
+ // No Server execution path defined.
return 'failed';
}
private function startServerOnWindows() {
- // Unimplemented.
+ // Unimplemented.
return 'failed';
}
private function stopServerOnUnix() {
if ( !empty( $this->SeleniumServerPid ) &&
- $this->SeleniumServerPid != 'NaN' ) {
+ $this->SeleniumServerPid != 'NaN' ) {
exec( "kill -9 " . $this->SeleniumServerPid );
return 'stopped';
}
}
private function stopServerOnWindows() {
- // Unimplemented.
+ // Unimplemented.
return 'failed';
}