From 5476a2ae5e844fe3ee4fcd53a25497f10971bcb8 Mon Sep 17 00:00:00 2001 From: Harish Ved Date: Mon, 14 Mar 2016 22:04:41 +0530 Subject: [PATCH 1/3] change paths --- lib/LocalBinary.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/LocalBinary.php b/lib/LocalBinary.php index 8f780e4..a447786 100644 --- a/lib/LocalBinary.php +++ b/lib/LocalBinary.php @@ -50,14 +50,14 @@ private function server_home() { private function platform_url(){ if (PHP_OS == "Darwin") - return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-darwin-x64'; + return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-darwin-x64'; else if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') - return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-win32.exe'; + return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-win32.exe'; if ((strtoupper(PHP_OS)) == "LINUX") { if (PHP_INT_SIZE * 8 == 64) - return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-x64'; + return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-x64'; else - return 'https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-ia32'; + return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32'; } } From 74eeb265a6a8f858d2719ebdb02cf3dd90e3c966 Mon Sep 17 00:00:00 2001 From: Harish Ved Date: Fri, 18 Mar 2016 13:27:08 +0530 Subject: [PATCH 2/3] Windows Changes --- lib/LocalBinary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/LocalBinary.php b/lib/LocalBinary.php index a447786..a0cb5c3 100644 --- a/lib/LocalBinary.php +++ b/lib/LocalBinary.php @@ -52,7 +52,7 @@ private function platform_url(){ if (PHP_OS == "Darwin") return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-darwin-x64'; else if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') - return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-win32.exe'; + return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal.exe'; if ((strtoupper(PHP_OS)) == "LINUX") { if (PHP_INT_SIZE * 8 == 64) return 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-x64'; From 9aa73bebf20cf48872018dc65292ae9a0a6a4a95 Mon Sep 17 00:00:00 2001 From: Harish Ved Date: Fri, 18 Mar 2016 16:38:39 +0530 Subject: [PATCH 3/3] Windows Changes --- lib/Local.php | 10 +++++++++- lib/LocalBinary.php | 26 ++++++++++++++++++-------- tests/LocalTest.php | 5 ++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/Local.php b/lib/Local.php index 399729e..69e6819 100644 --- a/lib/Local.php +++ b/lib/Local.php @@ -113,8 +113,16 @@ public function stop() { fclose($this->pipes[1]); fclose($this->pipes[2]); - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { exec('kill -15 ' . $this->pid); + } else { + $binary_pid = proc_get_status($this->handle)['pid']; + $wmic_output = shell_exec('wmic process where (ParentProcessId='. $binary_pid. ') get Caption,ProcessId'); + preg_match_all('!\d+!', $wmic_output, $possible_pids); + if(!empty($possible_pids[0][0])) { + exec("taskkill /F /PID ". $possible_pids[0][0]); + } + } proc_terminate($this->handle); while($this->isRunning()) diff --git a/lib/LocalBinary.php b/lib/LocalBinary.php index a0cb5c3..5c6121a 100644 --- a/lib/LocalBinary.php +++ b/lib/LocalBinary.php @@ -22,7 +22,11 @@ public function __destruct() { public function binary_path() { $dest_parent_dir = $this->get_available_dirs(); - $binary_path = $dest_parent_dir. "/BrowserStackLocal"; + $dest_binary_name = "BrowserStackLocal"; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $dest_binary_name = $dest_binary_name. ".exe"; + } + $binary_path = $dest_parent_dir. "/". $dest_binary_name; if(file_exists($binary_path)){ return $binary_path; } @@ -66,18 +70,24 @@ public function download_binary($path) { if (!file_exists($path)) mkdir($path, 0777, true); - $ch = curl_init(); + + $dest_binary_name = "BrowserStackLocal"; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $dest_binary_name = $dest_binary_name. ".exe"; + } + $dest_binary_path = $path. '/'. $dest_binary_name; + $file = fopen($dest_binary_path , "w+"); + $ch = curl_init(""); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FILE, $file); $data = curl_exec ($ch); curl_close ($ch); - - $file = fopen($path . '/BrowserStackLocal', "w+"); - fputs($file, $data); - fclose($file); - chmod($path . '/BrowserStackLocal', 0755); - return $path . "/BrowserStackLocal"; + fclose($file); + chmod($dest_binary_path, 0755); + return $dest_binary_path; } private function get_available_dirs() { diff --git a/tests/LocalTest.php b/tests/LocalTest.php index f5b9a04..c5484f3 100644 --- a/tests/LocalTest.php +++ b/tests/LocalTest.php @@ -87,12 +87,15 @@ public function test_checkPid() { public function test_multiple_binary() { $this->bs_local->start(array('v' => true)); $bs_local_2 = new Local(); + $log_file2 = getcwd(). '/log2.log'; + print($log_file2); try { - $bs_local_2->start(array('v' => true)); + $bs_local_2->start(array('v' => true, 'logfile' => $log_file2)); $this->fail("Expected Exception has not been raised."); } catch (LocalException $ex) { $emessage = $ex->getMessage(); $this->assertEquals(trim($emessage), 'Error: Either another browserstack local client is running on your machine or some server is listening on port 45691'); + unlink($log_file2); return; } }