-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_case.py
More file actions
executable file
·66 lines (53 loc) · 1.74 KB
/
Copy pathtest_case.py
File metadata and controls
executable file
·66 lines (53 loc) · 1.74 KB
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
import subprocess, time, os
CASE_LIST=[
"com.lenovo.lsf.device.test.SdacTest#testSdacReg01",
"com.lenovo.lsf.device.test.SdacTest#testSdacReg04",
"com.lenovo.lsf.device.test.SdacTest#testSdacReg06"
] #CASE_LIST END
PKG_LIST=[
"com.lenovo.lsf.device",
"com.lenovo.lsf.device.test"
]
APK_LIST=[
"LSF-Device-Lenovo-Phone.8888.apk",
"LSF-Device-Lenovo-Phone-Testcase.8888.apk"
]
#Test case
def test_case():
for pkg in PKG_LIST:
out = run_cmd('adb uninstall '+pkg)
print 'Uninstall '+pkg+' '+out
for apk in APK_LIST:
out = run_cmd('adb install C:/Users/a/Desktop/'+apk)
print 'Installing apk '+apk+'\n'+out
out = run_cmd('adb root')
if out.find('adbd is already running as root')<0:
print out
time.sleep(10)
out = run_cmd('adb remount')
if out.find('remount succeeded')<0:
raise Exception('adb remount error : %s' %out)
print 'Test START.\n'
count = 1
for case in CASE_LIST:
print 'Testing case'+str(count)+': '+case
count+=1
out = run_cmd('adb shell am instrument -e class '+case+' -w com.lenovo.lsf.device.test/android.test.InstrumentationTestRunner')
print out
print 'Test END.'
os.system("pause")
#The run command method
def run_cmd(command):
cmd_list = command.split()
proc = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#The read(), close() and wait() come from the commnunicate() optimized part
#Since we use 2 pipes, the communicate() will start multiple threads on windows, or call poll/select on unix.
#So we don't call communicate, and we only read stdout in main thread
out = proc.stdout.read()
proc.stdout.close()
proc.wait()
if out.find('error: device not found')>=0:
raise Exception('%s - %s' %(command, out))
return out.replace('\r', '')
#Run the test method
test_case()