def play_video(self, secs=None, timeout=None): """click play video""" print "[Debug] play_video" mark_time = logcat.get_device_time_mark() pre_dump = self.d.dump() pre_focus = SystemUi.get_current_focus() print pre_focus self._view.play.click.wait() if secs: time.sleep(secs) end_dump = self.d.dump() end_focus = SystemUi.get_current_focus() print end_focus seq_match = difflib.SequenceMatcher(None, pre_dump, end_dump) ratio = round(seq_match.ratio(), 2) * 100 print "ratio:%s" % ratio if ratio == 100 and pre_focus == end_focus: assert False, "[FAILURE] Play video No any reply" if not secs: start_time = time.time() play_done = False while time.time() - start_time < timeout: time.sleep(10) if self._view.play.exists: play_done = True break assert play_done, "[FAILURE] Play video time out" errmsg = logcat.get_device_log(mark_time, filters='MediaPlayer:E *:S') assert not errmsg, "[FAILURE] Found Errors in Logcat during Play Video\n%s" % ( errmsg)
def play_video(self, secs=5): """play video""" print "[Debug] play_video" pre_dump = self.d.dump() pre_focus = SystemUi.get_current_focus() print pre_focus self.a.permission_allower() # if not self.d(description="play").exists: # self.d.press.back() time.sleep(2) self.plugin_video.play.click.wait(timeout=5000) time.sleep(secs) end_dump = self.d.dump() end_focus = SystemUi.get_current_focus() print end_focus seq_match = difflib.SequenceMatcher(None, pre_dump, end_dump) ratio = round(seq_match.ratio(), 2) * 100 print "ratio:%s" % ratio if ratio == 100 and pre_focus == end_focus: assert False, "[FAILURE] Play video No any reply"
def find_photo(self): print "[Debug] find_photo" for i in range(self._home.list_item.count): self._home.list_item[i].click() time.sleep(2) _, activity = SystemUi.get_current_focus() if activity != self.HostPhotoPagerActivity: continue if not self._view.is_video: self.d.press.back() time.sleep(2) print "photo index:%s" % (i) return i self.d.press.back() assert False, "There is no photo items"
class DocsToGo: ''' classdocs ''' pkg_name = "com.dataviz.docstogo" activity_name = "com.dataviz.dxtg.common.launcher.android.LauncherActivity" def __init__(self): self._device = g_common_obj.get_device() self._locator = Locator(self._device) self.tmpdir = getTmpDir() self.systemui = SystemUiExtendImpl() def launch_app_am(self): """ Launch DocsToGo via adb am command """ print "Launch DocsToGo by adb am" g_common_obj.launch_app_am(\ DocsToGo.pkg_name, DocsToGo.activity_name) time.sleep(3) if self._device(text="Welcome!").exists: self._device(text="Next").click() time.sleep(1) self._device(text="Accept").click() time.sleep(1) self._device(text="Later").click() time.sleep(1) @staticmethod def stop_app_am(): """ Stop DocsToGo via adb am command """ print "Stop DocsToGo by adb am" g_common_obj.stop_app_am(DocsToGo.pkg_name) def clean_workaround(self, docx): """ Clean the workaround to avoid other file affect. """ print "delete DocsToGo created documents folder" cmd = 'rm -rf sdcard/documents' g_common_obj.adb_cmd(cmd) print "delete the docx pushed" cmd = "rm -rf /sdcard/%s" % docx g_common_obj.adb_cmd(cmd) def edit_docx(self): """ Edit docx in DocsToGo. """ if not self._locator.create_file.exists: self.check_ad() self._locator.create_file.click.wait() time.sleep(1) self._locator.word_btn.click.wait() time.sleep(2) cmd = "input text test" g_common_obj.adb_cmd(cmd) print "Excute:Select all" self._locator.more_btn.click.wait() time.sleep(1) self._locator.edit_btn.click.wait() time.sleep(1) self._locator.select_all_btn.click.wait() time.sleep(1) print "Excute:Add Format Bold" self._locator.more_btn.click.wait() time.sleep(1) self._locator.format_btn.click.wait() time.sleep(1) self._locator.bold_btn.click.wait() time.sleep(1) print "Excute:Add Format Underline" self._locator.more_btn.click.wait() time.sleep(1) self._locator.format_btn.click.wait() time.sleep(1) self._locator.underline_btn.click.wait() time.sleep(1) print "Excute:Save docx" self._locator.more_btn.click.wait() time.sleep(1) self._locator.file_btn.click.wait() time.sleep(1) self._locator.save_btn.click.wait() time.sleep(1) self._locator.save_btn.click.wait() time.sleep(1) if self._device(text="File already exists, overwrite?").exists: self._device(text="Yes").click.wait() time.sleep(1) self._locator.return_btn.click.wait() time.sleep(2) self.check_ad() def check_docx(self): """ get screenshot and check cocx which template docx by screenshot in DocsToGo. """ assert self._device( text="Untitled.docx" ).exists, "Can not find the edited file Untitled.docx" self._device(text="Untitled.docx").click.wait() time.sleep(2) print "Excute:Select all" self._locator.more_btn.click.wait() time.sleep(1) self._locator.edit_btn.click.wait() time.sleep(1) self._locator.select_all_btn.click.wait() time.sleep(2) self.get_docx_screenshot("before.png") self._locator.return_btn.click.wait() time.sleep(2) self.check_ad() self._locator.back_btn.click.wait() time.sleep(1) if self._locator.back_btn.exists: self._locator.back_btn.click.wait() time.sleep(1) if not self._device(text="template.docx").exists: self._device(scrollable=True).scroll.to(text="template.docx") time.sleep(1) assert self._device( text="template.docx").exists, "can not found template.docx" self._device(text="template.docx").click.wait() time.sleep(2) print "Excute:Select all" self._locator.more_btn.click.wait() time.sleep(1) self._locator.edit_btn.click.wait() time.sleep(1) self._locator.select_all_btn.click.wait() time.sleep(2) self.get_docx_screenshot("after.png") time.sleep(2) rms = compare_pic.compare_pic(self.tmpdir + "/before.png", self.tmpdir + "/after.png") time.sleep(1) print "The Similarity value of 2 screenshot is %s" % rms assert rms <= 5, "Add front fail,rms=%s" % rms def get_docx_screenshot(self, picname): """ check cocx which template docx by screenshot in DocsToGo. """ print "catch screenshot %s" % picname bounds = self._device( resourceId="com.dataviz.docstogo:id/wtg_main_field_id").bounds path = get_screenshot_region(bounds) print path cmd = ('mv %s ' + self.tmpdir + '/' + picname) % path os.system(cmd) def check_ad(self): """ check if AD dialog popup,and close it. """ _, activity = self.systemui.get_current_focus() time.sleep(2) if activity == "com.google.android.gms.ads.AdActivity" or activity == "com.amazon.device.ads.AdActivity": if self._device(description="nativeCloseButtonImage").exists: print "static ads" self._device(description="nativeCloseButtonImage").click.wait() elif self._device(description="Skip Ad ").exists: print "video ads" self._device(description="Skip Ad ").click.wait() else: print "other ads" self._device.press.back() time.sleep(3) def uninstall_app(self): """ uninstall DocsToGo """ print "uninstall DocsToGo" cmd = 'uninstall %s' % DocsToGo.pkg_name g_common_obj.adb_cmd_common(cmd)
class ScreenCastingIdleTest(ChromeCastTestBase): @classmethod def setUpClass(cls): print "[setUpClass]: %s" % cls.__name__ super(ScreenCastingIdleTest, cls).setUpClass() def setUp(self): print "[Setup]:%s" % self.__class__.__name__ super(ScreenCastingIdleTest, self).setUp() cmd = 'date +"%m-%d %H:%M:%S"' self.test_time_mark = g_common_obj.adb_cmd_capture_msg(repr(cmd)) self.chrome_cast = self.IChromeCastImpl(self.cast_model) self.systemui = SystemUiExtendImpl() self.chrome_cast.setup() self.systemui.unlock_screen() self.d.screen.on() def tearDown(self): print "[tearDown]:%s" % self.__class__.__name__ cmd = 'logcat -d -v time -t "%s.000" *:F|grep -i Fatal' % ( self.test_time_mark) fatal_msg = g_common_obj.adb_cmd_common(cmd) assert not fatal_msg,\ "occurred Fatal error during testing:%s" % (fatal_msg) super(ScreenCastingIdleTest, self).tearDown() @classmethod def tearDownClass(cls): print "[tearDownClass]: %s" % cls.__name__ super(ScreenCastingIdleTest, cls).tearDownClass() def test_ScreenCasting_Idle20minutes(self): """ test_ScreenCasting_Idle20minutes Steps: 1. Turn on Chromecast on DUT. The Chromecast is shown on the scan list. 2. Connect to the Chromecast. The DUT is connected to the Chromecast. 3. Press Home button. The Home screen is shown. 4. Idle 20 minutes. The connection is not lost. """ print "[RunTest]: %s" % self.__str__() print """[Step] 1. Turn on Chromecast on DUT. The Chromecast is shown on the scan list.""" self.turn_on_wireless() self.chrome_cast.launch() cast_real_name = self.chrome_cast.choose_castscreen(self.cast_model) print """[Step] 2. Connect to the Chromecast. The DUT is connected to the Chromecast.""" self.chrome_cast.connect_cast_screen(cast_real_name) print """[Step] 3. Press Home button. The Home screen is shown.""" self.d.press.home() print self.systemui.get_current_focus() print """[Step] 4. Idle 20 minutes. The connection is not lost.""" self.chrome_cast.watch_connection_status(count=20, step=60) self.chrome_cast.verify_connection_from_quick_settings(self.cast_model) self.chrome_cast.resume() self.chrome_cast.disconnect_cast_screen()
class DisplayAllAppsOnHomeScreen(UIATestBase): @classmethod def setUpClass(cls): print "[setUpClass]: %s" % cls.__name__ super(DisplayAllAppsOnHomeScreen, cls).setUpClass() cls.d = g_common_obj.get_device() g_common_obj.root_on_device() g_common_obj.remount_device() config = TestConfig() cfg_file = 'tests.tablet.artifactory.conf' cfg_arti = config.read(cfg_file, 'artifactory') config_handle = ConfigHandle() cfg_arti["location"] = config_handle.read_configuration( 'artifactory', 'location', '/etc/oat/', 'sys.conf') # Change to photoGrid app since meitupic is not support for x86 cpu cfg_picasatool = config.read(cfg_file, 'content_photogrid') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_picasatool.get("name") file_path = arti.get(binary_name) print "[Setup]: install photogrid" result = config_handle.check_apps("com.roidapp.photogrid") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_picsart = config.read(cfg_file, 'content_picsart') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_picsart.get("name") file_path = arti.get(binary_name) print "[Setup]: install picsart" result = config_handle.check_apps("com.picsart.studio") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_picsay = config.read(cfg_file, 'content_picsay') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_picsay.get("name") file_path = arti.get(binary_name) print "[Setup]: install picsay" result = config_handle.check_apps("com.shinycore.picsayfree") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_sketchbook = config.read(cfg_file, 'content_sketchbook') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_sketchbook.get("name") file_path = arti.get(binary_name) print "[Setup]: install sketchbook" result = config_handle.check_apps("com.adsk.sketchbookhdexpress") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) cfg_skitch = config.read(cfg_file, 'content_skitch') arti = Artifactory(cfg_arti.get('location')) binary_name = cfg_skitch.get("name") file_path = arti.get(binary_name) print "[Setup]: install skitch" result = config_handle.check_apps("com.evernote.skitch") if result == 0: g_common_obj.adb_cmd_common('install ' + file_path) def setUp(self): print "[Setup]:%s" % self.__class__.__name__ super(DisplayAllAppsOnHomeScreen, self).setUp() self.systemui = SystemUiExtendImpl() # self.meitu_impl = MeituPicEdit() self.systemui.unlock_screen() self.d.screen.on() self.d.press.menu() self.mark_time = logcat.get_device_time_mark() def tearDown(self): print "[tearDown]:%s" % self.__class__.__name__ super(DisplayAllAppsOnHomeScreen, self).tearDown() # self.meitu_impl.uninstall_app() PhotoGridEdit().uninstall_app() PicsArtStudio().uninstall_app() PicSay().uninstall_app() SketchBookX().uninstall_app() Skitch().uninstall_app() @classmethod def tearDownClass(cls): print "[tearDownClass]: %s" % cls.__name__ super(DisplayAllAppsOnHomeScreen, cls).tearDownClass() def test_Display_AllAppsOnHomeScreen(self): """ test_Display_AllAppsOnHomeScreen """ # self.meitu_impl.launch_app_am() PhotoGridEdit().launch_app_am() app_pid = g_common_obj.adb_cmd_capture_msg( "ps | grep '%s' |awk '{print $2}'" % (PhotoGridEdit().pkg_name)) for i in range(6): time.sleep(5) _, activity = self.systemui.get_current_focus() if not activity == '': break assert activity == PhotoGridEdit( ).activity_name, "Check MeituPicEdit launch fail" fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F', pid=app_pid) assert len( fatal_msg) == 0, "occurred Fatal error during testing:\n%s" % ( fatal_msg) PhotoGridEdit().stop_app_am() time.sleep(2) PicsArtStudio().launch_app_am() _, activity = self.systemui.get_current_focus() assert activity == PicsArtStudio( ).activity_name, "Check PicsArtStudio launch fail" # fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F') # assert len(fatal_msg) == 0, \ # "occurred Fatal error during testing:\n%s" % (fatal_msg) PicsArtStudio().stop_app_am() time.sleep(2) PicSay().launch_app_am() _, activity = self.systemui.get_current_focus() assert activity == PicSay().activity_name, "Check PicSay launch fail" fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F', pid=app_pid) assert len( fatal_msg) == 0, "occurred Fatal error during testing:\n%s" % ( fatal_msg) PicSay().stop_app_am() time.sleep(2) SketchBookX().launch_app_am() _, activity = self.systemui.get_current_focus() assert activity == SketchBookX( ).activity_name, "Check SketchBookX launch fail" # fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F') # assert len(fatal_msg) == 0, \ # "occurred Fatal error during testing:\n%s" % (fatal_msg) SketchBookX().stop_app_am() time.sleep(2) Skitch().launch_app_am() _, activity = self.systemui.get_current_focus() assert activity == Skitch().activity_name, "Check Skitch launch fail" # fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F') # assert len(fatal_msg) == 0, \ # "occurred Fatal error during testing:\n%s" % (fatal_msg) Skitch().stop_app_am() time.sleep(2)