Exemplo n.º 1
0
    def run_test(self, log, timeout=30):
        self.video_test.logout(self.video_test.my_func_name(),
                               ">>>>>>>> Start video test <<<<<<<< ")
        self.video_test.clear_app_data()
        os.system(
            "adb shell am start -n com.opera.browser/com.opera.android.MainLauncherActivity -d http://10.239.93.52/workloads/H265_4k60fps.html"
        )
        time.sleep(30)
        print "123..."
        os.system("adb shell input tap 967.5 978")
        print "click accept..."
        # icount = 0
        # while icount < timeout:
        #     kill_adb_uiautomator_block_old()
        #     time.sleep(2)
        # kill_adb_uiautomator_block_old()
        # dev = self.video_test.device(test='ACCEPT & CONTINUE')
        # kill_adb_uiautomator_block_old()
        # if dev.exists:
        #     print "==click=="
        #     kill_adb_uiautomator_block_old()
        #     time.sleep(2)
        #     self.video_test.device(test='ACCEPT & CONTINUE').click()
        #     kill_adb_uiautomator_block_old()
        #     # dev.click()
        #     time.sleep(2)
        time.sleep(3)
        os.system("adb shell input tap 63 442")
        print "fullscreen..."
        time.sleep(2)
        os.system("adb shell input tap 968 528")
        print "play video..."
        time.sleep(25)
        self.video_fps_test.logout(self.video_fps_test.my_func_name(),
                                   "sssssssssssssssssssssssssssss")

        self.video_fps_test.doInThread(
            self.video_fps_test.run_fpstool_for_opera, log)
        self.video_fps_test.logout(self.video_fps_test.my_func_name(), "sssss")
        duration = 20
        while duration > 0:
            if utiliy.is_app_runing(self.app_package):
                self.video_test.logout(
                    self.video_test.my_func_name(),
                    "\r>>>Please wait for test complete ... %s(s)" % duration)
                duration -= 10
                time.sleep(10)
            else:
                print "nnnnnnnnnnnnot run"
            #else:
            #   self.video_fps_test.kill_fps_tools()
            #  return 0

        avg_fps = self.video_fps_test.collect_result(log)
        self.video_fps_test.logout(
            self.video_fps_test.my_func_name(),
            "%s result is:%s" % (self.test_case, avg_fps))
        self.video_fps_test.kill_fps_tools()
        #kill_adb_uiautomator_block()
        return avg_fps
    def wait_for_open_spacial_function(self,
                                       sp_text="",
                                       resourceIdMatches_txt="",
                                       timeout=600):
        failed_time = 0

        self.logout(
            self.my_func_name(),
            "Wait for %s spacial function: %s" % (self.app_package, sp_text))
        for i in range(timeout):
            unclock_android_o_screen()
            if i % 5 == 0:
                kill_adb_uiautomator_block()
            if resourceIdMatches_txt == "":
                if self.device(text=sp_text).exists:
                    return True
            else:
                if self.device(resourceIdMatches=".+/%s$" %
                               resourceIdMatches_txt).exists:
                    return True
            i += 1
            time.sleep(1)
            if not utiliy.is_app_runing(self.app_package):
                if failed_time > 6:
                    self.logout(self.my_func_name(),
                                "%s test is failed..." % self.app_package)
                    return False
                failed_time += 1
                continue
            failed_time = 0
        return False
 def click_ui_button_by_resourceIdMatches(self,
                                          key_code,
                                          not_id=False,
                                          timeout=10,
                                          package=''):
     icount = 0
     kill_adb_uiautomator_block_old()
     self.logout(self.my_func_name(), "%s click..." % key_code)
     while icount < timeout:
         unclock_android_o_screen()
         if package == '' and not utiliy.is_app_runing(self.app_package):
             self.logout(self.my_func_name(),
                         "%s test is failed..." % self.app_package)
             return False
         if not_id:
             app_dev = self.device(resourceIdMatches="%s" % key_code)
         else:
             app_dev = self.device(resourceIdMatches=".+/%s$" % key_code)
         if app_dev.exists:
             app_dev.click()
             icount = 0
             break
         time.sleep(1)
         icount += 1
         kill_adb_uiautomator_block_old()
     if icount > 0:
         return False
     else:
         return True
 def click_ui_button_by_text_or_resid(self,
                                      key_code='',
                                      resid='',
                                      timeout=10):
     icount = 0
     kill_adb_uiautomator_block_old()
     while icount < timeout:
         unclock_android_o_screen()
         if not utiliy.is_app_runing(self.app_package):
             self.logout(self.my_func_name(),
                         "%s test is failed..." % self.app_package)
             return False
         if resid == "":
             app_dev = self.device(text=key_code)
         else:
             app_dev = self.device(resourceId=resid)
         if app_dev.exists:
             app_dev.click()
             icount = 0
             break
         time.sleep(1)
         icount += 1
         kill_adb_uiautomator_block_old()
     if icount > 0:
         return False
     else:
         return True
 def wait_for_complete_ex(self, complete_text, timeout=1800):
     i = 0
     failed_time = 0
     self.logout(self.my_func_name(),
                 "%s test waiting..." % self.app_package)
     kill_adb_uiautomator_block()
     while i < timeout:
         unclock_android_o_screen()
         if self.device(resourceId="%s" % complete_text).exists:
             return True
         else:
             i += 5
             kill_adb_uiautomator_block()
             time.sleep(5)
             if not utiliy.is_app_runing(self.app_package):
                 if failed_time > 2:
                     self.logout(self.my_func_name(),
                                 "%s test is failed..." % self.app_package)
                     return False
                 failed_time += 1
                 continue
             sys.stdout.write("\r>>>Please wait for test complete. %s (s)" %
                              i)
             sys.stdout.flush()
             failed_time = 0
     else:
         self.logout(self.my_func_name(),
                     "Timeout for %s test" % self.app_name)
         return False
    def wait_for_complete(self,
                          complete_text,
                          timeout=600,
                          splittime=5,
                          package=''):
        i = 0
        failed_time = 0
        if not splittime == 5:
            time.sleep(splittime)
        kill_adb_uiautomator_block_old()

        while i < timeout:
            unclock_android_o_screen()
            kill_adb_uiautomator_block()
            if package == '' and not utiliy.is_app_runing(self.app_package):
                if failed_time > 2:
                    return False
                failed_time += 1
                continue
            app_dev = self.device(resourceIdMatches=".+/%s$" % complete_text)
            if app_dev:
                if app_dev.exists:
                    self.logout(self.my_func_name(),
                                "%s test finshed..." % self.app_name)
                    return True
            else:
                i += 5
                time.sleep(5)
                self.logout(self.my_func_name(),
                            "\r>>>Please wait for test complete. %s (s)" % i)
                failed_time = 0
        else:
            self.logout(self.my_func_name(),
                        "Timeout for %s test" % self.app_package)
            return False
    def run_test(self, log):
        self.video_test.logout(self.video_test.my_func_name(),
                               ">>>>>>>> Start video test <<<<<<<< ")
        self.video_test.clear_app_data()
        self.video_test.launch_app()
        time.sleep(2)
        print "lunch......"
        time.sleep(2)
        if not self.choose_video():
            return 0
        time.sleep(25)
        self.video_fps_test.doInThread(self.video_fps_test.run_fpstool, log)
        duration = 20
        while duration > 0:
            if utiliy.is_app_runing(self.app_package):
                self.video_test.logout(
                    self.video_test.my_func_name(),
                    "\r>>>Please wait for test complete ... %s(s)" % duration)
                duration -= 10
                time.sleep(10)
            else:
                self.video_fps_test.kill_fps_tools()
                return 0

        avg_fps = self.video_fps_test.collect_result(log)
        self.video_fps_test.logout(
            self.video_fps_test.my_func_name(),
            "%s result is:%s" % (self.test_case, avg_fps))
        self.video_fps_test.kill_fps_tools()
        #kill_adb_uiautomator_block()
        return avg_fps
    def wait_for_compelet_for_fps(self, timeout=100):
        kill_uiautomator()
        while timeout > 0:
            if not utiliy.is_app_runing(self.app_package):
                self.logout(self.my_func_name(),
                            "%s test is failed..." % self.app_package)
                return False
            timeout -= 10
            time.sleep(10)
            self.logout(
                self.my_func_name(),
                "\r>>>Please wait for test complete ... %s(s)" % timeout)

        return True
 def wait_for_root_page(self,
                        root_text="",
                        decription_text="",
                        timeout=300):
     failed_time = 0
     self.logout(self.my_func_name(),
                 "Wait for %s root page" % self.app_name)
     for i in range(timeout):
         unclock_android_o_screen()
         if i % 5 == 0:
             kill_adb_uiautomator_block_old()
             kill_uiautomator()
         if decription_text == "":
             if self.device(resourceIdMatches=".+/%s$" % root_text).exists:
                 print
                 break
         else:
             if self.device(description="%s" % decription_text).exists:
                 print
                 break
         i += 1
         time.sleep(1)
         if not utiliy.is_app_runing(self.app_package):
             if failed_time > 6:
                 self.logout(self.my_func_name(),
                             "%s test is failed..." % self.app_package)
                 return False
             failed_time += 1
             continue
         sys.stdout.write("\r>>>Please wait for %s root page. %s (s)" %
                          (self.app_name, i))
         sys.stdout.flush()
         failed_time = 0
     if i >= timeout:
         return False
     else:
         return True
 def click_ui_button_by_text(self,
                             key_code="",
                             textcont="",
                             index_nu="",
                             timeout=10,
                             skip_utiliy=False):
     icount = 0
     kill_adb_uiautomator_block_old()
     while icount < timeout:
         unclock_android_o_screen()
         if not skip_utiliy and not utiliy.is_app_runing(self.app_package):
             self.logout(self.my_func_name(),
                         "%s test is failed..." % self.app_package)
             return False
         if not "" == index_nu:
             if not "" == key_code:
                 app_dev = self.device(index=index_nu, text=key_code)
             if not "" == textcont:
                 app_dev = self.device(index=index_nu,
                                       textContains=textcont)
         else:
             if not "" == key_code:
                 app_dev = self.device(text=key_code)
             if not "" == textcont:
                 app_dev = self.device(textContains=textcont)
         if app_dev.exists:
             app_dev.click()
             icount = 0
             break
         time.sleep(1)
         icount += 1
         kill_adb_uiautomator_block_old()
     if icount > 0:
         return False
     else:
         return True
 def click_ui_button_by_text_to_right_resourceIdMatches(
         self, test_text, key_code, timeout=10):
     icount = 0
     kill_adb_uiautomator_block_old()
     while icount < timeout:
         unclock_android_o_screen()
         if not utiliy.is_app_runing(self.app_package):
             self.logout(self.my_func_name(),
                         "%s test is failed..." % self.app_package)
             return False
         app_dev = self.device(text=test_text)
         if app_dev.exists:
             right_bt = app_dev.right(resourceIdMatches=".+/%s$" % key_code)
             if right_bt.exists:
                 right_bt.click()
                 icount = 0
                 break
         time.sleep(1)
         icount += 1
         kill_adb_uiautomator_block_old()
     if icount > 0:
         return False
     else:
         return True
 def click_ui_button_by_description(self,
                                    key_code='',
                                    descriptioncon='',
                                    index_nu='',
                                    timeout=10):
     icount = 0
     kill_adb_uiautomator_block_old()
     self.logout(self.my_func_name(), "%s click..." % key_code)
     while icount < timeout:
         unclock_android_o_screen()
         if not utiliy.is_app_runing(self.app_package):
             self.logout(self.my_func_name(),
                         "%s test is failed..." % self.app_package)
             return False
         if not "" == index_nu:
             if not "" == key_code:
                 app_dev = self.device(index=index_nu, description=key_code)
             if not "" == descriptioncon:
                 app_dev = self.device(index=index_nu,
                                       descriptionContains=descriptioncon)
         else:
             if not "" == key_code:
                 app_dev = self.device(description=key_code)
             if not "" == descriptioncon:
                 app_dev = self.device(descriptionContains=descriptioncon)
         if app_dev.exists:
             app_dev.click()
             icount = 0
             break
         time.sleep(1)
         icount += 1
         kill_adb_uiautomator_block_old()
     if icount > 0:
         return False
     else:
         return True