def startCameraApp(self): """ Used to start the camera application """ CameraCommon().unlockScreen() self.logger.debug("launch gms camera start") os.system("adb shell am start -n %s/%s" % (self.PACKAGE_NAME_GMSCAMERA, self.ACTIVITY_NAME_GMSCAMERA)) time_left = 0 start = time.time() success = False while time_left < CameraCommon().waitStartAppTime: if self.isShutterBtnExists() or self.GMSCameraWidget( ).photoPreviewPageDeleteBtn().exists: success = True break CameraCommon().checkCameraAccessDevicesLocation() CameraCommon().checkGuide() time_left = time.time() - start time.sleep(0.5) CameraCommon().checkCameraCrash() if (not success) or time_left > CameraCommon().waitStartAppTime: scname = g_common_obj.get_user_log_dir() + "/assert.png" g_common_obj.take_screenshot(scname) assert False, "gms camera launch fail,launch time is greater than " \ + str(CameraCommon().waitStartAppTime) + " seconds" time.sleep(2) if self.GMSCameraWidget().text("NEXT").exists: CameraCommon().checkGuide() self.logger.debug("launch gms camera 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 startCameraApp(self): """ Used to start the camera application """ CameraCommon().unlockScreen() self.logger.debug("launch arcsoft camera start") os.system("adb shell am start -S %s/%s" % (self.PACKAGE_NAME_ARCSOFTCAMERA, self.ACTIVITY_NAME_ARCSOFTCAMERA)) time_left = 0 start = time.time() success = False while time_left < CameraCommon().waitStartAppTime + 5: if self.isShutterBtnExists(): success = True break CameraCommon().checkGuide() time_left = time.time() - start time.sleep(0.5) CameraCommon().checkCameraCrash() if (not success) or time_left > CameraCommon().waitStartAppTime: scname = g_common_obj.get_user_log_dir() + "/assert.png" g_common_obj.take_screenshot(scname) assert False, "arcsoft camera launch fail,launch time is greater than " \ + str(CameraCommon().waitStartAppTime + 5) + " seconds" self.logger.debug("launch arcsoft camera successfully")
def find_icon(self, filename, timeout=3, error="can not get the picture"): from testlib.common.base import getTmpDir if_getpic_succeed = False time = 0 base_path = os.path.split(os.path.realpath(__file__))[0].split(os.sep) pics_path = (os.sep).join(base_path + ['pics', '']) if timeout > 8: timeout = 3 x = self.d.info["displayWidth"] y = self.d.info["displayHeight"] mycomp = igascomparator() region = matchedregion_s() base_filename = filename next = 2 toEnd = False swipetime = 1 sleep(2) screenshotPath = getTmpDir() if not os.path.exists(screenshotPath): os.mkdir(screenshotPath) screenshotPath = os.path.join(screenshotPath, "screenshot.png") while region.center_x == 0 and region.center_y == 0 and time < timeout: verifyImage(pics_path + filename) for eachTry in range(3): try: g_common_obj.take_screenshot(screenshotPath) verifyImage(screenshotPath) sleep(2) break except BaseException, e: if eachTry == 2: raise print e print "screen shot failed, try again!" mycomp.findpattern(pics_path + filename, screenshotPath, region) sleep(1) time = time + 2 if region.center_x != 0 or region.center_y != 0: if_getpic_succeed = True if time >= timeout and region.center_x == 0 and region.center_y == 0: tempname = base_filename.split(".") next_file = tempname[0] + str(next) + "." + tempname[1] if (os.path.exists(pics_path + next_file)): filename = next_file print filename next += 1 time = 1 else: if toEnd: break swipetime += 1 #self.d.swipe(x-50,y/2,50,y/2) time = 1 filename = base_filename print filename next = 2 if swipetime > 5: toEnd = True continue
def failureException(self): try: scname = os.path.join(g_common_obj.globalcontext.user_log_dir + "screenshot.png") g_common_obj.take_screenshot(scname) except Exception as e: print e.message, e.args traceback.print_exc()
def test_AppSwitching(self): print "[RunTest]: %s" % self.__str__() self.photos.play_video_command(self.remote_path, 5) self.bench.setup() self.bench.run_test("ALU 2", 50000) time.sleep(10) self.photos.play_video_command(self.remote_path, 5) screen_temp = tempfile.mktemp(suffix='.png', prefix='screenshot_', dir='/tmp') g_common_obj.take_screenshot(screen_temp) ret, qrcode = self._qr.decode_image_qrcode(screen_temp) assert ret and qrcode == "QRCODE_TEST_STRING", "Video playback failed!"
def get_screenshot_region(bounds=g_common_obj.get_device()().bounds): """get screen's region image""" screenshot_img = tempfile.mktemp(suffix='.png', prefix='temp_screen_', dir='/tmp') region_img = tempfile.mktemp(suffix='.png', prefix='region_', dir='/tmp') g_common_obj.take_screenshot(screenshot_img) assert os.path.isfile(screenshot_img) image = Image.open(screenshot_img) box = (bounds["left"], bounds["top"], bounds["right"], bounds["bottom"]) region = image.crop(box) region.save(region_img) remove_temp_file(screenshot_img) return region_img
def startCameraApp(self, check_success=1): """ Used to start the camera application """ self.logger.debug("launch ivi camera start") self.relay08_helper.set_relay_NO(IVICamera.CAMERA_RELAY) start = time.time() success = False if check_success == 1: while time.time() - start < self.waitStartCameraTime: if self.isCameraLayoutExists(): success = True break time.sleep(1) self.checkCameraCrash() if not success: scname = g_common_obj.get_user_log_dir() + "/assert.png" g_common_obj.take_screenshot(scname) assert False, "ivi camera launch fail,launch time is greater than " \ + str(self.waitStartCameraTime) + " seconds" self.logger.debug("launch ivi camera successfully") else: self.logger.debug("launch ivi camera, skip check function")