Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: ruby
rvm:
- 1.8.7
- 1.9.3
- 2.2.1

before_install:
- true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19BQ0NFU1NfS0VZPUh5VmZydXJvb3dYb041eGhLZEs2Cg==`
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# browserstack-local-ruby

[![Build Status](https://travis-ci.org/browserstack/browserstack-local-ruby.svg?branch=master)](https://travis-ci.org/browserstack/browserstack-local-ruby)

## Setup

```
Expand Down
16 changes: 12 additions & 4 deletions lib/browserstack/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module BrowserStack
class Local
attr_reader :pid

def initialize(key = nil)
def initialize(key = ENV["BROWSERSTACK_ACCESS_KEY"])
@key = key
@logfile = File.join(Dir.pwd, "local.log")
end
Expand Down Expand Up @@ -58,7 +58,9 @@ def start(options = {})
end

system("echo '' > '#{@logfile}'")
@process = IO.popen(command, "w+")
#@pid = spawn()
#Process.detach @pid
@process = IO.popen(command_args)
@stdout = File.open(@logfile, "r")

while true
Expand Down Expand Up @@ -95,15 +97,21 @@ def stop
return if @pid.nil?
Process.kill("TERM", @pid)
@process.close
while true
break if !self.isRunning
while self.isRunning
sleep 1
end
end

def command
"#{@binary_path} -logFile '#{@logfile}' #{@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
end

def command_args
args = ["#{@binary_path}", "-logFile", "#{@logfile}", "#{@key}", "#{@folder_flag}", "#{@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}"]
args = args.select {|a| a.to_s != "" }
args.push(:err => [:child, :out])
args
end
end

end
22 changes: 10 additions & 12 deletions lib/browserstack/localbinary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def initialize
@http_path = case host_os
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
@windows = true
"https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal.exe"
"https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-win32.exe"
when /darwin|mac os/
"https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-darwin-x64"
"https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-darwin-x64"
when /linux/
if 1.size == 8
"https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-x64"
"https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-x64"
else
"https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32"
"https://s3.amazonaws.com/bs-automate-prod/local/BrowserStackLocal-linux-ia32"
end
end

Expand All @@ -41,14 +41,12 @@ def download(dest_parent_dir)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

http.request_get(uri.path) do |res|
file = open(binary_path, 'w')
res.read_body do |chunk|
file.write(res.body)
end
file.close
FileUtils.chmod 0755, binary_path
end
res = http.get(uri.path)
file = open(binary_path, 'w')
file.write(res.body)
file.close
FileUtils.chmod 0755, binary_path

binary_path
end

Expand Down
8 changes: 4 additions & 4 deletions test/browserstack-local-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ def setup
end

def test_check_pid
@bs_local.start({'key' => ENV["BROWSERSTACK_ACCESS_KEY"]})
@bs_local.start
refute_nil @bs_local.pid, 0
end

def test_is_running
@bs_local.start({'key' => ENV["BROWSERSTACK_ACCESS_KEY"]})
@bs_local.start
assert_equal true, @bs_local.isRunning
end

def test_multiple_binary
@bs_local.start({'key' => ENV["BROWSERSTACK_ACCESS_KEY"]})
@bs_local.start
bs_local_2 = BrowserStack::Local.new
assert_raises BrowserStack::LocalException do
bs_local_2.start({'key' => ENV["BROWSERSTACK_ACCESS_KEY"]})
bs_local_2.start
end
end

Expand Down