class RefCamCamera(CameraAppInterface, CameraTestBase): PACKAGE_NAME_REFCAMCAMERA = "com.intel.refcam" ACTIVITY_NAME_REFCAMCAMERA = ".CameraActivity" PERMISSION_LIST = [ "android.permission.ACCESS_FINE_LOCATION", "android.permission.CAMERA", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.RECORD_AUDIO" ] def __init__(self, cfg=None): if cfg == None: self.cfg = self.config.read(CameraCommon.DEFAULT_CONFIG_FILE, "multimedia_camera") else: self.cfg = cfg self.d = g_common_obj.get_device() self.logger = CameraLogger.instance() self.x = self.d.info["displayWidth"] self.y = self.d.info["displayHeight"] self.camera_widget = self.CameraWidget() self.camera_common = CameraCommon() self.multimedia_setting = MultiMediaSetting( self.camera_common.DEFAULT_CONFIG_FILE) self.multimedia_setting.install_apk("ref_camera_1_apk") self.camera_common.grantPermission(self.PACKAGE_NAME_REFCAMCAMERA, self.PERMISSION_LIST) class CameraWidget: def __init__(self): self.d = g_common_obj.get_device() def frontback(self): ''' front back button ''' return self.d(resourceId="com.intel.refcam:id/switch_frontback") def itemChildMenu(self): ''' item clild menu ''' return self.d( resourceId="com.intel.refcam:id/setting_item_child_menu_text") def seekBar(self): ''' menu seek bar ''' return self.d( resourceId="com.intel.refcam:id/setting_item_child_menu_seekbar" ) def shutterBtn(self): ''' shutter button ''' return self.d(resourceId="com.intel.refcam:id/shutter") def shotlist(self): ''' front back button ''' return self.d(resourceId="com.intel.refcam:id/open_shot_list") def settingsBtn(self): ''' settings ''' return self.d(resourceId="com.intel.refcam:id/setting") def text(self, _text): ''' page text ''' return self.d(textContains=_text) def itemChildMenuText(self, _text): ''' page text ''' return self.d( resourceId="com.intel.refcam:id/setting_item_child_menu_text", textContains=_text) def zoomLayer(self): ''' zoom layer ''' return self.d(resourceId="com.intel.refcam:id/zoom_layer") #============================================================= def clickScreen(self): d = g_common_obj.get_device() x = d.info["displayWidth"] self.camera_common.clickBtn(x - 100, 300) def isShutterBtnExists(self): return self.camera_common.isWidgetExists( self.camera_widget.shutterBtn()) def setCaptureMode(self, value): self.camera_common.waitForWidgetToAppear(self.camera_widget.shotlist(), "mode button") self.camera_widget.shotlist().click.wait() self.camera_widget.text(value).click.wait() self.logger.debug("set capture mode to %s successfully" % value) self.camera_common.clickScreenCenter() #------------------------------------------------------------ # Interfaces' implementations are from here def cleanMediaFiles(self): """ Used to clean the media files in some folders; eg. /mnt/sdcard/DCIM/Camera """ self.logger.debug("clean media files start") g_common_obj.stop_app_am(self.PACKAGE_NAME_REFCAMCAMERA) g_common_obj.adb_cmd("pm clear %s" % self.PACKAGE_NAME_REFCAMCAMERA) self.logger.debug("clean media files successfully") def startCameraApp(self): """ Used to start the camera application """ self.camera_common.unlockScreen() self.logger.debug("launch refcam2 camera start") os.system( "adb shell am start -S %s/%s" % (self.PACKAGE_NAME_REFCAMCAMERA, self.ACTIVITY_NAME_REFCAMCAMERA)) time_left = 0 start = time.time() success = False while time_left < self.camera_common.waitStartAppTime + 15: if self.isShutterBtnExists() or self.camera_widget.shotlist( ).exists: success = True break if self.camera_widget.text( "Allow").exists or self.camera_widget.text("ALLOW").exists: self.camera_common.checkGuide() if self.camera_common.getAndroidVersion() == "N": self.stopCameraApp() os.system("adb shell am start -S %s/%s" % (self.PACKAGE_NAME_REFCAMCAMERA, self.ACTIVITY_NAME_REFCAMCAMERA)) time_left = time.time() - start time.sleep(0.5) self.camera_common.checkCameraCrash() if (not success ) or time_left > self.camera_common.waitStartAppTime + 15: scname = g_common_obj.get_user_log_dir() + "/assert.png" g_common_obj.take_screenshot(scname) assert False, "refcam2 camera launch fail,launch time is greater than " \ + str(self.camera_common.waitStartAppTime + 15) + " seconds" self.logger.debug("launch refcam2 camera successfully") def stopCameraApp(self): """ Used to stop the camera application """ g_common_obj.stop_app_am(self.PACKAGE_NAME_REFCAMCAMERA) self.logger.debug("stop arcsoft camera app successfully") def selectMode(self, mode="Camera"): """ Used to select a mode such as camera, video, panorama, lens blur, photo sphere and so on... """ self.camera_common.waitForWidgetToAppear( self.camera_widget.shutterBtn(), "shutter button") self.camera_widget.shotlist().click.wait() self.camera_widget.text(mode).click.wait() self.camera_common.clickScreenCenter() self.logger.debug("Change to %s mode" % mode) def switchRearOrFront(self, lens="Back"): """ Used to switch rear or front camera lens = Back / Front """ self.camera_common.waitForWidgetToAppear( self.camera_widget.shutterBtn(), "shutter button") if lens == "Front": self.camera_widget.frontback().click.wait() self.logger.debug("change to " + str(lens) + " camera") if lens == "Back" or lens == "Rear": self.logger.debug("change to " + str(lens) + " camera") time.sleep(2) def setExposure(self, value): pass def setFlash(self, flash="off"): """ Used to control the flash; on, off, auto """ pass def setGrid(self, grid="off"): """ Used to control the grid; on, off """ pass def setTimer(self, timer="off"): """ Used to control the timer value: off/2s/3s/10s """ pass def getAllVideoResolutions(self, lens): """ Return all of the video resolutions """ pass def setVideoResolution(self, resolution, lens): """ Used to control the video resolution, used with the getAllVideoResolutions """ pass def getAllCameraMode(self): pass def getAllPhotoResolutions(self, lens, type="Capture Size (JPEG)"): """ Return all of the photo resolutions """ self.camera_common.waitForWidgetToAppear( self.camera_widget.settingsBtn(), "setting button") self.camera_widget.settingsBtn().click.wait() if not self.camera_widget.text(type).exists: self.d(scrollable=True).scroll.vert.to(textContains=type) self.camera_common.waitForWidgetToAppear(self.camera_widget.text(type), "capture size button") self.camera_widget.text(type).click.wait() mCount = self.camera_widget.itemChildMenu().count mList = [] for i in range(mCount): mList.append(self.camera_widget.itemChildMenu()[i].info["text"]) self.clickScreen() self.logger.debug("mList=%s" % mList) if mList == []: self.logger.debug( "can't find photo resolutions with \"%s\" type!" % type) return [], -1, -1 else: return mList, mList[0], mList[mCount - 1] def setSettingsButton(self, main_click_button, sub_click_button): self.camera_common.waitForWidgetToAppear( self.camera_widget.settingsBtn(), "setting button") self.camera_widget.settingsBtn().click.wait() if not self.camera_widget.text(main_click_button).exists: self.d(scrollable=True).scroll.vert.to( textContains=main_click_button) self.camera_common.waitForWidgetToAppear( self.camera_widget.text(main_click_button), "click main button: %s" % main_click_button) self.camera_widget.text(main_click_button).click.wait() self.camera_widget.itemChildMenuText(sub_click_button).click.wait() self.logger.debug("click sub button: %s" % sub_click_button) self.clickScreen() def setPhotoResolution(self, resolution, lens, type="Capture Size (JPEG)"): """ Used to control the photo resolution, used with the getAllPhotoResolutions """ self.camera_common.waitForWidgetToAppear( self.camera_widget.settingsBtn(), "setting button") self.camera_widget.settingsBtn().click.wait() if not self.camera_widget.text(type).exists: self.d(scrollable=True).scroll.vert.to(textContains=type) self.camera_common.waitForWidgetToAppear(self.camera_widget.text(type), "capture size button") self.camera_widget.text(type).click.wait() self.camera_widget.itemChildMenuText(resolution).click.wait() self.logger.debug("set resolution to " + resolution) self.clickScreen() def capturePhoto(self, num=1, generated=True): """ Used to capture num photos """ self.camera_common.waitForWidgetToAppear( self.camera_widget.shutterBtn(), "shutter button") for i in range(int(num)): if self.camera_widget.shutterBtn().exists: self.camera_widget.shutterBtn().click.wait() self.logger.debug("capture photo %d" % (i + 1)) if generated: self.camera_common.waitForTheFilesAreGenerated() time.sleep(1.5) else: self.camera_common.checkCameraCrash() def reviewPhoto(self, num=1): """ Used to review num photos """ pass def reviewPhotoAndVideo(self, num=1, timeout=10): """ Used to review num photos """ pass def recordVideo(self, videoNum=1, duration=5): """ Used to capture num duration videos """ pass def reviewVideo(self, num=1, duration=1): """ Used to review num duration videos """ pass def snapShotDuringVideo(self, videoNum=1, duration=5, snapShotNum=1): """ Used to snapshot num pictures during a duration videos """ pass
class CameraBenchTest(CameraTestBase): """ @summary: This test used to test camera function """ def setUp(self): """ @summary: set up @return: None """ super(CameraBenchTest, self).setUp() self._test_name = __name__ print "[Setup]: %s" % self._test_name def tearDown(self): """ @summary: tearDown @return: None """ super(CameraBenchTest, self).tearDown() print "[Teardown]: %s" % self._test_name g_common_obj.stop_exp_handle() time.sleep(3) def appPrepare(self): self.camera = CameraCommon().switchPlatform(None, False, True, False, True) # self.camera = RefCam2Camera() self.common = CameraCommon() self.multimedia_setting = MultiMediaSetting( CameraCommon.DEFAULT_CONFIG_FILE) # self.camera = self.common.switchPlatform() self.checkImage = CheckImage() self.video = CheckVideo() # self.checkIQ = CheckIQ() self.host_path = self.common.getTmpDir() self.makefileTime = self.common.makefileTime self.camera_dir = self.common.camera_dir self.common.removeDeivceFile() self.common.removeFile(self.host_path + "/*") self.camera.cleanMediaFiles() # self.common.setOrientationToVertical() self.logger.debug("app prepare successfully") self.device = self.common.initDevice() self.common.resetDevice(self.device) def checkFileCorrupt(self, mediaFileCount=1): return self.common.checkFileCorrupt(mediaFileCount) def cameraExtendPanoramaRearLeft2RightAutoStopTest(self): try: self.appPrepare() # self.common.controlLightBox(1) # self.common.controlLightBox(6) # device = self.common.initDevice() self.camera.startCameraApp() self.camera.switchRearOrFront("Back") self.camera.setCaptureMode("Panorama") self.camera.capturePhoto(1, False) time.sleep(3) self.common.rotateDevice(self.device, -180) self.common.resetDevice(self.device) self.checkFileCorrupt() # self.common.controlLightBox(6) # self.common.controlLightBox(1) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def cameraFaceTrackTurnOnAndOffTest(self, lens): try: self.appPrepare() self.camera.startCameraApp() self.camera.switchRearOrFront(lens) if lens == "Back": self.common.rotateDevice(self.device, -90) else: self.common.rotateDevice(self.device, 90) self.camera.faceDetectionOnAndOff() time.sleep(5) self.common.clickScreenCenter() self.common.getScreenshotAndPullToHost("sc_enable_ft1.png", self.host_path) self.camera.faceDetectionOnAndOff() time.sleep(5) self.common.clickScreenCenter() self.common.pressBack(2) self.camera.startCameraApp() self.common.getScreenshotAndPullToHost("sc_disable_ft2.png", self.host_path) self.camera.faceDetectionOnAndOff() time.sleep(5) self.common.clickScreenCenter() self.common.getScreenshotAndPullToHost("sc_enable_ft2.png", self.host_path) self.common.resetDevice(self.device) remotejarFile = self.multimedia_setting.download_file_to_host( "Multimedia_Camera/apk/IQCheck") print remotejarFile iqcheckDir = self.host_path + os.sep + "IQCheck" print iqcheckDir if os.path.exists(iqcheckDir) == False: os.system("cp " + remotejarFile + " " + iqcheckDir) os.system("chmod 777 " + iqcheckDir) checkIQ = CheckIQ("", self.host_path) l = self.camera.getFOVRegion() region = CheckIQ.Region(l[0], l[1], l[2], l[3], False) enable_number1 = checkIQ.detectRect( self.host_path + "/sc_enable_ft1.png", region) disable_number = checkIQ.detectRect( self.host_path + "/sc_disable_ft2.png", region) enable_number2 = checkIQ.detectRect( self.host_path + "/sc_enable_ft2.png", region) if enable_number1 > disable_number: self.logger.debug("face detect success") else: os.system("cp " + self.host_path + "/sc_enable_ft1.png " + g_common_obj.get_user_log_dir()) os.system("cp " + self.host_path + "/sc_disable_ft2.png " + g_common_obj.get_user_log_dir()) self.logger.debug("enable_number1=" + str(enable_number1)) self.logger.debug("disable_number=" + str(disable_number)) self.assertTrue(False, "face detect failure") if enable_number2 > disable_number: self.logger.debug("face detect success") else: os.system("cp " + self.host_path + "/sc_enable_ft1.png " + g_common_obj.get_user_log_dir()) os.system("cp " + self.host_path + "/sc_disable_ft2.png " + g_common_obj.get_user_log_dir()) self.logger.debug("enable_number2=" + str(enable_number2)) self.logger.debug("disable_number=" + str(disable_number)) self.assertTrue(False, "face detect failure") # print self.checkIQ.detectRect("/tmp/logs/sc_disable_ft2.png",self.checkIQ.Region(self.camera.getFOVRegion(),False)) # print self.checkIQ.detectRect("/tmp/logs/sc_enable_ft2.png", self.checkIQ.Region(self.camera.getFOVRegion(), False)) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def cameraSceneDetectPortraitCaptureTest(self): try: self.appPrepare() self.camera.startCameraApp() self.camera.switchRearOrFront("Back") self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: if value != "Standard": self.assertTrue(False, "scene capture type is not standard") else: self.assertTrue(False, "scene capture type info is none") self.common.removeDeivceFile() self.camera.setCaptureMode("Smart") self.common.clickScreenCenter() self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: if value != "Portrait": self.assertTrue(False, "scene capture type is not portrait") else: self.logger.debug( "check scene capture type is portrait success") else: self.assertTrue(False, "scene capture type info is none") self.camera.switchRearOrFront("Front") self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: # print "=====================front value3=" + value if value != "Standard": self.assertTrue(False, "scene capture type is not standard") else: self.assertTrue(False, "scene capture type info is none") self.common.removeDeivceFile() self.camera.setCaptureMode("Smart") self.common.clickScreenCenter() self.camera.capturePhoto() info = self.checkFileCorrupt()[0] value = info.get("Scene Capture Type") if None != value: # print "====================front value4=" + value if value != "Portrait": self.assertTrue(False, "scene capture type is not portrait") else: self.logger.debug( "check scene capture type is portrait success") else: self.assertTrue(False, "scene capture type info is none") self.common.resetDevice(self.device) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def cameraSmileShotSmileDetectTest(self, lens): try: self.appPrepare() self.camera.startCameraApp() self.camera.switchRearOrFront(lens) if lens == "Back": self.common.rotateDevice(self.device, -90) else: self.common.rotateDevice(self.device, 90) self.camera.setCaptureMode("Smile") time.sleep(10) if self.common.checkDeviceFile(): self.assertTrue(False, "file exists, check file failed") self.camera.capturePhoto() self.checkFileCorrupt() self.common.removeDeivceFile() if lens == "Back": self.common.rotateDevice(self.device, 90) else: self.common.rotateDevice(self.device, 90) if not self.common.checkDeviceFile(): self.assertTrue(False, "file not exists, check file failed") self.checkFileCorrupt() self.common.resetDevice(self.device) except Exception as e: self.common.resetDevice(self.device) self.common.checkCameraCrash() self.assertTrue(False, e) def test_Camera_ExtendPanorama_Rear_Left2Right_AutoStop(self): self.cameraExtendPanoramaRearLeft2RightAutoStopTest() def test_Camera_FaceTrack_Front_TurnOnAndOff(self): self.cameraFaceTrackTurnOnAndOffTest("Front") def test_Camera_FaceTrack_Rear_TurnOnAndOff(self): self.cameraFaceTrackTurnOnAndOffTest("Back") def test_Camera_SceneDetect_Portrait_Capture(self): self.cameraSceneDetectPortraitCaptureTest() def test_Camera_SmileShot_Front_SmileDetect(self): self.cameraSmileShotSmileDetectTest("Front") def test_Camera_SmileShot_Rear_SmileDetect(self): self.cameraSmileShotSmileDetectTest("Back")