def verify_wallpaper(self, qrcode): home_screen = tempfile.mktemp(suffix='.png', prefix='screen_', dir='/tmp') self.d.press.home() time.sleep(1) self.d.screenshot(home_screen) _, decode = qrcode_obj.decode_image_qrcode(home_screen) print "[Debug] verify_wallpaper qrcode:%s decode:%s" % (qrcode, decode) assert decode == qrcode, \ "[FAILURE] Failed verify wallpaper qrcode:%s decode:%s" % (qrcode, decode) remove_temp_file(home_screen)
def verify_screenshot_qrcode(self, qrcode): """ capture screenshot and decode qrcode """ home_screen = tempfile.mktemp(suffix='.png', prefix='screen_', dir='/tmp') self.d.screenshot(home_screen) _, decode = qrcode_obj.decode_image_qrcode(home_screen) print "[Debug] verify_wallpaper qrcode:%s decode:%s" % (qrcode, decode) assert decode == qrcode, \ "[FAILURE] Failed verify wallpaper qrcode:%s decode:%s" % (qrcode, decode) remove_temp_file(home_screen)
def verify_imageview(self): home_screen = tempfile.mktemp(suffix='.png', prefix='screen_', dir='/tmp') decode = '' for _ in range(10): self.d.screenshot(home_screen) ret, decode = qrcode_obj.decode_image_qrcode(home_screen) print "[Debug]", ret, decode if ret is False or decode == 'NULL': special_actions.zoom_in() continue break remove_temp_file(home_screen) return decode
def push_specified_qrcode_pictures(self, count=1, exts=None, mark_count=1): remote_pictures = [] pictures = self.configer.read(self.config_file, "Pictures") if exts: pictures = { k: v for k, v in pictures.iteritems() if v.lower().endswith(exts) } if count > len(pictures.items()): assert False, \ "[FAILURE] There are not enough resource." for _, value in pictures.iteritems(): pic_path = self.arti.get(value) qrcode = "ABCDEFGHIJ" pic_path = qrcode_obj.mark_image_qrcode(pic_path, code=qrcode, count=mark_count) ret = g_common_obj.push_file(pic_path, self.dut_photos_dir) remote_pictures.append({ 'qrcode': qrcode, 'path': self.dut_video_dir + '/' + os.path.basename(pic_path) }) assert ret, 'Failed push %s' % (pic_path) remove_temp_file(pic_path) count -= 1 if count == 0: break cmd = \ "am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://%s"\ % (self.dut_photos_dir) g_common_obj.adb_cmd_capture_msg(repr(cmd)) print "[Debug] pushed %s" % (remote_pictures) return remote_pictures
def set_option(self, name, percent): """change option SeekBar value""" print "[Debug] set_option %s %s" % (name, percent) pre_image = get_screenshot_region(self.image_display.bounds) self.device().scroll.to(text=name) bounds = self.device(text=name)\ .down(className='android.widget.SeekBar').info['bounds'] pre_bar = get_screenshot_region(bounds) self.device.click( bounds['left'] + (bounds['right'] - bounds['left']) * (percent / 100.00), (bounds['top'] + bounds['bottom']) / 2) time.sleep(1) end_bar = get_screenshot_region(bounds) g_common_obj.assert_exp_happens() end_image = get_screenshot_region(self.image_display.bounds) g_common_obj.assert_exp_happens() remove_temp_file(pre_bar) remove_temp_file(end_bar) remove_temp_file(pre_image) remove_temp_file(end_image)