forked from braintree/braintree_android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_listener.rb
51 lines (44 loc) · 1.22 KB
/
log_listener.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'pty'
TAGS = ["request_screenshot", "request_command"]
def get_filter
"'#{TAGS.join('|')}'"
end
def setup
puts `mkdir failed_test_screenshots`
puts `rm -rf failed_test_screenshots/*`
puts `adb logcat -c`
end
def handle_screenshot_request(screenshot_name)
puts `adb shell screencap -p | perl -pe 's/\\x0D\\x0A/\\x0A/g' > failed_test_screenshots/#{screenshot_name}.png`
end
def handle_command_request(command)
if command == 'install fakewallet'
puts `./gradlew :FakeWallet:installDebug`
elsif command == 'uninstall fakewallet'
puts `adb uninstall com.braintreepayments.fake.wallet`
end
end
def run
puts "Listening..."
puts "adb logcat | grep -E #{get_filter}"
begin
PTY.spawn("adb logcat | grep -E #{get_filter}") do |stdin, stdout, pid|
begin
stdin.each do |line|
puts line
if line.include?("request_screenshot")
handle_screenshot_request(line.split(':')[1].strip)
elsif line.include?("request_command")
handle_command_request(line.split(':')[1].strip)
end
end
rescue Errno::EIO
puts "adb exited, stopping"
end
end
rescue PTY::ChildExited
puts "adb exited, stopping"
end
end
setup
run