-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera_BAT.py
512 lines (443 loc) · 16.9 KB
/
Camera_BAT.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
#/usr/bin/python
from devicewrapper.android import device as d
from uiautomator import device as dd
import unittest
import time
import os
import sys
import commands
import string
CAMERA_ACTIVITY = 'adb shell am start -n com.intel.camera22/.Camera'
CAMERA_ID = 'adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0.xml | grep pref_camera_id_key'
PictureSize_STATE ='adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0_0.xml | grep pref_camera_picture_size_key'
DCIM_PATH = '/sdcard/DCIM'
CAMERA_FOLDER = '100ANDRO'
VideoSize_STATE= 'adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0_0.xml | grep pref_video_quality_key'
VIDEO_NUMBERS = 'ls /mnt/sdcard/DCIM/100ANDRO/ | grep VID | wc -l'
Flash_STATE= 'adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0_0.xml | grep pref_camera_flashmode_key'
Geolocation_STATE ='adb shell cat /data/data/com.intel.camera22/shared_prefs/com.intel.camera22_preferences_0.xml | grep pref_camera_geo_location_key'
CameraIcon =(367,1085)
Flash =(370,75)
Setting =(52,60)
VideoSize =(288,175)
Geolocation =(172,175)
FrontGeolocation=(55,175)
SwitchCamera=(658,57)
Testcamera =(62,182)
WhiteBalance=(514,173)
Exposure = (407,175)
CPTUREBUTTON_RESOURCEID ='com.intel.camera22:id/shutter_button'
CPTUREPOINT='adb shell input swipe 363 1145 359 1045 '
FRONTBACKBUTTON_DESCR = 'Front and back camera switch'
DRAWDOWN_MENU='adb shell input swipe 530 6 523 22'
DRAWUP_CAPTUREBUTTON='adb shell input swipe 363 1145 359 1045 '
#####################################################3
class MyTest(unittest.TestCase):
def setUp(self):
d.press.home()
self._launchcamera()
super(MyTest,self).setUp()
def tearDown(self):
d.press.back()
super(MyTest,self).tearDown()
# Test case 1
def testCaptureWithBackAndFrontCamera(self):
# set camera status to back
self._confirmcamerastatus('back')
# take 10 picture
for i in range (0,1):
self._takePicture()
self._confirmcamerastatus('front')
for i in range (0,1):
self._takePicture()
self._confirmcamerastatus('back')
# Test case 2
def testCaptureWith6MPPortraitFlashOn(self):
# Set picture size
self._setPictureSizeStatus('WideScreen')
# Set flash status
self._setFlashStatus('on')
time.sleep(1)
self._takePicture()
# Test case 3
def testCaptureWithFrontCamera(self):
self._confirmcamerastatus('front')
time.sleep(1)
self._takePicture()
self._confirmcamerastatus('back')
# Test case 4
def testCaptureWith8MPPortraitFlashAuto(self):
# Set picture size
self._setPictureSizeStatus('StandardScreen')
# Set flash status
self._setFlashStatus('auto')
time.sleep(1)
self._takePicture()
time.sleep(1)
self._setPictureSizeStatus('WideScreen')
# Test case 5
def testCapturevideo720portraitposition(self):
# Select Video Mode mode
self._VideoMode()
time.sleep(1)
self._setVideoSizeStatus('5')
time.sleep(1)
self._takeVideo()
# Test case 6
def testCaptureburstimagesportraitmode(self):
self._launchBurst()
time.sleep(1)
self._takePicture()
# Test case 7
def testCapturePicturePanoramaWithGeolocation(self):
self._launchpanorama()
time.sleep(1)
self._setGeoLocationStatus('on')
time.sleep(1)
self._PtakePicture()
# Test case 8
def testCaptureVideoRecordingPressShutter(self):
self._VideoMode()
time.sleep(1)
self._CtakeVideo()
# Test case 9
def testCaptureSmilingFaceDefaultsettingPortraitBacFacingCamera(self):
self._launchSmail()
time.sleep(1)
self._stakePicture()
# Test case 10
def testCapturePerfectShotmodewithFacesPortrait(self):
self._launchperfectshot()
time.sleep(1)
self._setGeoLocationStatus('off')
time.sleep(1)
self._btakePicture()
# Test case 11
def testCaptureCaptureImagewithZoom(self):
d(resourceId = "com.intel.camera22:id/face_view").pinch.Out(percent=80, steps=200)
d(resourceId = "com.intel.camera22:id/face_view").pinch.Out(percent=80, steps=200)
d(resourceId = "com.intel.camera22:id/face_view").pinch.Out(percent=80, steps=200)
time.sleep(1)
self._takePicture()
# Test case 12
def testCaptureCaptureVideowithZoominbetween(self):
self._VideoMode()
time.sleep(2)
d(resourceId = "com.intel.camera22:id/camera_preview").pinch.Out(percent=80, steps=200)
d(resourceId = "com.intel.camera22:id/camera_preview").pinch.Out(percent=80, steps=200)
d(resourceId = "com.intel.camera22:id/camera_preview").pinch.Out(percent=80, steps=200)
self._takeVideo()
##############################################################
def _switchBackOrFrontCamera(self,status):
#Dictionary
camerastatus = {'back': '0','front':'1'}
# Get the current camera status
currentstatus = commands.getoutput(CAMERA_ID)
# Confirm the current status of the user is required
if currentstatus.find(camerastatus.get(status)) == -1:
# draw down the menu
commands.getoutput(DRAWDOWN_MENU)
time.sleep(1)
# set the camera status
d(description = FRONTBACKBUTTON_DESCR).click.wait()
time.sleep(3)
# Get the current camera status
currentstatus = commands.getoutput(CAMERA_ID)
# check the result
if currentstatus.find(camerastatus.get(status)) != -1:
print ('set camear is '+status)
return True
else:
print ('set camear is '+status+' fail')
return False
else:
print('Current camera is ' + status)
def _launchcamera(self):
commands.getoutput(CAMERA_ACTIVITY)
try:
d(text = 'OK').wait.exists(timeout=3000)
d(text = 'OK').click.wait()
except:
pass
finally:
pass
def _confirmcamerastatus(self,status):
#check back/front camera
if status == 'front':
camera = commands.getoutput(CAMERA_ID)
cameravalue = camera.find('1')
if cameravalue == -1:
commands.getoutput('adb shell input swipe 530 6 523 22')
d(description = 'Front and back camera switch').click.wait()
time.sleep(2)
camera = commands.getoutput(CAMERA_ID)
cameravalue = camera.find('1')
assert cameravalue != -1
if status == 'back':
camera = commands.getoutput(CAMERA_ID)
cameravalue = camera.find('0')
if cameravalue == -1:
commands.getoutput('adb shell input swipe 530 6 523 22')
d(description = 'Front and back camera switch').click.wait()
time.sleep(2)
camera = commands.getoutput(CAMERA_ID)
cameravalue = camera.find('0')
assert cameravalue != -1
def _takePicture(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
before = '0'
#Get the number of photo in sdcard
else:
before = commands.getoutput('adb shell ls /sdcard/DCIM/* | grep jpg | wc -l')
time.sleep(3)
d.click(356,1100)
time.sleep(3)
after = commands.getoutput('adb shell ls /sdcard/DCIM/* | grep jpg | wc -l')
time.sleep(2)
if string.atoi(before) < string.atoi(after):
print('take picture success!')
else:
self.fail('take picture fail!')
def _btakePicture(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
before = '0'
#Get the number of photo in sdcard
else:
before = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep BST | wc -l')
time.sleep(3)
d.click(356,1100)
time.sleep(2)
after = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep BST | wc -l')
time.sleep(2)
if string.atoi(before) < string.atoi(after) - 2 :
print('take picture success!')
else:
self.fail('take picture fail!')
def _stakePicture(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
before = '0'
#Get the number of photo in sdcard
else:
before = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep jpg | wc -l')
time.sleep(3)
d.click(356,1100)
time.sleep(2)
d.click(356,1100)
after = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep jpg | wc -l')
time.sleep(2)
if string.atoi(before) == string.atoi(after) - 1 or string.atoi(before) == string.atoi(after) - 2:
print('take picture success!')
else:
self.fail('take picture fail!')
def _PtakePicture(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
before = '0'
#Get the number of photo in sdcard
else:
before = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep jpg | wc -l')
time.sleep(3)
d.click(356,1100)
time.sleep(2)
d.click(356,1100)
time.sleep(3)
after = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep jpg | wc -l')
time.sleep(3)
if string.atoi(before) == string.atoi(after) - 1 or string.atoi(before) == string.atoi(after) - 2:
print('take picture success!')
else:
self.fail('take picture fail!')
def _DtakePicture(self):
self._ClearData()
d.swipe(363, 1145, 359, 1045, steps=600)
time.sleep(2)
after = commands.getoutput('adb shell ls /sdcard/DCIM/100ANDRO/* | grep jpg | wc -l')
time.sleep(3)
if string.atoi(after) > 10:
print('take picture success!')
else:
self.fail('take picture fail!')
def _setPictureSizeStatus(self,status):
#commands.getoutput('adb shell input swipe 530 6 523 22')
d.swipe(530,6,523,22)
time.sleep(1)
d.click(65,85)
time.sleep(1)
d.click(412,185)
time.sleep(1)
if status == 'WideScreen':
d.click(60,292)
elif status == 'StandardScreen':
d.click(180,292)
time.sleep(2)
state = commands.getoutput(PictureSize_STATE)
statevalue = state.find(status)
if statevalue == -1:
self.fail('set camera picture size to' + status +'fail!')
def _setFlashStatus(self,status):
#commands.getoutput('adb shell input swipe 530 6 523 22')
# Touch flash setting
d.swipe(530,6,523,22)
time.sleep(1)
d.click(270,85)
time.sleep(2)
if status == 'on':
d.click(176,176)
elif status == 'off':
d.click(59,178)
elif status == 'auto':
d.click(300,180)
else:
d.click(296,176)
time.sleep(2)
state = commands.getoutput(Flash_STATE)
statevalue = state.find(status)
if statevalue == -1:
self.fail('set camera flash status to' + status + 'fail!')
def _VideoMode(self):
d.click(645,1100)
time.sleep(1)
d.click(515,1100)
time.sleep(1)
def _setVideoSizeStatus(self,status):
commands.getoutput('adb shell input swipe 530 6 523 22')
time.sleep(1)
d.click(52,60)
time.sleep(1)
d.click(295,180)
time.sleep(1)
if status =='6':
d.click(405,288)
elif status =='5':
d.click(170,290)
elif status =='4':
d.click(56,288)
state = commands.getoutput(VideoSize_STATE)
if state != "":
statevalue = state.find(status)
if statevalue == -1:
self.fail('set video size with' +status+ 'fail!')
def _takeVideo(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
self.beforeNO = '0'
else:
self.beforeNO = commands.getoutput('adb shell '+ VIDEO_NUMBERS)
#Record video(30 seconds)
d(description = 'Shutter button').click.wait()
time.sleep(5)
d(description = 'Shutter button').click.wait()
#Identify add video successfully
addVideo = commands.getoutput('adb shell '+ VIDEO_NUMBERS)
if string.atoi(addVideo) != string.atoi(self.beforeNO)+1:
self.fail('take video fail!')
def _launchBurst(self):
try:
d(text = 'OK').wait.exists(timeout=3000)
d(text = 'OK').click.wait()
except:
pass
finally:
self._confirmcamerastatus('back')
d.click(650,1090)
d.click(358,1076)
d.click(360,922)
def _launchpanorama(self):
try:
d(text = 'OK').wait.exists(timeout=3000)
d(text = 'OK').click.wait()
except:
pass
finally:
d.click(650,1090)
time.sleep(2)
d.click(80,1084)
def _setGeoLocationStatus(self,status):
commands.getoutput('adb shell input swipe 530 6 523 22')
d.click(52,60)
d.click(50,168)
if status == 'on':
d.click(170,284)
elif status == 'off':
d.click(60,276)
state = commands.getoutput(Geolocation_STATE)
statevalue = state.find(status)
if statevalue == -1:
self.fail('set camera geoloaction to' + status + 'fail!')
def _VideoMode(self):
try:
d(text = 'OK').wait.exists(timeout=3000)
d(text = 'OK').click.wait()
except:
pass
finally:
d.click(650,1090)
time.sleep(3)
d.click(492,1101)
time.sleep(5)
def _CtakeVideo(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
self.beforeNO = '0'
else:
self.beforeNO = commands.getoutput('adb shell '+ VIDEO_NUMBERS)
#Record video(30 seconds)
d.swipe(363, 1145, 359, 1045, steps=100)
#Identify add video successfully
addVideo = commands.getoutput('adb shell '+ VIDEO_NUMBERS)
if string.atoi(addVideo) != string.atoi(self.beforeNO)+1:
self.fail('take video fail!')
def _launchSmail(self):
try:
d(text = 'OK').wait.exists(timeout=3000)
d(text = 'OK').click.wait()
except:
pass
finally:
d.click(650,1090)
d.click(650,930)
def _StakePicture(self):
result = commands.getoutput('adb shell ls '+DCIM_PATH)
if result.find(CAMERA_FOLDER) == -1:
self.logger.info("no 100ANDRO folder.")
before = '0'
#Get the number of photo in sdcard
else:
before = commands.getoutput('adb shell ls /sdcard/DCIM/* | grep IMG | wc -l')
time.sleep(3)
d(description = 'Shutter button').click.wait()
time.sleep(1)
d(description = 'Shutter button').click.wait()
after = commands.getoutput('adb shell ls /sdcard/DCIM/* | grep IMG | wc -l')
time.sleep(3)
if string.atoi(before) == string.atoi(after) - 1 or string.atoi(before) == string.atoi(after) - 2:
print('take picture success!')
else:
self.fail('take picture fail!')
def _launchperfectshot(self):
try:
d(text = 'OK').wait.exists(timeout=3000)
d(text = 'OK').click.wait()
except:
pass
finally:
d.click(650,1090)
time.sleep(3)
d.click(230,1097)
def _ClearData(self):
commands.getoutput('adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///mnt/sdcard/')
time.sleep(5)
commands.getoutput('adb shell rm /mnt/sdcard/DCIM/100ANDRO/*')
time.sleep(2)
commands.getoutput('adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///mnt/sdcard/')
if __name__ =='__main__':
unittest.main()