/
adb_steps.rb
108 lines (88 loc) · 3.19 KB
/
adb_steps.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
APK_FILE_NAME = 'features/support/ApiDemos.apk'
TEMP_FILE_NAME = 'cuke_test_file.txt'
TEMP_FILE_REMOTE_LOCATION = '/sdcard/'
When /^the adb server is started$/ do
start_server
end
Then /^the adb server should be running$/ do
last_stdout.should include "daemon started successfully"
end
Then /^I should be able to connect to a local device$/ do
sn = devices[0]
wait_for_device({:serial => sn}, 60)
connect('localhost')
last_stdout.should include "connected to localhost"
disconnect('localhost')
end
Given /^I am connected to the local device$/ do
connect
end
Then /^I should see the device "(.*?)"$/ do |device|
devices.should include device
end
Then /^I should be able to install the sample application$/ do
sn = devices[0]
wait_for_device({:serial => sn}, 60)
install APK_FILE_NAME, nil, {:serial => sn}, 60
last_stdout.should include 'Success'
end
Then /^I should be able to install the sample application using the "(.*?)" option$/ do |option|
sn = devices[0]
wait_for_device({:serial => sn}, 60)
install APK_FILE_NAME, option, {:serial => sn}, 60
end
Then /^I should be able to uninstall the sample application$/ do
sn = devices[0]
uninstall 'com.example.android.apis', {:serial => sn}
last_stdout.should include 'Success'
end
When /^I change the devices date and time to (.*?)$/ do |date_arg|
sn = devices[0]
date = DateTime.strptime(date_arg, '%m/%d/%C%y %I:%M')
shell("date -s #{format_date_for_adb(date)}", {:serial => sn}, 60)
end
Then /^the device time should be (.*?)$/ do |date_str|
last_stdout.should include date_str
end
Then /^I should be able to forward "(.*?)" to "(.*?)"$/ do |source, target|
sn = devices[0]
forward(source, target, {:serial => sn})
end
Then /^I can remount the system partition$/ do
sn = devices[0]
wait_for_device({:serial => sn}, 60)
remount({:serial => sn})
last_stdout.should include 'remount succeeded'
end
Then /^I can attain root privileges$/ do
sn = devices[0]
wait_for_device({:serial => sn}, 60)
root({:serial => sn})
#TODO: how to assert?
#last_stdout.should include 'remount succeeded'
end
Then /^I should be able to push a file to the local device$/ do
# be sure that the file doesn't already exist
sn = devices[0]
wait_for_device({:serial => sn}, 60)
remount({:serial => sn})
shell("rm #{TEMP_FILE_NAME}", {:serial => sn})
shell("ls #{TEMP_FILE_NAME}", {:serial => sn})
last_stdout.should include 'No such file or directory'
# create the temp file
File.open(TEMP_FILE_NAME, 'w'){ |f| f.write('Temporary file for adb testing. If found, please delete.') }
# push the file
push(TEMP_FILE_NAME, "#{TEMP_FILE_REMOTE_LOCATION}#{TEMP_FILE_NAME}", {:serial => sn})
last_stderr.should_not include 'failed to copy'
end
Then /^I should be able to pull a file from the local device$/ do
# confirm that the file exists on the device and not locally
sn = devices[0]
wait_for_device({:serial => sn}, 60)
remount({:serial => sn})
shell("touch #{TEMP_FILE_REMOTE_LOCATION}#{TEMP_FILE_NAME}", {:serial => sn})
# pull the file
pull "#{TEMP_FILE_REMOTE_LOCATION}#{TEMP_FILE_NAME}", #{TEMP_FILE_NAME}", {:serial => sn})
# confirm that the file was created
File.exists?(TEMP_FILE_NAME).should == true
end