File tree Expand file tree Collapse file tree 4 files changed +58
-10
lines changed
Expand file tree Collapse file tree 4 files changed +58
-10
lines changed Original file line number Diff line number Diff line change 11dist /*
2+ * .log
Original file line number Diff line number Diff line change 11require 'browserstack/localbinary'
2+ require 'browserstack/localexception'
23
34module BrowserStack
45
@@ -51,17 +52,24 @@ def start(options = {})
5152 end
5253
5354 @process = IO . popen ( command , "w+" )
55+ @stdout = @process # File.open("local.log", "r")
5456
5557 while true
56- line = @process . readline
58+ begin
59+ line = @stdout . readline
60+ rescue EOFError => e
61+ sleep 1
62+ next
63+ end
5764 break if line . nil?
5865 if line . match ( /\* \* \* Error\: / )
59- @process . close
66+ #@stdout .close
6067 raise BrowserStack ::LocalException . new ( line )
6168 return
6269 end
6370 if line . strip == "Press Ctrl-C to exit"
6471 @pid = @process . pid
72+ #@stdout.close
6573 return
6674 end
6775 end
@@ -79,16 +87,17 @@ def isRunning
7987
8088 def stop
8189 return if @pid . nil?
82- Process . kill ( "INT " , @pid )
90+ Process . kill ( "TERM " , @pid )
8391 @process . close
92+ while true
93+ break if !self . isRunning
94+ sleep 1
95+ end
8496 end
8597
8698 def command
8799 "#{ @binary_path } #{ @folder_flag } #{ @key } #{ @folder_path } #{ @force_local_flag } #{ @local_identifier_flag } #{ @only_flag } #{ @only_automate_flag } #{ @proxy_host } #{ @proxy_port } #{ @proxy_user } #{ @proxy_pass } #{ @force_flag } #{ @verbose_flag } #{ @hosts } " . strip
88100 end
89101end
90102
91- class LocalException < Exception
92- end
93-
94103end
Original file line number Diff line number Diff line change 11require 'net/http'
22require 'rbconfig'
33require 'openssl'
4+ require 'tmpdir'
5+ require 'browserstack/localexception'
46
57module BrowserStack
68
@@ -20,10 +22,15 @@ def initialize
2022 "https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32"
2123 end
2224 end
25+
26+ @ordered_paths = [
27+ File . expand_path ( '~' ) , '.browserstack' ,
28+ Dir . pwd ,
29+ Dir . tmpdir
30+ ]
2331 end
2432
25- def download
26- dest_parent_dir = File . join ( File . expand_path ( '~' ) , '.browserstack' )
33+ def download ( dest_parent_dir )
2734 unless File . exists? dest_parent_dir
2835 Dir . mkdir dest_parent_dir
2936 end
@@ -44,12 +51,37 @@ def download
4451 end
4552
4653 def binary_path
47- dest_parent_dir = File . join ( File . expand_path ( '~' ) , '.browserstack' )
54+ dest_parent_dir = get_available_dirs
4855 binary_path = File . join ( dest_parent_dir , "BrowserStackLocal#{ ".exe" if @windows } " )
4956 if File . exists? binary_path
5057 binary_path
5158 else
52- download
59+ download ( dest_parent_dir )
60+ end
61+ end
62+
63+ private
64+
65+ def get_available_dirs
66+ i = 0
67+ while i < @ordered_paths . size
68+ path = @ordered_paths [ i ]
69+ if make_path ( path )
70+ return path
71+ else
72+ i += 1
73+ end
74+ end
75+ raise BrowserStack ::LocalException . new ( 'Error trying to download BrowserStack Local binary' )
76+ end
77+
78+ def make_path ( path )
79+ begin
80+ FileUtils . mkdir_p path if !Dir . exists? ( path )
81+ return true
82+ rescue Exception => e
83+ puts "Exception #{ e . message } #{ e . backtrace } "
84+ return false
5385 end
5486 end
5587end
Original file line number Diff line number Diff line change 1+ module BrowserStack
2+
3+ class LocalException < Exception
4+ end
5+
6+ end
You can’t perform that action at this time.
0 commit comments