class AppSystemTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()
        
#         self.account.sleep()
#         self.account.wakeup()
#         self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start1=time.time()
        while time.time()-start1<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        if not AppStoreIcon.exists:
            #注销登陆
#             self.d.click(57,10)
#             time.sleep(1)
#             self.d.click(68,141)
#             start2=time.time()
#             while time.time()-start2<constants.Time_Out:
#                 if  Button1.exists:
#                     break
#                 else:
#                     time.sleep(1)
#             self.account.login()
#             start3=time.time()
#             while time.time()-start3<constants.Time_Out:
#                 if not Button1.exists:
#                     break
#                 else:
#                     time.sleep(1)
            self.d.click(950,562)
            time.sleep(1)
            Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
            if Button1.exists:
                Button1.click()
            time.sleep(1)
            if not AppStoreIcon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(AppStoreIcon.exists)
        
        self.adb_tools.adb_shell('am force-stop com.alibaba.micropc.appstore')
        
        
    def tearDown(self):
        self.adb_tools.adb_shell('am force-stop com.alibaba.micropc.appstore')

    def test_EnterAppstore(self):
        logger.info('Enter -- MUAT:AppSystemTest:test_EnterAppstore')
        apk_manager = ApkManager()
        value = {}
        #report = MuatReport()
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
        
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        click_x = AppStoreIcon.info['visibleBounds']['left'] +5
        click_y = AppStoreIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
                break
            else:
                time.sleep(1)
        if not self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists)
        if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.micropc.appstore")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
                #time.sleep(5)
        logger.info('Exit -- MUAT:AppSystemTest:test_EnterAppstore')
                
    def test_EnterAppstoreIndexTab(self):
        logger.info('Enter -- MUAT:AppSystemTest:test_EnterAppstoreIndexTab')
        apk_manager = ApkManager()
        value = {}
        #report = MuatReport()
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
         
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        click_x = AppStoreIcon.info['visibleBounds']['left'] +5
        click_y = AppStoreIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
                break
            else:
                time.sleep(1)
        if not self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists)
        indexTab = self.d(text=u"推荐", resourceId="com.alibaba.micropc.appstore:id/indexTab")
        if not indexTab.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(indexTab.exists)
        if indexTab.exists:
            indexTab.click()
            #time.sleep(5)
        if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.micropc.appstore")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
                #time.sleep(5)
        logger.info('Exit -- MUAT:AppSystemTest:test_EnterAppstoreIndexTab')
                
    def test_EnterAppstoreTopicTab(self):
        logger.info('Enter -- MUAT:AppSystemTest:test_EnterAppstoreTopicTab')
        apk_manager = ApkManager()
        value = {}
        #report = MuatReport()
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
        
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        click_x = AppStoreIcon.info['visibleBounds']['left'] +5
        click_y = AppStoreIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
                break
            else:
                time.sleep(1)
        if not self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists)
        topicTab = self.d(text=u"发现", resourceId="com.alibaba.micropc.appstore:id/topicTab")
        if not topicTab.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(topicTab.exists)
        if topicTab.exists:
            topicTab.click()
            #time.sleep(5)
        if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.micropc.appstore")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
                #time.sleep(5)
        logger.info('Exit -- MUAT:AppSystemTest:test_EnterAppstoreTopicTab')
        
    def test_EnterAppstoreMyApp(self):
        logger.info('Enter -- MUAT:AppSystemTest:test_EnterAppstoreMyApp')
        apk_manager = ApkManager()
        value = {}
        #report = MuatReport()
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
        
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        click_x = AppStoreIcon.info['visibleBounds']['left'] +5
        click_y = AppStoreIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
                break
            else:
                time.sleep(1)
        if not self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists)
        topicTab = self.d(text=u"我的应用", resourceId="com.alibaba.micropc.appstore:id/myappTab")
        if not topicTab.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(topicTab.exists)
        if topicTab.exists:
            topicTab.click()
            #time.sleep(5)
        if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.micropc.appstore")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
                #time.sleep(5)
        logger.info('Exit -- MUAT:AppSystemTest:test_EnterAppstoreMyApp')
        
        
        
Exemple #2
0
class DesktopSystemTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest("process monitor stop")

        self.d = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.mouse.move(1920, 1080)
        self.adb_tools = AdbTools()

        self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
        self.FailureIamgePath = os.path.join(
            os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage"
        )
        self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")

        if not os.path.exists(self.TmpImagePath):
            os.mkdir(self.TmpImagePath)
        if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
            os.mkdir(os.path.join(self.TmpImagePath, "croped"))

        #         self.account.sleep()
        #         self.account.wakeup()
        #         self.account.login()
        Button1 = self.d(resourceId="com.yunpc.yunosloginui:id/avatar")
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        self.adb_tools.adb_shell("am force-stop com.alibaba.micropc.appstore")
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        if not AppStoreIcon.exists:
            start2 = time.time()
            while time.time() - start2 < constants.Time_Out:
                if Button1.exists:
                    break
                else:
                    time.sleep(1)
            if not AppStoreIcon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self, name)

    def tearDown(self):
        self.adb_tools.adb_shell("am force-stop com.alibaba.micropc.appstore")
        if os.path.exists(self.TmpImagePath):
            shutil.rmtree(self.TmpImagePath)
        time.sleep(1)

    def test_StatusBar(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_StatusBar")
        BaseImg = os.path.join(self.BaseImagePath, "test_StatusBar.jpg")
        name = "test_StatusBar_%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime())
        img = os.path.join(self.TmpImagePath, name)
        self.d.screenshot(img)
        cropedImgPath = os.path.join(self.TmpImagePath, "croped", name.replace(".jpg", "_croped.jpg"))
        CropImage(img, cropedImgPath, 0, 0, 1810, 25)
        if not CompareImage(cropedImgPath, BaseImg, 0.9):
            shutil.copy(cropedImgPath, os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")))
            path = os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg"))
            self.fail("The failure file path is %s") % path

        logger.info("Exit -- MUAT:DesktopSystemTest:test_StatusBar")

    def test_TaskBar(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_TaskBar")

        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        click_x = AppStoreIcon.info["visibleBounds"]["left"] + 5
        click_y = AppStoreIcon.info["visibleBounds"]["top"] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        appstoreWindow = self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore")
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if appstoreWindow.exists:
                break
            else:
                time.sleep(1)
        if not appstoreWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)

        self.assertTrue(appstoreWindow.exists)
        self.mouse.click(
            appstoreWindow.info["visibleBounds"]["left"] + 10,
            appstoreWindow.info["visibleBounds"]["top"] + 10,
            constants.MouseLeftKey,
        )

        hideButton = self.d(packageName="com.alibaba.micropc.appstore", resourceId="android:id/pc_hide")
        if hideButton.exists:
            hideButton.click()
            start = time.time()
            while time.time() - start < constants.Time_Out:
                if not hideButton.exists:
                    break
                else:
                    time.sleep(1)
            if self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self, name)

            self.assertFalse(
                self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists
            )
            BaseImg = os.path.join(self.BaseImagePath, "test_TaskBar.jpg")
            name = "test_TaskBar_%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime())
            img = os.path.join(self.TmpImagePath, name)
            self.d.screenshot(img)
            cropedImgPath = os.path.join(self.TmpImagePath, "croped", name.replace(".jpg", "_croped.jpg"))
            CropImage(img, cropedImgPath, 0, 1035, 70, 1080)
            if not CompareImage(cropedImgPath, BaseImg, 0.9):
                shutil.copy(cropedImgPath, os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")))
                self.fail("The failure file path is %s") % os.path.join(
                    self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")
                )
            self.mouse.click(35, 1050, constants.MouseLeftKey)
            start = time.time()
            while time.time() - start < constants.Time_Out:
                if hideButton.exists:
                    break
                else:
                    time.sleep(1)
            if not self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self, name)
            self.assertTrue(
                self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore").exists
            )

        closeButton = self.d(packageName="com.alibaba.micropc.appstore", resourceId="android:id/pc_close")
        if closeButton.exists:
            closeButton.click()
        else:
            self.mouse.click(35, 1050, constants.MouseLeftKey)
            start = time.time()
            while time.time() - start < constants.Time_Out:
                if hideButton.exists:
                    break
                else:
                    time.sleep(1)
            closeButton = self.d(packageName="com.alibaba.micropc.appstore", resourceId="android:id/pc_close")
            closeButton.click()
        logger.info("Exit -- MUAT:DesktopSystemTest:test_TaskBar")

    def test_DragIcon(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_DragIcon")
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        if AppStoreIcon.exists:
            oldX = AppStoreIcon.info["visibleBounds"]["left"]
            oldY = AppStoreIcon.info["visibleBounds"]["top"]
            self.mouse.pressmove(
                AppStoreIcon.info["visibleBounds"]["left"] + 5,
                AppStoreIcon.info["visibleBounds"]["top"] + 5,
                300,
                300,
                constants.MouseLeftKey,
            )
            time.sleep(5)
            newAppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
            if not newAppStoreIcon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self, name)
            self.assertTrue(newAppStoreIcon.exists)
            if newAppStoreIcon.exists:
                self.assertNotEqual(oldX, newAppStoreIcon.info["visibleBounds"]["left"])
                self.assertNotEqual(oldY, newAppStoreIcon.info["visibleBounds"]["top"])
                self.mouse.pressmove(
                    newAppStoreIcon.info["visibleBounds"]["left"] + 5,
                    newAppStoreIcon.info["visibleBounds"]["top"] + 5,
                    -300,
                    -300,
                    constants.MouseLeftKey,
                )
        logger.info("Exit -- MUAT:DesktopSystemTest:test_DragIcon")

    def test_DoubleClickIcon(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_DoubleClickIcon")
        AppStoreIcon = self.d(text=u"应用商店", className="android.widget.TextView")
        if AppStoreIcon.exists:
            self.mouse.doubleclick(
                AppStoreIcon.info["visibleBounds"]["left"] + 5,
                AppStoreIcon.info["visibleBounds"]["top"] + 5,
                constants.MouseLeftKey,
            )
            AppStoreWindow = self.d(className="android.widget.FrameLayout", packageName="com.alibaba.micropc.appstore")
            start = time.time()
            while time.time() - start < constants.Time_Out:
                if AppStoreWindow.exists:
                    break
                else:
                    time.sleep(1)
            if not AppStoreWindow.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self, name)
            self.assertTrue(AppStoreWindow.exists)
            if AppStoreWindow.exists:
                closeButton = self.d(
                    resourceId="android:id/pc_close",
                    className="android.widget.ImageView",
                    packageName="com.alibaba.micropc.appstore",
                )
                if closeButton.exists:
                    logger.debug("click close button: (%s)" % (closeButton.info["packageName"]))
                    closeButton.click()
                    # time.sleep(5)
        logger.info("Exit -- MUAT:DesktopSystemTest:test_DoubleClickIcon")

    def test_StartAppFromLMClick(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_StartAppFromLMClick")

        # click the applist
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)

        # get applist picture
        BaseImg = os.path.join(self.BaseImagePath, "applist_browser.jpg")
        name = "test_StartAppFromLMClick_%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime())
        img = os.path.join(self.TmpImagePath, name)
        self.d.screenshot(img)
        cropedImgPath = os.path.join(self.TmpImagePath, "croped", name.replace(".jpg", "_croped.jpg"))
        # (1292, 315) = 1920 - 120 * 5 - 18 - 10; 1080 - 136 * 5 - 18 - 25 - 42
        # (1892, 995) = 1920 - 18 - 10; 1080 - 18 - 25 - 42
        # region = array(5,5), with each 120 * 136
        CropImage(img, cropedImgPath, 1292, 315, 1892, 995)

        # find required image
        # compare pic rect of base image, it is 64*64 pix
        ret = FindImage(cropedImgPath, BaseImg, (28, 24, 92, 88), 50)
        if not ret:
            shutil.copy(cropedImgPath, os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")))
            path = os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg"))
            self.fail("The failure file path is %s" % path)
        else:
            # mouse left click the item
            self.mouse.click(1292 + ret[0], 315 + ret[1], constants.MouseLeftKey)

        # verify the item
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if BrowserWindow.exists:
                break
            else:
                time.sleep(1)
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            closeButton = self.d(
                resourceId="android:id/pc_close",
                className="android.widget.ImageView",
                packageName="org.chromium.chrome",
            )
            if closeButton.exists:
                logger.debug("click close button: (%s)" % (closeButton.info["packageName"]))
                closeButton.click()
        logger.info("Exit -- MUAT:DesktopSystemTest:test_StartAppFromLMClick")

    def test_StartAppFromRMClick(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_StartAppFromRMClick")

        # click the applist
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)

        # get applist picture
        BaseImg = os.path.join(self.BaseImagePath, "applist_browser.jpg")
        name = "test_StartAppFromRMClick_%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime())
        img = os.path.join(self.TmpImagePath, name)
        self.d.screenshot(img)
        cropedImgPath = os.path.join(self.TmpImagePath, "croped", name.replace(".jpg", "_croped.jpg"))
        # (1292, 315) = 1920 - 120 * 5 - 18 - 10; 1080 - 136 * 5 - 18 - 25 - 42
        # (1892, 995) = 1920 - 18 - 10; 1080 - 18 - 25 - 42
        # region = array(5,5), with each 120 * 136
        CropImage(img, cropedImgPath, 1292, 315, 1892, 995)

        # find required image
        # compare pic rect of base image, it is 64*64 pix
        ret = FindImage(cropedImgPath, BaseImg, (28, 24, 92, 88), 50)
        if not ret:
            shutil.copy(cropedImgPath, os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")))
            path = os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg"))
            self.fail("The failure file path is %s" % path)
        else:
            # mouse right click the item
            self.mouse.click(1292 + ret[0], 315 + ret[1], constants.MouseRightKey)
            time.sleep(1)
            # mouse left click start item
            self.mouse.click(1292 + ret[0] + 20, 315 + ret[1] + 20, constants.MouseLeftKey)

        # verify the item
        # time.sleep(2)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if BrowserWindow.exists:
                break
            else:
                time.sleep(1)
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            closeButton = self.d(
                resourceId="android:id/pc_close",
                className="android.widget.ImageView",
                packageName="org.chromium.chrome",
            )
            if closeButton.exists:
                logger.debug("click close button: (%s)" % (closeButton.info["packageName"]))
                closeButton.click()
        logger.info("Exit -- MUAT:DesktopSystemTest:test_StartAppFromRMClick")

    def test_AddAPPIconToDesktop(self):
        logger.info("Enter -- MUAT:DesktopSystemTest:test_AddAPPIconToDesktop")

        # remove the shortcut from Desktop first
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        if BrowserIcon.exists:
            BrowserIcon_bounds = BrowserIcon.info["bounds"]
            self.mouse.click(
                (BrowserIcon_bounds["left"] + BrowserIcon_bounds["right"]) / 2,
                (BrowserIcon_bounds["top"] + BrowserIcon_bounds["bottom"]) / 2,
                constants.MouseRightKey,
            )
            time.sleep(0.2)
            self.mouse.click(
                (BrowserIcon_bounds["left"] + BrowserIcon_bounds["right"]) / 2 + 50,
                (BrowserIcon_bounds["top"] + BrowserIcon_bounds["bottom"]) / 2 + 50,
                constants.MouseLeftKey,
            )
            time.sleep(0.2)
            deleteButton = self.d(text=u"删除", className="android.widget.Button")
            if deleteButton.exists:
                deleteButton.click()
                time.sleep(0.2)

        # click the applist
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)

        # get applist picture
        BaseImg = os.path.join(self.BaseImagePath, "applist_browser.jpg")
        name = "test_AddAPPIconToDesktop_%s.jpg" % time.strftime("%Y%m%d%H%M%S", time.localtime())
        img = os.path.join(self.TmpImagePath, name)
        self.d.screenshot(img)
        cropedImgPath = os.path.join(self.TmpImagePath, "croped", name.replace(".jpg", "_croped.jpg"))
        # (1292, 315) = 1920 - 120 * 5 - 18 - 10; 1080 - 136 * 5 - 18 - 25 - 42
        # (1892, 995) = 1920 - 18 - 10; 1080 - 18 - 25 - 42
        # region = array(5,5), with each 120 * 136
        CropImage(img, cropedImgPath, 1292, 315, 1892, 995)

        # find required image
        # compare pic rect of base image, it is 64*64 pix
        ret = FindImage(cropedImgPath, BaseImg, (28, 24, 92, 88), 50)
        if not ret:
            shutil.copy(cropedImgPath, os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")))
            path = os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg"))
            self.fail("The failure file path is %s" % path)
        else:
            # mouse click and move the item to desktop
            self.mouse.pressmove(1292 + ret[0], 315 + ret[1], 0, -315 - ret[1], constants.MouseLeftKey)
            time.sleep(0.2)

        # verify the item
        time.sleep(2)
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserIcon.exists)
        logger.info("Exit -- MUAT:DesktopSystemTest:test_APPAddShortcutToDesktop")
class MultiWindowsTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.adb_tools = AdbTools()
        self.mouse = AdbMouse()

#         self.account.sleep()
#         self.account.wakeup()
#         self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')
        Browser_Icon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        if not Browser_Icon.exists:
            self.d.click(57,10)
            time.sleep(2)
            self.d.click(68,141)
            start2=time.time()
            while time.time()-start2<constants.Time_Out:
                if  Button1.exists:
                    break
                else:
                    time.sleep(1)
            if self.mon and not self.mon.running_status:
                self.skipTest('process monitor stop')

            self.d      = AutomationDevice().get_device()
            self.account = Account(self.d)
            self.mouse = AdbMouse()
            self.adb_tools = AdbTools()
        

            self.account.wakeup()
            self.account.login()
            Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
            start=time.time()
            while time.time()-start<constants.Time_Out:
                if not Button1.exists:
                    break
                else:
                    time.sleep(1)
            #time.sleep(5)
            self.d.click(950,562)
            time.sleep(1)
            Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
            if Button1.exists:
                Button1.click()
            time.sleep(1)
            if not Browser_Icon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(Browser_Icon.exists)
        
        

    def tearDown(self):
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')

#     def test_DragWindow(self):
#         logger.info('Enter -- MUAT:MultiWindowsTest:test_DragWindow')
#       
#         BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
#         click_x = BrowserIcon.info['visibleBounds']['left'] +5
#         click_y = BrowserIcon.info['visibleBounds']['top'] +5
#         self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
#             
#         BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="com.android.browser")
#         self.assertTrue(BrowserWindow.exists)
#         if BrowserWindow.exists:
#             #BrowserWindow = self.d(text=u"浏览器", resourceId="android:id/pc_title", className="android.widget.TextView", packageName="com.android.browser")
#             LowerRightCoordinate_X = BrowserWindow.info['visibleBounds']['right'] - 1
#             LowerRightCoordinate_Y = BrowserWindow.info['visibleBounds']['bottom'] - 1
#             Target_X = LowerRightCoordinate_X + 100
#             Target_Y = LowerRightCoordinate_Y + 100
#                 
#             # drag
#             self.assertTrue(self.d.drag(LowerRightCoordinate_X, LowerRightCoordinate_Y, Target_X, Target_Y))
#             time.sleep(2)
#             # new coordinate
#             #EndBrowserWindow = self.d(text=u"浏览器", resourceId="android:id/pc_title", className="android.widget.TextView", packageName="com.android.browser")
#             EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="com.android.browser")
#             End_X = EndBrowserWindow.info['visibleBounds']['right'] -1 
#             End_Y = EndBrowserWindow.info['visibleBounds']['bottom'] -1
#     
#             # assert the math abs < 5 
#             self.assertTrue(abs(Target_X - End_X) < 5)
#             self.assertTrue(abs(Target_Y - End_Y) < 5)
#                 
#             self.assertTrue(self.d.drag(End_X, End_Y, LowerRightCoordinate_X, LowerRightCoordinate_Y))
#                             
#         logger.info('Exit -- MUAT:MultiWindowsTest:test_DragWindow')
          
          
    def test_ZoomInWindows(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_ZoomInWindows')
             
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
             
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            LowerRightCoordinate_X = BrowserWindow.info['visibleBounds']['right'] - 1
            LowerRightCoordinate_Y = BrowserWindow.info['visibleBounds']['bottom'] - 1
            Target_X = LowerRightCoordinate_X + 100
            Target_Y = LowerRightCoordinate_Y + 100
                 
            # drag
            self.assertTrue(self.d.drag(LowerRightCoordinate_X, LowerRightCoordinate_Y, Target_X, Target_Y))
            time.sleep(2)
            # new coordinate
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            End_X = EndBrowserWindow.info['visibleBounds']['right'] -1 
            End_Y = EndBrowserWindow.info['visibleBounds']['bottom'] -1
     
            # assert the math abs < 5 
            #self.assertTrue(abs(Target_X - End_X) < 5)
            #self.assertTrue(abs(Target_Y - End_Y) < 5)
                 
            self.assertTrue(self.d.drag(End_X, End_Y, LowerRightCoordinate_X, LowerRightCoordinate_Y))
        logger.info('Exit -- MUAT:MultiWindowsTest:test_ZoomInWindows')
                 
    def test_ZoomOutWindows(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_ZoomOutWindows')
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
             
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            LowerRightCoordinate_X = BrowserWindow.info['visibleBounds']['right'] - 1
            LowerRightCoordinate_Y = BrowserWindow.info['visibleBounds']['bottom'] - 1
            Target_X = LowerRightCoordinate_X - 100
            Target_Y = LowerRightCoordinate_Y - 100
                 
            # drag
            self.assertTrue(self.d.drag(LowerRightCoordinate_X, LowerRightCoordinate_Y, Target_X, Target_Y))
            time.sleep(2)
            # new coordinate
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            End_X = EndBrowserWindow.info['visibleBounds']['right'] -1 
            End_Y = EndBrowserWindow.info['visibleBounds']['bottom'] -1
     
            # assert the math abs < 5 
            #self.assertTrue(abs(Target_X - End_X) < 5)
            #self.assertTrue(abs(Target_Y - End_Y) < 5)
                  
            self.assertTrue(self.d.drag(End_X, End_Y, LowerRightCoordinate_X, LowerRightCoordinate_Y))
                                  
        logger.info('Exit -- MUAT:MultiWindowsTest:test_ZoomOutWindows')
          
    def test_ElongateWindow(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_ElongateWindow')
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
              
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            LowerRightCoordinate_X = BrowserWindow.info['visibleBounds']['right'] - 100
            LowerRightCoordinate_Y = BrowserWindow.info['visibleBounds']['bottom'] - 1
            Target_X = LowerRightCoordinate_X
            Target_Y = LowerRightCoordinate_Y + 100
      
            # drag
            self.assertTrue(self.d.drag(LowerRightCoordinate_X, LowerRightCoordinate_Y, Target_X, Target_Y))
      
            time.sleep(2)
      
            # new coordinate
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            End_X = EndBrowserWindow.info['visibleBounds']['right'] -1 
            End_Y = EndBrowserWindow.info['visibleBounds']['bottom'] -1
      
            # assert the math abs < 5 
            self.assertTrue(abs(Target_Y - End_Y) < 5)
                  
            self.assertTrue(self.d.drag(End_X-100, End_Y, LowerRightCoordinate_X, LowerRightCoordinate_Y))
        logger.info('Exit -- MUAT:MultiWindowsTest:test_ElongateWindow')                
                  
    def test_WidenWindow(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_WidenWindow')
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
              
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            LowerRightCoordinate_X = BrowserWindow.info['visibleBounds']['right'] - 1
            LowerRightCoordinate_Y = BrowserWindow.info['visibleBounds']['bottom'] - 100
            Target_X = LowerRightCoordinate_X + 100
            Target_Y = LowerRightCoordinate_Y
      
            # drag
            self.assertTrue(self.d.drag(LowerRightCoordinate_X, LowerRightCoordinate_Y, Target_X, Target_Y))
      
            time.sleep(2)
      
            # new coordinate
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            End_X = EndBrowserWindow.info['visibleBounds']['right'] -1 
            End_Y = EndBrowserWindow.info['visibleBounds']['bottom'] -1
      
            # assert the math abs < 5 
            self.assertTrue(abs(Target_X - End_X) < 5)
      
            self.assertTrue(self.d.drag(End_X, End_Y-100, LowerRightCoordinate_X, LowerRightCoordinate_Y))
                                  
        logger.info('Exit -- MUAT:MultiWindowsTest:test_WidenWindow')
      
    def test_F11ToFullScreen(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_F11ToFullScreen')
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
              
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            WindowTop = BrowserWindow.info['visibleBounds']['top']
            WindowLeft = BrowserWindow.info['visibleBounds']['left']
            WindowRight = BrowserWindow.info['visibleBounds']['right']
            WindowBottom = BrowserWindow.info['visibleBounds']['bottom']
                  
            # not full screen
            self.assertNotEqual(WindowTop, 0)
            self.assertNotEqual(WindowLeft, 0)
            self.assertNotEqual(WindowRight, 1920)
            self.assertNotEqual(WindowBottom, 1080)
                  
            # press F11 key
            self.assertTrue(self.d.press(0x8d))
      
            time.sleep(2)
      
            # new coordinate
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            NewWindowTop = EndBrowserWindow.info['visibleBounds']['top']
            NewWindowLeft = EndBrowserWindow.info['visibleBounds']['left']
            NewWindowRight = EndBrowserWindow.info['visibleBounds']['right']
            NewWindowBottom = EndBrowserWindow.info['visibleBounds']['bottom']
                  
            # full screen
            self.assertEqual(NewWindowTop, 0)
            self.assertEqual(NewWindowLeft, 0)
            self.assertEqual(NewWindowRight, 1920)
            self.assertEqual(NewWindowBottom, 1080)
            if not self.d.press(0x8d):
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(self.d.press(0x8d))
                  
        logger.info('Exit -- MUAT:MultiWindowsTest:test_F11ToFullScreen')
             
             
    def test_maximization(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_maximization')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
            
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            oldWindowTop = BrowserWindow.info['visibleBounds']['top']
            oldWindowLeft = BrowserWindow.info['visibleBounds']['left']
            oldWindowLeft1 = BrowserWindow.info['visibleBounds']['left']
            oldWindowRight = BrowserWindow.info['visibleBounds']['right']
            oldWindowRight1 = BrowserWindow.info['visibleBounds']['right']
            oldWindowBottom = BrowserWindow.info['visibleBounds']['bottom']
                
            # not maximization
            self.assertNotEqual(oldWindowTop, 0)
            self.assertNotEqual(oldWindowLeft, 0)
            self.assertNotEqual(oldWindowRight, 1920)
            self.assertNotEqual(oldWindowBottom, 1080)
                
            # maxmiun the window
            max_button = self.d(packageName="org.chromium.chrome", resourceId='android:id/pc_max')
            if max_button.exists:
                max_button.click()
                start=time.time()
                while time.time()-start<constants.Time_Out:
                    if oldWindowLeft1==0 and oldWindowRight1==1920:
                        break
                    else:
                        time.sleep(1)
                        oldWindowLeft1 = BrowserWindow.info['visibleBounds']['left']
                        oldWindowRight1 = BrowserWindow.info['visibleBounds']['right']
    
            # new coordinate
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            NewWindowTop = EndBrowserWindow.info['visibleBounds']['top']
            NewWindowLeft = EndBrowserWindow.info['visibleBounds']['left']
            NewWindowRight = EndBrowserWindow.info['visibleBounds']['right']
            NewWindowBottom = EndBrowserWindow.info['visibleBounds']['bottom']
                
            # full screen
            # the topbar height 22px
            # the taskbar height 42px (1080-42=1038) 
            self.assertTrue(abs(NewWindowTop - 18) < 5)
            self.assertEqual(NewWindowLeft, 0)
            self.assertEqual(NewWindowRight, 1920)
            self.assertTrue(abs(NewWindowBottom- 1048) < 5)
                
            # reclick the max button
            if max_button.exists:
                max_button.click()
                start=time.time()
                while time.time()-start<constants.Time_Out:
                    if not NewWindowLeft==0:
                        break
                    else:
                        time.sleep(1)
                        NewWindowLeft = EndBrowserWindow.info['visibleBounds']['left']
                        
            # restore the window
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            NewWindowTop = EndBrowserWindow.info['visibleBounds']['top']
            NewWindowLeft = EndBrowserWindow.info['visibleBounds']['left']
            NewWindowRight = EndBrowserWindow.info['visibleBounds']['right']
            NewWindowBottom = EndBrowserWindow.info['visibleBounds']['bottom']
            self.assertEqual(NewWindowTop, oldWindowTop)
            self.assertEqual(NewWindowLeft, oldWindowLeft)
            self.assertEqual(NewWindowRight, oldWindowRight)
            self.assertEqual(NewWindowBottom, oldWindowBottom)
                            
        logger.info('Exit -- MUAT:MultiWindowsTest:test_maximization')
            
    def test_minimization(self):
        logger.info('Enter -- MUAT:MultiWindowsTest:test_minimization')
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
           
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            oldWindowTop = BrowserWindow.info['visibleBounds']['top']
            oldWindowLeft = BrowserWindow.info['visibleBounds']['left']
            oldWindowRight = BrowserWindow.info['visibleBounds']['right']
            oldWindowBottom = BrowserWindow.info['visibleBounds']['bottom']
               
            # not maximization
            self.assertNotEqual(oldWindowTop, 0)
            self.assertNotEqual(oldWindowLeft, 0)
            self.assertNotEqual(oldWindowRight, 1920)
            self.assertNotEqual(oldWindowBottom, 1080)
               
            # hide the window
            hide_button = self.d(packageName="org.chromium.chrome", resourceId='android:id/pc_hide')
            if hide_button.exists:
                hide_button.click()
                start=time.time()
                while time.time()-start<constants.Time_Out:
                    if not hide_button.exists:
                        break
                    else:
                        time.sleep(1)
   
            # check hide window
            if self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertFalse(self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists)
                                               
            # click the browser in the taskbar
            self.mouse.click(100, 1080-25, constants.MouseLeftKey)
            start=time.time()
            while time.time()-start<constants.Time_Out:
                if  hide_button.exists:
                    break
                else:
                    time.sleep(1)
   
            # restore the window
            EndBrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
            NewWindowTop = EndBrowserWindow.info['visibleBounds']['top']
            NewWindowLeft = EndBrowserWindow.info['visibleBounds']['left']
            NewWindowRight = EndBrowserWindow.info['visibleBounds']['right']
            NewWindowBottom = EndBrowserWindow.info['visibleBounds']['bottom']
            self.assertEqual(NewWindowTop, oldWindowTop)
            self.assertEqual(NewWindowLeft, oldWindowLeft)
            self.assertEqual(NewWindowRight, oldWindowRight)
            self.assertEqual(NewWindowBottom, oldWindowBottom)
                                      
        logger.info('Exit -- MUAT:MultiWindowsTest:test_minimization')
class CunTaoTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor refresh_button')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()
        
        self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
        self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
        self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
        
        if not os.path.exists(self.TmpImagePath):
            os.mkdir(self.TmpImagePath)
        if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
            os.mkdir(os.path.join(self.TmpImagePath, "croped"))

#         self.account.sleep()
#         self.account.wakeup()
#         self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start1=time.time()
        while time.time()-start1<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        #time.sleep(5)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        #self.adb_tools.adb_shell('am force-refresh_button org.chromium.chrome')
        #time.sleep(3)
       
        Browser_Icon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        if not Browser_Icon.exists:
            pass
            #self.adb_tools.adb_shell('adb shell am force-stop com.kingsoft.moffice_pro')
            #注销登陆
#             self.d.click(57,10)
#             time.sleep(1)
#             self.d.click(68,141)
#             start2=time.time()
#             while time.time()-start2<constants.Time_Out:
#                 if  Button1.exists:
#                     break
#                 else:
#                     time.sleep(1)
#             if self.mon and not self.mon.running_status:
#                 self.skipTest('process monitor refresh_button')
# 
#             self.d      = AutomationDevice().get_device()
#             self.account = Account(self.d)
#             self.mouse = AdbMouse()
#             self.adb_tools = AdbTools()
#         
#             self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
#             self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
#             self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
#         
#             if not os.path.exists(self.TmpImagePath):
#                 os.mkdir(self.TmpImagePath)
#             if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
#                 os.mkdir(os.path.join(self.TmpImagePath, "croped"))
# 
#             self.account.wakeup()
#             self.account.login()
#             Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
#             start=time.time()
#             while time.time()-start<constants.Time_Out:
#                 if not Button1.exists:
#                     break
#                 else:
#                     time.sleep(1)
#             self.d.click(950,562)
#             #time.sleep(2)
#             Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
#             if Button1.exists:
#                 Button1.click()
#             time.sleep(1)
            if not Browser_Icon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(Browser_Icon.exists)

    def tearDown(self):
        Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if Button1.exists:
            Button1.click()
            self.adb_tools.adb_shell('am start -n org.chromium.chrome/.browser.ChromeTabbedActivity')
            start=time.time()
            while time.time()-start <  constants.Time_Out:
                if closeButton.exists:
                    break
                else:
                    time.sleep(1)
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(1)
        if closeButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertFalse(closeButton.exists)
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')    
        time.sleep(1)
        
    def test_Login(self):
        logger.info('Enter -- MUAT:CuntaoTest:test_login')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        refresh_buttonButton=self.d(description=u'停止网页加载',resourceId='org.chromium.chrome:id/refresh_button')
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            maxButton = self.d(resourceId="android:id/pc_max", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if maxButton.exists:
                logger.debug('click max button: (%s)' % (maxButton.info['packageName']))
                maxButton.click()
#             blankpage = self.d(resourceId="org.chromium.chrome:id/title")
#             if blankpage.exists:
#                 self.assertEqual(blankpage.info['text'], u"搜索或输入网址")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("cun.taobao.com")
                self.d.press(0x42)
                #sleep
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not refresh_buttonButton.exists:
                        break
                    else:
                        time.sleep(1)
                time.sleep(5)
                #关闭广告
                self.d.click(1545,182)
                time.sleep(5)
                #点击请登陆
                self.d.click(409,177)
                #sleep
                time.sleep(20)
                self.d.press(61)
#                 self.d.press(113,1)
                time.sleep(0.5)
                self.d.press(48)
                self.d.press(33)
                self.d.press(47)
                self.d.press(48)
                self.d.press(33)
                self.d.press(46)
                self.d.press(69,1)
                self.d.press(8)
                self.d.press(61)
#                 self.d.press(113,1)
                time.sleep(0.5)
                self.d.press(48)
                self.d.press(33)
                self.d.press(47)
                self.d.press(48)
                self.d.press(8)
                self.d.press(9)
                self.d.press(10)
                self.d.press(11)
                self.d.press(66)
                #sleep
                time.sleep(25)
                self.d.click(425,180)
                time.sleep(3)
                self.d.click(393,251)
                time.sleep(5)
                  
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:CuntaoTest:test_login')
  		 
    def test_Shopping(self):
        logger.info('Enter -- MUAT:CuntaoTest:test_Shopping')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        refresh_buttonButton=self.d(description=u'停止网页加载',resourceId='org.chromium.chrome:id/refresh_button')
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            maxButton = self.d(resourceId="android:id/pc_max", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if maxButton.exists:
                logger.debug('click max button: (%s)' % (maxButton.info['packageName']))
                maxButton.click()
#             blankpage = self.d(resourceId="org.chromium.chrome:id/title")
#             if blankpage.exists:
#                 self.assertEqual(blankpage.info['text'], u"搜索或输入网址")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            #addButton = self.d(resourceId="org.chromium.chrome:id/newtab")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("cun.taobao.com")
                self.d.press(0x42)
                #sleep
                time.sleep(20)
                self.d.click(1545,182)
                time.sleep(5)
                self.d.click(409,177)
                #sleep
                time.sleep(20)
                self.d.press(61)
#                 self.d.press(113,1)
                time.sleep(0.5)
                self.d.press(48)
                self.d.press(33)
                self.d.press(47)
                self.d.press(48)
                self.d.press(33)
                self.d.press(46)
                self.d.press(69,1)
                self.d.press(8)
                self.d.press(61)
#                 self.d.press(113,1)
                time.sleep(0.5)
                self.d.press(48)
                self.d.press(33)
                self.d.press(47)
                self.d.press(48)
                self.d.press(8)
                self.d.press(9)
                self.d.press(10)
                self.d.press(11)
                self.d.press(66)
                #sleep
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not refresh_buttonButton.exists:
                        break
                    else:
                        time.sleep(1)
                #通过输入网址找耳机
                #addButton.click()
                address.clear_text()
                address.set_text("https://detail.tmall.com/item.htm?id=18936252543&ali_trackid=2:mm_33231723_0_0:1437708324_2k3_1993164502&spm=5759.1411664.1111.4.xBX2i5&skuId=63591272480")
                self.d.press(0x42)
                #sleep
                time.sleep(20)
                self.d.click(1172,985)
                time.sleep(10)
                self.d.click(1209,176)
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not refresh_buttonButton.exists:
                        break
                    else:
                        time.sleep(1)
                self.d.click(384,361)
                time.sleep(5)
                self.d.click(454,587)
                time.sleep(5)
                self.d.click(832,633)
                time.sleep(5)
                self.d.click(470,182)
                time.sleep(5) 
                self.d.click(678,219)
                time.sleep(5)
                  
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:CuntaoTest:test_Shopping')   
 							
 
    def test_AddAddress(self):
        logger.info('Enter -- MUAT:CuntaoTest:test_AddAddress')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        refresh_buttonButton=self.d(description=u'停止网页加载',resourceId='org.chromium.chrome:id/refresh_button')
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            maxButton = self.d(resourceId="android:id/pc_max", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if maxButton.exists:
                logger.debug('click max button: (%s)' % (maxButton.info['packageName']))
                maxButton.click()
#             blankpage = self.d(resourceId="org.chromium.chrome:id/title")
#             if blankpage.exists:
#                 self.assertEqual(blankpage.info['text'], u"搜索或输入网址")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("cun.taobao.com")
                self.d.press(0x42)
                #sleep
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not refresh_buttonButton.exists:
                        break
                    else:
                        time.sleep(1)
                time.sleep(5)
                #关闭广告
                self.d.click(1545,182)
                time.sleep(5)
                #点击请登陆
                self.d.click(409,177)
                #sleep
                time.sleep(20)
                self.d.press(61)
#                 self.d.press(113,1)
                time.sleep(0.5)
                self.d.press(48)
                self.d.press(33)
                self.d.press(47)
                self.d.press(48)
                self.d.press(33)
                self.d.press(46)
                self.d.press(69,1)
                self.d.press(8)
                self.d.press(61)
#                 self.d.press(113,1)
                time.sleep(0.5)
                self.d.press(48)
                self.d.press(33)
                self.d.press(47)
                self.d.press(48)
                self.d.press(8)
                self.d.press(9)
                self.d.press(10)
                self.d.press(11)
                self.d.press(66)
                #sleep
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not refresh_buttonButton.exists:
                        break
                    else:
                        time.sleep(1)
                time.sleep(5)
                self.d.click(1545,182)
                time.sleep(5)
                self.d.click(413,177)
                time.sleep(2)
                self.d.click(392,221)
                time.sleep(15)
                #点击收货地址
                self.d.click(512,656)
                time.sleep(10)
                self.d.click(921,384)
                time.sleep(2)
                self.d.click(882,454)
                time.sleep(2)
                self.d.click(882,454)
                time.sleep(2)
                self.d.click(882,454)
                time.sleep(2)
                self.d.click(882,454)
                time.sleep(2)
                self.d.click(882,454)
                self.d.press(35)
                time.sleep(1)
                button1=self.d(text=u'继续',resourceId='android:id/button1',packageName='org.chromium.chrome')
                if button1.exists:
                    button1.click()
                self.d.press(61)
                self.d.press(35)
                self.d.press(35)
                self.d.press(35)
                self.d.press(35)
                self.d.press(61)
                self.d.press(8)
                self.d.press(61)
                self.d.press(35)
                self.d.press(35)
                self.d.press(61)
                self.d.press(61)
                self.d.press(8)
                self.d.press(8)
                self.d.press(8)
                self.d.press(8)
                self.d.press(8)
                self.d.press(8)
                self.d.press(66)
                time.sleep(5)
                self.d.click(1280,825)    
                time.sleep(3)
                self.d.click(886,644)
                time.sleep(5)
                #登出
                self.d.click(573,180)
                time.sleep(2) 
                self.d.click(781,219)
                time.sleep(3)
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:CunTaoTest:test_AddAddress')
        
    def test_Search(self):
        logger.info('Enter -- MUAT:CuntaoTest:test_Search')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        refresh_buttonButton=self.d(description=u'停止网页加载',resourceId='org.chromium.chrome:id/refresh_button')
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            maxButton = self.d(resourceId="android:id/pc_max", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if maxButton.exists:
                logger.debug('click max button: (%s)' % (maxButton.info['packageName']))
                maxButton.click()
#             blankpage = self.d(resourceId="org.chromium.chrome:id/title")
#             if blankpage.exists:
#                 self.assertEqual(blankpage.info['text'], u"搜索或输入网址")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("cun.taobao.com")
                self.d.press(0x42)
                time.sleep(20)
                #关闭广告
                self.d.click(1545,182)
                time.sleep(5)
                self.d.click(731,246)
                self.d.press(29)
                self.d.press(32)
                self.d.press(37)
                self.d.press(32)
                self.d.press(29)
                self.d.press(47)
                self.d.press(66)
                time.sleep(15)
                 
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
                self.assertFalse(closeButton.exists)
        logger.info('Exit -- MUAT:CunTaoTest:test_Search')
                
class StressVdiTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.adb_tools = AdbTools()
        self.mouse = AdbMouse()

        self.account.sleep()
        self.account.wakeup()
        self.account.login()
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.yunos.acdp")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()

    def tearDown(self):
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.yunos.acdp")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        self.account.sleep()

    def test_LoginWin7(self):
        logger.info('Enter -- MUAT:StressVdiTest:test_LoginWin7')
   
        # open yunpc application
        YunPCIcon = self.d(text=u"云PC", className="android.widget.TextView")
        click_x = YunPCIcon.info['visibleBounds']['left'] +5
        click_y = YunPCIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        logger.info('StressVdiTest:test_LoginWin7: open yunpc application')
        time.sleep(2)
         
        YunPCWindow = self.d(className="android.widget.FrameLayout", packageName="com.yunos.acdp")
        self.assertTrue(YunPCWindow.exists)
        
        for cnt in range(2):
            if YunPCWindow.exists:
                # click the bg image enter Win7 login page
                VMWindow= self.d(resourceId="com.yunos.acdp:id/yunpc_bg", className="android.widget.LinearLayout", packageName="com.yunos.acdp")
                click_x= (VMWindow.info['visibleBounds']['left'] + VMWindow.info['visibleBounds']['right']) / 2
                click_y= (VMWindow.info['visibleBounds']['top'] + VMWindow.info['visibleBounds']['bottom']) / 2
                self.mouse.click(click_x, click_y, constants.MouseLeftKey)
                time.sleep(4)
                 
#                 # login Win7
#                 CanvasPage= self.d(resourceId="com.yunos.acdp:id/vnc_canvas", className="android.view.View", packageName="com.yunos.acdp")
#                 # enter passws
#                 CanvasPage.set_text(constants.TEST_PASSWD)
#                 time.sleep(1)
                
    
#                 # click login, enter button offset (930, 560)
#                 click_x= CanvasPage.info['visibleBounds']['left'] + 930
#                 click_y= CanvasPage.info['visibleBounds']['top'] + 560
#                 self.mouse.click(click_x, click_y, constants.MouseLeftKey)
#                 time.sleep(4)
                # screenshot for check
                name = '%s-%s.png' % (time.strftime('%Y%m%d%H%M%S', time.localtime()), cnt)
                logger.info('StressVdiTest:test_LoginWin7: screen shot name: (%s)' % (name))
                self.d.screenshot('%s-%s.png' % (time.strftime('%Y%m%d%H%M%S', time.localtime()), cnt))
                
                self.d.press(0x84, 0x1000|0x02)
                time.sleep(1)

        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.yunos.acdp")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()

        logger.info('Exit -- MUAT:StressVdiTest:test_LoginWin7')
class YouKuTest(ParametrizedTestCase):

    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()

        self.account.sleep()
        self.account.wakeup()
        self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.youku.phone")
        #self.assertTure(closeButton.exists)
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(1)
        else:
            #logger.info("error---------->No closeButton")
            pass

        self.adb_tools.adb_shell("am force-stop com.youku.phone")
        time.sleep(1)


    def test_OpenAndExit(self):

        logger.info('Enter -- MUAT:YoukuTest:test_OpenAndExit')
        self.adb_tools.adb_shell("am start -n com.youku.phone/.ActivityWelcome")
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(resourceId='android:id/pc_titlebar',packageName='com.youku.phone').exists:
                break
            else:
                time.sleep(1)
        #如果弹出安全提示对话框则点击同意
        # agree_btn = self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", PackageName="com.youku.phone")
        # self.assertEqual(agree_btn.info['text'], u'同意')
        if self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", packageName="com.youku.phone").exists:
            self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", packageName="com.youku.phone").click()
            time.sleep(3)
        else:
            pass
        #click 我的
        myyouku = self.d(resourceId="com.youku.phone:id/text_myyouku", className="android.widget.TextView", packageName="com.youku.phone")
        if not myyouku.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertEqual(myyouku.info['text'], u'我的')
        if myyouku.exists:
            myyouku.click()
            time.sleep(1)
        #click 首页
        youkutitle = self.d(resourceId="com.youku.phone:id/text_youkutitle", className="android.widget.TextView")
        self.assertEqual(youkutitle.info['text'], u'首页')
        if youkutitle.exists:
            youkutitle.click()
            time.sleep(1)
        #click 订阅
        youkuguess = self.d(resourceId="com.youku.phone:id/text_youkuguess")
        self.assertEqual(youkuguess.info['text'], u'订阅')
        if youkuguess.exists:
            youkuguess.click()
            time.sleep(1)
        #click 频道
        userlike = self.d(resourceId="com.youku.phone:id/text_userlike")
        self.assertEqual(userlike.info['text'], u'频道')
        if userlike.exists:
            userlike.click()
            time.sleep(1)
        #exit youku app
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.youku.phone")
        #self.assertTure(closeButton.exists)
        if closeButton.exists:
            #logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(2)
        else:
            #logger.info("error---------->No closeButton")
            pass


        logger.info('Exit -- MUAT:YoukuTest:test_OpenAndExit')

    def test_PlayAndPause(self):

        logger.info('Enter -- MUAT:YoukuTest:test_PlayAndPause')

        self.adb_tools.adb_shell("am start -n com.youku.phone/.ActivityWelcome")
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(resourceId='android:id/pc_titlebar',packageName='com.youku.phone').exists:
                break
            else:
                time.sleep(1)
        #如果弹出安全提示对话框则点击同意
        # agree_btn = self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", PackageName="com.youku.phone")
        # self.assertEqual(agree_btn.info['text'], u'同意')
        if self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", packageName="com.youku.phone").exists:
            self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", packageName="com.youku.phone").click()
            time.sleep(3)
        else:
            pass

        #click 我的
        myyouku = self.d(resourceId="com.youku.phone:id/text_myyouku", className="android.widget.TextView", packageName="com.youku.phone")
        self.assertEqual(myyouku.info['text'], u'我的')
        if myyouku.exists:
            myyouku.click()
            time.sleep(1)
        #click 首页
        youkutitle = self.d(resourceId="com.youku.phone:id/text_youkutitle", className="android.widget.TextView")
        self.assertEqual(youkutitle.info['text'], u'首页')
        if youkutitle.exists:
            youkutitle.click()
            time.sleep(1)

        #点击首页左侧的视频,进入视频播放界面
        text_youkutitle = self.d(resourceId="com.youku.phone:id/text_youkutitle", className="android.widget.TextView")
        self.assertEqual(text_youkutitle.info['selected'], True)
        if text_youkutitle.exists:
            text_youkutitle.click()
            time.sleep(1)

        video = self.d(resourceId="com.youku.phone:id/home_gallery_item_img", className="android.widget.ImageView")
        if not video.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(video.exists)
        if video.exists:
            video.click()
            #视频播放1分钟
            time.sleep(60)
        #调出暂停按钮,点击按钮使食品暂停
        left_border = self.d(resourceId='android:id/left_border', className='android.widget.ImageView')
        if not left_border.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(left_border.exists)
        if left_border.exists:
            pause_btn_x = left_border.info['visibleBounds']['right'] + 60
            pause_btn_y = left_border.info['visibleBounds']['bottom'] - 60
            time.sleep(2)
            self.mouse.doubleclick(pause_btn_x, pause_btn_y, constants.MouseLeftKey)
            time.sleep(15)
            self.mouse.doubleclick(pause_btn_x, pause_btn_y, constants.MouseLeftKey)




        logger.info('Exit -- MUAT:YoukuTest:test_PlayAndPause')

    def test_FastForwardAndRewind(self):
        logger.info('Enter -- MUAT:YoukuTest:test_FastForwardAndRewind')
        self.adb_tools.adb_shell("am start -n com.youku.phone/.ActivityWelcome")
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(resourceId='android:id/pc_titlebar',packageName='com.youku.phone').exists:
                break
            else:
                time.sleep(1)
        #如果弹出安全提示对话框则点击同意
        # agree_btn = self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", PackageName="com.youku.phone")
        # self.assertEqual(agree_btn.info['text'], u'同意')
        if self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", packageName="com.youku.phone").exists:
            self.d(resourceId="com.youku.phone:id/app_agreement_done_textview", className="android.widget.TextView", packageName="com.youku.phone").click()
            time.sleep(3)
        else:
            pass

        #click 我的
        myyouku = self.d(resourceId="com.youku.phone:id/text_myyouku", className="android.widget.TextView", packageName="com.youku.phone")
        self.assertEqual(myyouku.info['text'], u'我的')
        if myyouku.exists:
            myyouku.click()
            time.sleep(1)
        #click 首页
        youkutitle = self.d(resourceId="com.youku.phone:id/text_youkutitle", className="android.widget.TextView")
        self.assertEqual(youkutitle.info['text'], u'首页')
        if youkutitle.exists:
            youkutitle.click()
            time.sleep(1)

        #点击首页左侧的视频,进入视频播放界面
        text_youkutitle = self.d(resourceId="com.youku.phone:id/text_youkutitle", className="android.widget.TextView")
        self.assertEqual(text_youkutitle.info['selected'], True)
        if text_youkutitle.exists:
            text_youkutitle.click()
            time.sleep(1)

        video = self.d(resourceId="com.youku.phone:id/home_gallery_item_img", className="android.widget.ImageView")
        if not video.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(video.exists)
        if video.exists:
            video.click()
            #视频播放1分钟
            time.sleep(15)

        left_border = self.d(resourceId="android:id/left_border", className="android.widget.ImageView")
        Sx = left_border.info['visibleBounds']['right'] + 200
        Sy = (left_border.info['visibleBounds']['top'] + left_border.info['visibleBounds']['bottom'])/2
        Ex = Sx + 400
        Ey = Sy

        self.d.swipe(Sx, Sy, Ex, Ey, steps=10)

        time.sleep(10)
        self.d.swipe(Ex, Ey, Sx, Sy, steps=10)
        time.sleep(10)

        logger.info('Exit -- MUAT:YoukuTest:test_FastForwardAndRewind')
    def tearDown(self):

        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.youku.phone")
        #self.assertTure(closeButton.exists)
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(2)
        else:
            #logger.info("error---------->No closeButton")
            pass
        self.adb_tools.adb_shell("am force-stop com.youku.phone")
class BrowserProTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()
        
        self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
        self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
        self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
        
        if not os.path.exists(self.TmpImagePath):
            os.mkdir(self.TmpImagePath)
        if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
            os.mkdir(os.path.join(self.TmpImagePath, "croped"))

        self.account.sleep()
        self.account.wakeup()
        self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')
        #time.sleep(3)
        
        Browser_Icon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        if not Browser_Icon.exists:
#             self.d.click(57,10)
#             time.sleep(1)
#             self.d.click(68,141)
#             start=time.time()
#             while time.time()-start<constants.Time_Out:
#                 if  Button1.exists:
#                     break
#                 else:
#                     time.sleep(1)

            if self.mon and not self.mon.running_status:
                self.skipTest('process monitor stop')

            self.d      = AutomationDevice().get_device()
            self.account = Account(self.d)
            self.mouse = AdbMouse()
            self.adb_tools = AdbTools()
        
            self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
            self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
            self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
        
            if not os.path.exists(self.TmpImagePath):
                os.mkdir(self.TmpImagePath)
            if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
                os.mkdir(os.path.join(self.TmpImagePath, "croped"))

            self.account.wakeup()
            self.account.login()
            Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
            start=time.time()
            while time.time()-start<constants.Time_Out:
                if not Button1.exists:
                    break
                else:
                    time.sleep(1)
            #time.sleep(5)
            self.d.click(950,562)
            time.sleep(1)
            Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
            if Button1.exists:
                Button1.click()
            time.sleep(1)
            if not Browser_Icon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(Browser_Icon.exists)

    def tearDown(self):
        Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
        if Button1.exists:
            Button1.click()
            self.adb_tools.adb_shell('am start -n org.chromium.chrome/.browser.ChromeTabbedActivity')
            start=time.time()
            while time.time()-start<constants.Time_Out:
                if  self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome").exists:
                    break
                else:
                    time.sleep(1)
        
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(1)
        if closeButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertFalse(closeButton.exists)
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')
        if os.path.exists(self.TmpImagePath):
            shutil.rmtree(self.TmpImagePath)
            
    def test_CostTime(self):
        logger.info('Enter -- MUAT:BrowserTest:test_CostTime')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            maxButton = self.d(resourceId="android:id/pc_max", className="android.widget.ImageView", packageName="org.chromium.chrome")
            logger.debug('click max button: (%s)' % (maxButton.info['packageName']))
            maxButton.click()
            blankpage = self.d(resourceId="org.chromium.chrome:id/ntp_scrollview")
            if blankpage.exists:
                self.assertEqual(blankpage.info['contentDescription'], u"打开新的标签页")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
#                 address.clear_text()
#                 address.set_text("www.taobao.com")
#                 self.d.press(0x42)
                MenuButton=self.d(resourceId='org.chromium.chrome:id/menu_button',packageName='org.chromium.chrome')
                if MenuButton.exists:
                    MenuButton.click()
                    time.sleep(1)
                    self.d(resourceId='org.chromium.chrome:id/menu_item_text',packageName='org.chromium.chrome').click()
                    BookMark=self.d(resourceId='org.chromium.chrome:id/highlight')
                    if BookMark.exists:
                        BookMark.click()
                        time.sleep(1)
                StopButton=self.d(description=u'停止加载网页',resourceId='org.chromium.chrome:id/refresh_button')
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not StopButton.exists:
                        break
                    else:
                        time.sleep(0.5)
                logger.info( time.time()-start)
                 
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_CostTime')
         
        
    def test_Fps(self):
        logger.info('Enter -- MUAT:BrowserTest:test_Fps')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            maxButton = self.d(resourceId="android:id/pc_max", className="android.widget.ImageView", packageName="org.chromium.chrome")
            logger.debug('click max button: (%s)' % (maxButton.info['packageName']))
            maxButton.click()
            blankpage = self.d(resourceId="org.chromium.chrome:id/ntp_scrollview")
            if blankpage.exists:
                self.assertEqual(blankpage.info['contentDescription'], u"打开新的标签页")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                MenuButton=self.d(resourceId='org.chromium.chrome:id/menu_button',packageName='org.chromium.chrome')
                if MenuButton.exists:
                    MenuButton.click()
                    time.sleep(1)
                    self.d(resourceId='org.chromium.chrome:id/menu_item_text',packageName='org.chromium.chrome').click()
                    BookMark=self.d(resourceId='org.chromium.chrome:id/highlight')
                    if BookMark.exists:
                        BookMark.click()
                        time.sleep(1)
                StopButton=self.d(description=u'停止加载网页',resourceId='org.chromium.chrome:id/refresh_button')
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not StopButton.exists:
                        break
                    else:
                        time.sleep(0.5)
                detect_re = re.compile(r'D.UIAutomatorStub.*swipe')
                wanted_re = re.compile(r'MPT: sf post one frame at (.*)$')
                adb_log = AdbLog(mode=AdbLog.MODE_RE | AdbLog.MODE_NEED_DETECT | AdbLog.MODE_NEED_CONTINUE, wanted_re=wanted_re, detect_re=detect_re, logger=logger)
                adb_log.clear()
                adb_log.start()
                self.d.swipe(200,900,200,500)
                 
                self.mouse.wheel(860,500,constants.MouseWheelDown,70,5)
                self.mouse.wheel(860,500,constants.MouseWheelUp,60,5)
                # check the log and get the data
                while True:
                    if adb_log.result and len(adb_log.result) >= 3:
                        break
                    else:
                        time.sleep(1)
                adb_log.stop_log()
                adb_log.join()
 
                # store the result
                start_time = 0
                end_time = 0
                fps = 0
                try:
                    length = len(adb_log.result)
                    if length >=3:
                        start_time      = int(adb_log.result[1][0])
                        end_time        = int(adb_log.result[-1][0])
                        fps             = (length - 1) * 1000 / (end_time - start_time)
                    else:
                        logger.error('not enough data for calc fps: (%s)' % (adb_log.result))
                except:
                    logger.error('retrieve time from (%s) error' % (adb_log.result))
 
                logger.info('wheel taobao page fps: %s' % ( fps))
#                 baiduPage = self.d(className="android.webkit.WebView", packageName="org.chromium.chrome")
#                 if baiduPage.exists:
#                     self.assertEqual(baiduPage.info['contentDescription'], u'百度一下,你就知道')
                                
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_Fps')
        
    def test_Open16Tab(self):
        logger.info('Enter -- MUAT:ChromeTest:test_Open16Tab')
        
        #open chrome
        self.adb_tools.adb_shell("am start -n org.chromium.chrome/com.google.android.apps.chrome.Main")
        time.sleep(3)
        pc_max = self.d(resourceId='android:id/pc_max', className='android.widget.ImageView', packageName='org.chromium.chrome')
        pc_max.click()
        time.sleep(2)
        menuButton=self.d(resourceId='org.chromium.chrome:id/menu_button',packageName='org.chromium.chrome')
        menuButton.click()
        records=self.d(text=u"历史记录",packageName='org.chromium.chrome')
        records.click()
       
        for i in range(16):
            self.mouse.click(830,430,constants.MouseRightKey)
            self.mouse.click(890,460,constants.MouseLeftKey)
            time.sleep(1)
        str ='after open chrome 16 tab...\n' 
        getcpuinfo(str)
        #close chrome
        closebtn = self.d(resourceId='android:id/pc_close', className='android.widget.ImageView', packageName='org.chromium.chrome')
        closebtn.click()

        logger.info('Exit -- MUAT:ChromeTest:test_OpenChromeTab')
        
    def test_LanchTask(self):
        logger.info('Enter -- MUAT:ChromeTest:test_LanchTask')
        serial_number = None
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
        #open chrome
        self.adb_tools.adb_shell("am start -n org.chromium.chrome/com.google.android.apps.chrome.Main")
        time.sleep(3)
        pc_max = self.d(resourceId='android:id/pc_max', className='android.widget.ImageView', packageName='org.chromium.chrome')
        self.assertTrue(pc_max.exists)
        pc_max.click()
        time.sleep(2)
        menuButton=self.d(resourceId='org.chromium.chrome:id/menu_button',packageName='org.chromium.chrome')
        menuButton.click()
        records=self.d(text=u"历史记录",packageName='org.chromium.chrome')
        records.click()
       
        for i in range(16):
            self.mouse.click(830,430,constants.MouseRightKey)
            self.mouse.click(890,460,constants.MouseLeftKey)
            time.sleep(1)
        str ='lanch taskmgr after open chrome 16 tab...\n' 
        getcpuinfo(str)
            
        wanted_re = re.compile(r'I.ActivityManager.*com.aliyun.mpc.taskmgr.*\+(.*)ms' )
        adb_log = AdbLog(mode=AdbLog.MODE_RE, wanted_re=wanted_re, logger=logger, serial_number=serial_number)
        adb_log.clear()
        adb_log.start()

        # start apk
        self.adb_tools.adb_shell('am start -n  com.aliyun.mpc.taskmgr/.TaskMgr')
        
        # check the log and get the data
        while True:
            if adb_log.result:
                break
            else:
                time.sleep(1)
        # store the result
        cost_time = 0
        try:
            if 's' in adb_log.result[0][0]:
                composit = adb_log.result[0][0].split('s')
                cost_time = int(composit[0]) * 1000 + int(composit[1])
            else:
                cost_time = int(adb_log.result[0][0])
        except:
            logger.error('retrieve cost time from (%s) error' % (adb_log.result))
        
        logger.info('start TaskMgr cost: %s' % (cost_time))
        # close apk
        self.adb_tools.adb_shell('am force-stop com.aliyun.mpc.taskmgr')
        #close chrome
        closebtn = self.d(resourceId='android:id/pc_close', className='android.widget.ImageView', packageName='org.chromium.chrome')
        closebtn.click()

        logger.info('Exit -- MUAT:ChromeTest:test_LanchTask')
        
    def test_LanchApplist(self):
        logger.info('Enter -- MUAT:ChromeTest:test_LanchApplist')
        serial_number = None
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
        #open chrome
        self.adb_tools.adb_shell("am start -n org.chromium.chrome/com.google.android.apps.chrome.Main")
        time.sleep(3)
        pc_max = self.d(resourceId='android:id/pc_max', className='android.widget.ImageView', packageName='org.chromium.chrome')
        pc_max.click()
        time.sleep(2)
        menuButton=self.d(resourceId='org.chromium.chrome:id/menu_button',packageName='org.chromium.chrome')
        menuButton.click()
        records=self.d(text=u"历史记录",packageName='org.chromium.chrome')
        records.click()
        # 从历史记录中打开网页
        for i in range(16):
            self.mouse.click(830,430,constants.MouseRightKey)
            self.mouse.click(890,460,constants.MouseLeftKey)
            time.sleep(1)
        str ='lanch applist after open chrome 16 tab...\n' 
        getcpuinfo(str)
            
        # click blank region to disappear applist
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(1)

        # start adb log capture thread
        detect_re = re.compile(r'MPT click .(%s), (%s). at (.*)$' % (constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y))
        wanted_re = re.compile(r'MPT: sf post one frame at (.*)$')

        adb_log = AdbLog(mode=AdbLog.MODE_RE | AdbLog.MODE_NEED_DETECT, wanted_re=wanted_re, detect_re=detect_re, logger=logger, serial_number=serial_number)
        adb_log.clear()
        adb_log.start()

        # click app list
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        logger.debug('click applist point (%s,%s)' % (constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y))
        time.sleep(2)

        # check the log and get the data
        while True:
            if len(adb_log.result) == 2:
                break
            else:
                time.sleep(1)

        # store the result
        click_point_x = 0
        click_point_y = 0
        start_time = 0
        end_time = 0
        cost_time = 0
        try:
            click_point_x   = int(adb_log.result[0][0])
            click_point_y   = int(adb_log.result[0][1])
            start_time      = int(adb_log.result[0][2])
            end_time        = int(adb_log.result[1][0])
            if click_point_x == constants.MUAT_APP_LIST_POINT_X and click_point_y == constants.MUAT_APP_LIST_POINT_Y:
                cost_time = end_time - start_time
            else:
                logger.error('detect_re detect the wrong point: (%s)' % (adb_log.result[0]))
        except:
            logger.error('retrieve time from (%s) error' % (adb_log.result))

        logger.info('start applist cost: %s' % (cost_time))
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(1)
        #close chrome
        closebtn = self.d(resourceId='android:id/pc_close', className='android.widget.ImageView', packageName='org.chromium.chrome')
        closebtn.click()
        logger.info('Exit -- MUAT:ChromeTest:test_LanchApplist')
        
    def test_Open10AppTab(self):
        logger.info('Enter -- MUAT:ChromeTest:test_Open10AppTab')
        serial_number = None
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number
        
        #open youku
        self.adb_tools.adb_shell('am start -n com.youku.phone.x86/com.youku.phone.x86.ActivityWelcome')
        time.sleep(3)
        #open ttpod
        logger.info('open the ttpod application................')
        self.adb_tools.adb_shell("am start -n com.sds.android.ttpod/.EntryActivity")
        time.sleep(3)
        #open QQ
        logger.info('open QQ application.......................')
        self.adb_tools.adb_shell("am start -n com.tencent.mobileqq/.activity.SplashActivity")
        time.sleep(3)
        #open xiami
        logger.info('open xiami application.......................')
        self.adb_tools.adb_shell("am start -n fm.xiami.main/fm.xiami.bmamba.activity.StartMainActivity")
        time.sleep(3)
        #open qianniu
        logger.info('open qianniiu application.......................')
        self.adb_tools.adb_shell('am start -n com.taobao.qianniu/.ui.InitActivity')
        time.sleep(3)
        #open weibo
        logger.info('open weibo application.......................')
        self.adb_tools.adb_shell('am start -n com.sina.weibotab/.ui.ActivitySplash')
        time.sleep(3)
        #open wps_pro
        logger.info('open wps application.......................')
        self.adb_tools.adb_shell("am start -n com.kingsoft.moffice_pro/cn.wps.moffice.documentmanager.PreStartActivity")
        time.sleep(3)
        #open gaode map
        logger.info('open minimap application.......................')
        self.adb_tools.adb_shell("am start -n com.autonavi.minimap/.Splashy")
        time.sleep(3)
        #open wangxin
        logger.info('open mobileim application.......................')
        self.adb_tools.adb_shell("am start -n com.alibaba.mobileim/.SplashActivity")
        time.sleep(3)
        #open taobao
        logger.info('open taobaoHD application.......................')
        self.adb_tools.adb_shell("am start -n com.taobao.apad/.activity.MainActivity")
        time.sleep(3)
        #open chrome
        self.adb_tools.adb_shell("am start -n org.chromium.chrome/com.google.android.apps.chrome.Main")
        time.sleep(3)
        pc_max = self.d(resourceId='android:id/pc_max', className='android.widget.ImageView', packageName='org.chromium.chrome')
        self.assertTrue(pc_max.exists)
        pc_max.click()
        time.sleep(2)
        menuButton=self.d(resourceId='org.chromium.chrome:id/menu_button',packageName='org.chromium.chrome')
        menuButton.click()
        records=self.d(text=u"历史记录",packageName='org.chromium.chrome')
        records.click()
        for i in range(16):
            self.mouse.click(830,430,constants.MouseRightKey)
            self.mouse.click(890,460,constants.MouseLeftKey)
            time.sleep(1)
        str ='after 10Apps open chrome 16 tab...\n' 
        getcpuinfo(str)
        #记录打开applist的时间
         # click blank region to disappear applist
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(1)
        # start adb log capture thread
        detect_re = re.compile(r'MPT click .(%s), (%s). at (.*)$' % (constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y))
        wanted_re = re.compile(r'MPT: sf post one frame at (.*)$')

        adb_log = AdbLog(mode=AdbLog.MODE_RE | AdbLog.MODE_NEED_DETECT, wanted_re=wanted_re, detect_re=detect_re, logger=logger, serial_number=serial_number)
        adb_log.clear()
        adb_log.start()

        # click app list
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        logger.debug('click applist point (%s,%s)' % (constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y))
        time.sleep(2)

        # check the log and get the data
        while True:
            if len(adb_log.result) == 2:
                break
            else:
                time.sleep(1)

        # store the result
        click_point_x = 0
        click_point_y = 0
        start_time = 0
        end_time = 0
        cost_time = 0
        try:
            click_point_x   = int(adb_log.result[0][0])
            click_point_y   = int(adb_log.result[0][1])
            start_time      = int(adb_log.result[0][2])
            end_time        = int(adb_log.result[1][0])
            if click_point_x == constants.MUAT_APP_LIST_POINT_X and click_point_y == constants.MUAT_APP_LIST_POINT_Y:
                cost_time = end_time - start_time
            else:
                logger.error('detect_re detect the wrong point: (%s)' % (adb_log.result[0]))
        except:
            logger.error('retrieve time from (%s) error' % (adb_log.result))

        logger.info('after 10Apps start applist cost: %s' % (cost_time))
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        wanted_re = re.compile(r'I.ActivityManager.*com.aliyun.mpc.taskmgr.*\+(.*)ms' )
        adb_log = AdbLog(mode=AdbLog.MODE_RE, wanted_re=wanted_re, logger=logger, serial_number=serial_number)
        adb_log.clear()
        adb_log.start()
        
        #记录打开任务管理器的时间
        # start apk
        self.adb_tools.adb_shell('am start -n  com.aliyun.mpc.taskmgr/.TaskMgr')
        
        # check the log and get the data
        while True:
            if adb_log.result:
                break
            else:
                time.sleep(1)
        # store the result
        cost_time = 0
        try:
            if 's' in adb_log.result[0][0]:
                composit = adb_log.result[0][0].split('s')
                cost_time = int(composit[0]) * 1000 + int(composit[1])
            else:
                cost_time = int(adb_log.result[0][0])
        except:
            logger.error('retrieve cost time from (%s) error' % (adb_log.result))
        
        logger.info('after 10Apps start TaskMgr cost: %s' % (cost_time))
        # close apk
        self.adb_tools.adb_shell('am force-stop com.aliyun.mpc.taskmgr')
        
        #close youku
        logger.info('close the youku application................')
        self.adb_tools.adb_shell('am force-stop com.youku.phone.x86')
        time.sleep(2)
        #close ttpod
        logger.info('close the ttpod application................')
        self.adb_tools.adb_shell("am force-stop com.sds.android.ttpod")
        time.sleep(2)
        #close QQ
        logger.info('close QQ application.......................')
        self.adb_tools.adb_shell("am force-stop com.tencent.mobileqq")
        time.sleep(2)
        #close xiami
        logger.info('close xiami application.......................')
        self.adb_tools.adb_shell("am force-stop fm.xiami.main")
        time.sleep(2)
        #close qianniu
        logger.info('close qianniiu application.......................')
        self.adb_tools.adb_shell('am force-stop com.taobao.qianniu')
        time.sleep(2)
        #close weibo
        logger.info('close weibo application.......................')
        self.adb_tools.adb_shell('am force-stop com.sina.weibotab')
        time.sleep(2)
        #open wps_pro
        logger.info('close wps application.......................')
        self.adb_tools.adb_shell("am force-stop com.kingsoft.moffice_pro")
        time.sleep(2)
        #close gaode map
        logger.info('close minimap application.......................')
        self.adb_tools.adb_shell("am force-stop com.autonavi.minimap")
        time.sleep(2)
        #close wangxin
        logger.info('close mobileim application.......................')
        self.adb_tools.adb_shell("am force-stop com.alibaba.mobileim")
        time.sleep(2)
        #close taobao
        logger.info('close taobaoHD application.......................')
        self.adb_tools.adb_shell("am force-stop com.taobao.apad")
        time.sleep(2)
        #close chrome
        closebtn = self.d(resourceId='android:id/pc_close', className='android.widget.ImageView', packageName='org.chromium.chrome')
        closebtn.click()
        
        logger.info('Exit -- MUAT:ChromeTest:test_Open10AppTab')
        
        
        
        
        
        
        
        
        
        
        
class BrowserTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()

        self.BaseImagePath = os.path.join(
            os.path.abspath(os.path.dirname("__file__")), "dependency",
            "BaseImage")
        self.FailureIamgePath = os.path.join(
            os.path.abspath(os.path.dirname("__file__")), "test-reports",
            "FailureImage")
        self.TmpImagePath = os.path.join(
            os.path.abspath(os.path.dirname("__file__")), "test-reports",
            "TmpImage")

        if not os.path.exists(self.TmpImagePath):
            os.mkdir(self.TmpImagePath)
        if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
            os.mkdir(os.path.join(self.TmpImagePath, "croped"))

        self.account.sleep()
        self.account.wakeup()
        self.account.login()
        closeButton = self.d(resourceId="android:id/pc_close",
                             className="android.widget.ImageView",
                             packageName="com.android.browser")
        if closeButton.exists:
            logger.debug('click close button: (%s)' %
                         (closeButton.info['packageName']))
            closeButton.click()
        self.adb_tools.adb_shell('am force-stop com.android.browser')

    def tearDown(self):
        closeButton = self.d(resourceId="android:id/pc_close",
                             className="android.widget.ImageView",
                             packageName="com.android.browser")
        if closeButton.exists:
            logger.debug('click close button: (%s)' %
                         (closeButton.info['packageName']))
            closeButton.click()
        self.adb_tools.adb_shell('am force-stop com.android.browser')
        if os.path.exists(self.TmpImagePath):
            shutil.rmtree(self.TmpImagePath)
        self.account.sleep()

    def test_OpenAndExit(self):
        logger.info('Enter -- MUAT:BrowserTest:test_OpenAndExit')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)

        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_OpenAndExit')

    def test_BlankPage(self):
        logger.info('Enter -- MUAT:BrowserTest:test_BlankPage')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)

        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            blankpage = self.d(resourceId="com.android.browser:id/title")
            if blankpage.exists:
                logger.info(blankpage.info)
                self.assertEqual(blankpage.info['text'], u'about:blank')
            address = self.d(resourceId="com.android.browser:id/url")
            if address.exists:
                self.assertEqual(address.info['text'], u"about:blank")

            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_BlankPage')

    def test_InputAddr(self):
        logger.info('Enter -- MUAT:BrowserTest:test_InputAddr')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)

        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            blankpage = self.d(resourceId="com.android.browser:id/title")
            if blankpage.exists:
                self.assertEqual(blankpage.info['text'], "about:blank")
#self.assertEqual(blankpage.info["text"],"about:blank")
            address = self.d(resourceId="com.android.browser:id/url")
            if address.exists:
                self.assertEqual(address.info['text'], "about:blank")
                address.clear_text()
                address.set_text("www.baidu.com")
                self.d.press(0x42)
                time.sleep(5)
                baiduPage = self.d(resourceId="com.android.browser:id/title")
                if baiduPage.exists:
                    self.assertEqual(baiduPage.info['text'], u'百度一下,你就知道')

            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_InputAddr')

    def test_RefreshPage(self):
        logger.info('Enter -- MUAT:BrowserTest:test_RefreshPage')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)

        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            self.assertTrue(self.d.press(0x8d))
            time.sleep(2)
            blankpage = self.d(resourceId="com.android.browser:id/title")
            if blankpage.exists:
                self.assertEqual(blankpage.info['text'], "about:blank")
            address = self.d(resourceId="com.android.browser:id/url")
            if address.exists:
                self.assertEqual(address.info['text'], "about:blank")
                address.clear_text()
                address.set_text("time")
                self.d.press(0x42)
                time.sleep(15)
                timebaiduPage = self.d(
                    resourceId="com.android.browser:id/title")
                if timebaiduPage.exists:
                    if timebaiduPage.info['text'] == u'time_百度搜索':
                        name1 = "test_RefreshPage_%s.jpg" % time.strftime(
                            '%Y%m%d%H%M%S', time.localtime())
                        img = os.path.join(self.TmpImagePath, name1)
                        self.d.screenshot(img)
                        cropedImgPath1 = os.path.join(
                            self.TmpImagePath, "croped",
                            name1.replace(".jpg", "_croped.jpg"))
                        CropImage(img, cropedImgPath1, 125, 266, 470, 366)

                        refreshButton = self.d(
                            resourceId="com.android.browser:id/stop",
                            className="android.widget.ImageButton",
                            packageName="com.android.browser")
                        if refreshButton.exists:
                            refreshButton.click()
                            time.sleep(15)

                            name2 = "test_RefreshPage_%s.jpg" % time.strftime(
                                '%Y%m%d%H%M%S', time.localtime())
                            img = os.path.join(self.TmpImagePath, name2)
                            self.d.screenshot(img)
                            cropedImgPath2 = os.path.join(
                                self.TmpImagePath, "croped",
                                name2.replace(".jpg", "_croped.jpg"))
                            CropImage(img, cropedImgPath2, 125, 266, 470, 366)

                            if CompareImage(cropedImgPath1, cropedImgPath2,
                                            0.99):
                                shutil.copy(
                                    cropedImgPath1,
                                    os.path.join(
                                        self.FailureIamgePath,
                                        name1.replace(".jpg", "_failure.jpg")))
                                shutil.copy(
                                    cropedImgPath2,
                                    os.path.join(
                                        self.FailureIamgePath,
                                        name2.replace(".jpg", "_failure.jpg")))
                                path = os.path.join(
                                    self.FailureIamgePath,
                                    name1.replace(".jpg", "_failure.jpg"))
                                self.fail("The failure file path is %s" % path)
            pageCloseBt = self.d(resourceId="com.android.browser:id/close")
            if pageCloseBt.exists:
                pageCloseBt.click()
            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_RefreshPage')

    def test_ForwardOrBackwrad(self):
        logger.info('Enter -- MUAT:BrowserTest:test_ForwardOrBackwrad')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)

        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            blankpage = self.d(resourceId="com.android.browser:id/title")
            if blankpage.exists:
                self.assertEqual(blankpage.info['text'], "about:blank")
            address = self.d(resourceId="com.android.browser:id/url")
            if address.exists:
                self.assertEqual(address.info['text'], "about:blank")
                address.clear_text()
                address.set_text("www.baidu.com")
                self.d.press(0x42)
                time.sleep(5)
                baiduPage = self.d(resourceId="com.android.browser:id/title")
                if baiduPage.exists:
                    if baiduPage.info['text'] == u'百度一下,你就知道':
                        address = self.d(
                            resourceId="com.android.browser:id/url")
                        if address.exists:
                            address.clear_text()
                            address.set_text("www.taobao.com")
                            self.d.press(0x42)
                            time.sleep(5)

                            taobaoPage = self.d(
                                resourceId="com.android.browser:id/title")
                            if taobaoPage.exists:
                                self.assertEqual(taobaoPage.info['text'],
                                                 u'淘宝网 - 淘!我喜欢')
                                backButton = self.d(
                                    resourceId="com.android.browser:id/back",
                                    className="android.widget.ImageButton",
                                    packageName="com.android.browser")
                                if backButton.exists:
                                    backButton.click()
                                    time.sleep(5)
                                    baiduPage = self.d(
                                        resourceId=
                                        "com.android.browser:id/title")
                                    if baiduPage.exists:
                                        self.assertEqual(
                                            baiduPage.info['text'],
                                            u'百度一下,你就知道')
                                    forwardButton = self.d(
                                        resourceId=
                                        "com.android.browser:id/forward",
                                        className="android.widget.ImageButton",
                                        packageName="com.android.browser")
                                    if forwardButton.exists:
                                        forwardButton.click()
                                        time.sleep(5)
                                        taobaoPage = self.d(
                                            resourceId=
                                            "com.android.browser:id/title")
                                        if taobaoPage.exists:
                                            self.assertEqual(
                                                taobaoPage.info['text'],
                                                u'淘宝网 - 淘!我喜欢')

            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_ForwardOrBackwrad')

    def test_BaiduSearch(self):
        logger.info('Enter -- MUAT:BrowserTest:test_BaiduSearch')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        time.sleep(3)
        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            blankpage = self.d(resourceId="com.android.browser:id/title")
            if blankpage.exists:
                self.assertEqual(blankpage.info['text'], "about:blank")
            address = self.d(resourceId="com.android.browser:id/url")
            if address.exists:
                self.assertEqual(address.info['text'], "about:blank")
                address.clear_text()
                address.set_text("time")
                self.d.press(0x42)
                time.sleep(15)
                timebaiduPage = self.d(
                    resourceId="com.android.browser:id/title")
                if timebaiduPage.exists:
                    self.assertEqual(timebaiduPage.info['text'], u'time_百度搜索')

            pageCloseBt = self.d(resourceId="com.android.browser:id/close")
            if pageCloseBt.exists:
                pageCloseBt.click()
            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_BaiduSearch')

    def test_EmptyBookmark(self):
        logger.info('Enter -- MUAT:BrowserTest:test_EmptyBookmark')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)

        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            bookmarkButton = self.d(resourceId="com.android.browser:id/star",
                                    className="android.widget.ImageButton",
                                    packageName="com.android.browser")
            if bookmarkButton.exists:
                bookmarkButton.click()
                time.sleep(2)
                bookmarkLabel = self.d(
                    resourceId="com.android.browser:id/label")
                self.assertFalse(bookmarkLabel.exists)

            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_EmptyBookmark')

    def test_SearchWebPage(self):
        logger.info('Enter -- MUAT:BrowserTest:test_SearchWebPage')
        BrowserIcon = self.d(text=u"浏览器", className="android.widget.TextView")
        click_x = BrowserIcon.info['visibleBounds']['left'] + 5
        click_y = BrowserIcon.info['visibleBounds']['top'] + 5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        BrowserWindow = self.d(className="android.widget.FrameLayout",
                               packageName="com.android.browser")
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            self.assertTrue(self.d.press(0x8d))
            blankpage = self.d(resourceId="com.android.browser:id/title")
            if blankpage.exists:
                self.assertEqual(blankpage.info['text'], u"about:blank")
            address = self.d(resourceId="com.android.browser:id/url")
            if address.exists:
                self.assertEqual(address.info['text'], "about:blank")
                address.clear_text()
                address.set_text("www.baidu.com")
                self.d.press(0x42)
                time.sleep(5)
                baiduPage = self.d(resourceId="com.android.browser:id/title")
                if baiduPage.exists:
                    self.assertEqual(baiduPage.info['text'], u'百度一下,你就知道')
                    for button in self.d(
                            className="android.widget.ImageButton",
                            packageName="com.android.browser"):
                        if button.info['contentDescription'] == u'更多选项':
                            button.click()
                            searchButton = self.d(
                                text=u"在网页上查找", resourceId="android:id/title")
                            if searchButton.exists:
                                searchButton.click()
                                editView = self.d(text=u"在网页上查找",
                                                  resourceId="android:id/edit")
                                if editView.exists:
                                    editView.clear_text()
                                    editView.set_text(u"About")
                                    time.sleep(3)
                                    BaseImg = os.path.join(
                                        self.BaseImagePath,
                                        "test_SearchWebPage.jpg")
                                    name = "test_SearchWebPage_%s.jpg" % time.strftime(
                                        '%Y%m%d%H%M%S', time.localtime())
                                    img = os.path.join(self.TmpImagePath, name)
                                    self.d.screenshot(img)
                                    cropedImgPath = os.path.join(
                                        self.TmpImagePath, "croped",
                                        name.replace(".jpg", "_croped.jpg"))
                                    CropImage(img, cropedImgPath, 1000, 945,
                                              1090, 970)
                                    if not CompareImage(
                                            cropedImgPath, BaseImg, 0.99):
                                        shutil.copy(
                                            cropedImgPath,
                                            os.path.join(
                                                self.FailureIamgePath,
                                                name.replace(
                                                    ".jpg", "_failure.jpg")))
                                        path = os.path.join(
                                            self.FailureIamgePath,
                                            name.replace(
                                                ".jpg", "_failure.jpg"))
                                        self.fail(
                                            "The failure file path is %s" %
                                            path)
                            break

            closeButton = self.d(resourceId="android:id/pc_close",
                                 className="android.widget.ImageView",
                                 packageName="com.android.browser")
            if closeButton.exists:
                logger.debug('click close button: (%s)' %
                             (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_SearchWebPage')
class WPSTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()
 
#         self.account.sleep()
#         self.account.wakeup()
#         self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start=time.time()
        while time.time()-start < constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.kingsoft.moffice_pro")
        #self.adb_tools.adb_shell('adb shell am force-stop com.kingsoft.moffice_pro')
        if closeButton.exists:
            closeButton.click()
            time.sleep(1)

    def tearDown(self):
        closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.kingsoft.moffice_pro")
        if closeButton.exists:
            closeButton.click()
            time.sleep(1)
            if closeButton.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertFalse(closeButton.exists)
            
        #self.adb_tools.adb_shell('adb shell am force-stop com.kingsoft.moffice_pro')
        time.sleep(1)
#         self.account.sleep()
    
             
    def test_OpenAndExit(self):
        logger.info('Enter -- MUAT:WPSTest:test_OpenAndExit')
        #self.adb_tools.adb_shell('am start -n com.kingsoft.moffice_pro/cn.wps.moffice.documentmanager.DocumentManager')
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)
        wps=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text='WPS Office')
        click_x = wps.info['visibleBounds']['left'] +5
        click_y = wps.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
#         click_x = WPSIcon.info['visibleBounds']['left'] +5
#         click_y = WPSIcon.info['visibleBounds']['top'] +5
#         self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        WPS_Title=self.d(text='WPS Office',resourceId='android:id/pc_title',packageName='com.kingsoft.moffice_pro')
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if WPS_Title.exists:
                break
            else:
                time.sleep(1)
        if not WPS_Title.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(WPS_Title.exists)
        closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.kingsoft.moffice_pro")
        if closeButton.exists:
            closeButton.click()
        logger.info('Exit -- MUAT:WPSTest:test_OpenAndExit')
              
    def test_OpenFile(self):
        logger.info('Enter -- MUAT:WPSTest:test_OpenFile')
        #self.adb_tools.adb_shell('am start -n com.kingsoft.moffice_pro/cn.wps.moffice.documentmanager.DocumentManager')
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)
        wps=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text='WPS Office')
        if wps.exists:
            click_x = wps.info['visibleBounds']['left'] +5
            click_y = wps.info['visibleBounds']['top'] +5
            self.mouse.click(click_x, click_y, constants.MouseLeftKey)
            WPS_Title=self.d(text='WPS Office',resourceId='android:id/pc_title',packageName='com.kingsoft.moffice_pro')
            start = time.time()
            while time.time() - start < constants.Time_Out:
                if WPS_Title.exists:
                    break
                else:
                    time.sleep(1)
            if not WPS_Title.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(WPS_Title.exists)    
        profile_layout=self.d(resourceId='com.kingsoft.moffice_pro:id/left_nav_profile_layout')
        click_x=profile_layout.info['visibleBounds']['right'] - 10
        click_y=profile_layout.info['visibleBounds']['bottom'] + 10
        self.mouse.click(click_x,click_y,constants.MouseLeftKey)
        #DOC
        doc_file=self.d(text=u'文档' , resourceId='com.kingsoft.moffice_pro:id/text')
        if doc_file.exists:
            doc_file.click()
            start = time.time()
            backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_backBtn')
            while time.time() - start < constants.Time_Out:
                if backButton.exists:
                    break
                else:
                    time.sleep(1)
            if not self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_logo').exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_logo').exists)
            self.d.press(48)
            self.d.press(62)
            saveIcon=self.d(resourceId='com.kingsoft.moffice_pro:id/image_save')
            if saveIcon.exists:
                saveIcon.click()
                myfile=self.d(text=u'我的文档',resourceId='com.kingsoft.moffice_pro:id/fb_filename_text')
                if myfile.exists:
                    myfile.click()
                    saveButton=self.d(resourceId='com.kingsoft.moffice_pro:id/btn_save')
                    if saveButton.exists:
                        saveButton.click()
                        replaceButton=self.d(resourceId='com.kingsoft.moffice_pro:id/dialog_button_positive')
                        if replaceButton.exists:
                            replaceButton.click()
                        time.sleep(3)
                        if backButton.exists:
                            backButton.click()
                            time.sleep(1)
        #TXT
        txt_file=self.d(text=u'便笺',resourceId='com.kingsoft.moffice_pro:id/text')
        if txt_file.exists:
            txt_file.click()
            start = time.time()
            backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_backBtn')
            while time.time() - start < constants.Time_Out:
                if backButton.exists:
                    break
                else:
                    time.sleep(1)
            if not self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_logo').exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_logo').exists)
            self.d.press(48)
            self.d.press(62)
            saveIcon=self.d(resourceId='com.kingsoft.moffice_pro:id/image_save')
            if saveIcon.exists:
                saveIcon.click()
                myfile=self.d(text=u'我的文档',resourceId='com.kingsoft.moffice_pro:id/fb_filename_text')
                if myfile.exists:
                    myfile.click()
                    saveButton=self.d(resourceId='com.kingsoft.moffice_pro:id/btn_save')
                    if saveButton.exists:
                        saveButton.click()
                        replaceButton=self.d(resourceId='com.kingsoft.moffice_pro:id/dialog_button_positive')
                        if replaceButton.exists:
                            replaceButton.click()
                            replaceButton.click()
                        time.sleep(3)
                        if backButton.exists:
                            backButton.click()
                            time.sleep(1)
                               
        #XLS
        xls_file=self.d(text=u'表格',resourceId='com.kingsoft.moffice_pro:id/text')
        if xls_file.exists:
            xls_file.click()
            start = time.time()
            backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/ss_titlebar_close')
            while time.time() - start < constants.Time_Out:
                if self.d(resourceId='com.kingsoft.moffice_pro:id/image_save').exists:
                    break
                else:
                    time.sleep(1)
            #time.sleep(1)
            if not self.d(resourceId='com.kingsoft.moffice_pro:id/ss_titlebar_logo').exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(self.d(resourceId='com.kingsoft.moffice_pro:id/ss_titlebar_logo').exists)
            self.d.press(48)
            self.d.press(62)
            self.d.press(66)
            saveIcon=self.d(resourceId='com.kingsoft.moffice_pro:id/image_save')
            if saveIcon.exists:
                saveIcon.click()
                myfile=self.d(text=u'我的文档',resourceId='com.kingsoft.moffice_pro:id/fb_filename_text')
                if myfile.exists:
                    myfile.click()
                    saveButton=self.d(resourceId='com.kingsoft.moffice_pro:id/btn_save')
                    if saveButton.exists:
                        saveButton.click()
                        replaceButton=self.d(resourceId='com.kingsoft.moffice_pro:id/dialog_button_positive')
                        if replaceButton.exists:
                            replaceButton.click()
                            time.sleep(3)
                        backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/ss_titlebar_close')
                        if backButton.exists:
                            backButton.click()
                            time.sleep(1)
        #PPT
#         ppt_file=self.d(text=u'演示',resourceId='com.kingsoft.moffice_pro:id/text')
#         if ppt_file.exists:
#             ppt_file.click()
#             start = time.time()
#             #backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_backBtn')
#             saveIcon=self.d(resourceId='com.kingsoft.moffice_pro:id/image_save')
#             while time.time() - start < constants.Time_Out:
#                 if saveIcon.exists:
#                     break
#                 else:
#                     time.sleep(1)
#             #self.d.press(48)
#             wps_content = self.d(resourceId='com.kingsoft.moffice_pro:id/content')
#             write_x = wps_content.info['visibleBounds']['left']+700
#             write_y = wps_content.info['visibleBounds']['top']+300
#             self.mouse.doubleclick(write_x,write_y,constants.MouseLeftKey)
#             self.d.press(48)
#             self.d.press(62)
#             #saveIcon=self.d(resourceId='com.kingsoft.moffice_pro:id/image_save')
#             if saveIcon.exists:
#                 saveIcon.click()
#                 myfile=self.d(text=u'我的文档',resourceId='com.kingsoft.moffice_pro:id/fb_filename_text')
#                 if myfile.exists:
#                     myfile.click()
#                     saveButton=self.d(resourceId='com.kingsoft.moffice_pro:id/btn_save')
#                     if saveButton.exists:
#                         saveButton.click()
#                         replaceButton=self.d(resourceId='com.kingsoft.moffice_pro:id/dialog_button_positive')
#                         if replaceButton.exists:
#                             replaceButton.click()
#                             time.sleep(3)
#                             self.d(resourceId='com.kingsoft.moffice_pro:id/ppt_titlebar_close').click()
#                         backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/ss_titlebar_close')
#                         if backButton.exists:
#                             backButton.click()
        
        closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.kingsoft.moffice_pro")
        if closeButton.exists:
            closeButton.click()
        logger.info('Exit -- MUAT:WPSTest:test_OpenFile')
             
    def test_RecentFile(self):
        logger.info('Enter -- MUAT:WPSTest:test_RecentFile')
        #self.adb_tools.adb_shell('am start -n com.kingsoft.moffice_pro/cn.wps.moffice.documentmanager.DocumentManager')
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)
        wps=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text='WPS Office')
        click_x = wps.info['visibleBounds']['left'] +5
        click_y = wps.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
#         click_x = WPSIcon.info['visibleBounds']['left'] +5
#         click_y = WPSIcon.info['visibleBounds']['top'] +5
#         self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        WPS_Title=self.d(text='WPS Office',resourceId='android:id/pc_title',packageName='com.kingsoft.moffice_pro')
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if WPS_Title.exists:
                break
            else:
                time.sleep(1)
        if not WPS_Title.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(WPS_Title.exists)
        profile_layout=self.d(resourceId='com.kingsoft.moffice_pro:id/left_nav_profile_layout')
        click_x=profile_layout.info['visibleBounds']['right'] - 10
        click_y=profile_layout.info['visibleBounds']['bottom'] + 58
        self.mouse.click(click_x,click_y,constants.MouseLeftKey)
        history_icon=self.d(resourceId='com.kingsoft.moffice_pro:id/history_record_item_icon')
        if not history_icon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(history_icon.exists)
           
        closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.kingsoft.moffice_pro")
        if closeButton.exists:
            closeButton.click()
        logger.info('Exit -- MUAT:WPSTest:test_RecentFile')
          
    def test_BackHome(self):
        logger.info('Enter -- MUAT:WPSTest:test_BackHome')
        #self.adb_tools.adb_shell('am start -n com.kingsoft.moffice_pro/cn.wps.moffice.documentmanager.DocumentManager')
        time.sleep(1)
        self.d.click(constants.MUAT_APP_LIST_EMPTY_X, constants.MUAT_APP_LIST_EMPTY_Y)
        time.sleep(0.2)
        self.d.click(constants.MUAT_APP_LIST_POINT_X, constants.MUAT_APP_LIST_POINT_Y)
        time.sleep(1)
        wps=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text='WPS Office')
        click_x = wps.info['visibleBounds']['left'] +5
        click_y = wps.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        
#         click_x = WPSIcon.info['visibleBounds']['left'] +5
#         click_y = WPSIcon.info['visibleBounds']['top'] +5
#         self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        WPS_Title=self.d(text='WPS Office',resourceId='android:id/pc_title',packageName='com.kingsoft.moffice_pro')
        start = time.time()
        while time.time() - start < constants.Time_Out:
            if WPS_Title.exists:
                break
            else:
                time.sleep(1)
        if not WPS_Title.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(WPS_Title.exists)
        profile_layout=self.d(resourceId='com.kingsoft.moffice_pro:id/left_nav_profile_layout')
        click_x=profile_layout.info['visibleBounds']['right'] - 10
        click_y=profile_layout.info['visibleBounds']['bottom'] + 10
        self.mouse.click(click_x,click_y,constants.MouseLeftKey)
        #DOC
        doc_file=self.d(text=u'文档' , resourceId='com.kingsoft.moffice_pro:id/text')
        if doc_file.exists:
            doc_file.click()
            start = time.time()
            backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_backBtn')
            while time.time() - start < constants.Time_Out:
                if backButton.exists:
                    break
                else:
                    time.sleep(1)
            WLogo=self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_logo',packageName='com.kingsoft.moffice_pro')
            if WLogo.exists:
                WLogo.click()
                time.sleep(1)
            if not self.d(text=u'新建',resourceId='com.kingsoft.moffice_pro:id/nav_item_title').exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(self.d(text=u'新建',resourceId='com.kingsoft.moffice_pro:id/nav_item_title').exists)
            self.assertTrue(self.d(text=u'最近',resourceId='com.kingsoft.moffice_pro:id/nav_item_title').exists)
            self.assertTrue(self.d(text=u'星标',resourceId='com.kingsoft.moffice_pro:id/nav_item_title').exists)
            self.d(resourceId='android:id/pc_max').click()
            self.d.click(960,540)
            time.sleep(2)
            backButton=self.d(resourceId='com.kingsoft.moffice_pro:id/writer_maintoolbar_backBtn')
            if backButton.exists:
                backButton.click()
              
        closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.kingsoft.moffice_pro")
        if closeButton.exists:
            closeButton.click()
        logger.info('Exit -- MUAT:WPSTest:test_BackHome')
            
class BrowserTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()
        
        self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
        self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
        self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
        
        if not os.path.exists(self.TmpImagePath):
            os.mkdir(self.TmpImagePath)
        if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
            os.mkdir(os.path.join(self.TmpImagePath, "croped"))

#         self.account.sleep()
#         self.account.wakeup()
#         self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')
        #time.sleep(3)
        
        Browser_Icon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        if not Browser_Icon.exists:
#             self.d.click(57,10)
#             time.sleep(1)
#             self.d.click(68,141)
#             start=time.time()
#             while time.time()-start<constants.Time_Out:
#                 if  Button1.exists:
#                     break
#                 else:
#                     time.sleep(1)

            if self.mon and not self.mon.running_status:
                self.skipTest('process monitor stop')

            self.d      = AutomationDevice().get_device()
            self.account = Account(self.d)
            self.mouse = AdbMouse()
            self.adb_tools = AdbTools()
        
            self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
            self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
            self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
        
            if not os.path.exists(self.TmpImagePath):
                os.mkdir(self.TmpImagePath)
            if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
                os.mkdir(os.path.join(self.TmpImagePath, "croped"))

            self.account.wakeup()
            self.account.login()
            Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
            start=time.time()
            while time.time()-start<constants.Time_Out:
                if not Button1.exists:
                    break
                else:
                    time.sleep(1)
            #time.sleep(5)
            self.d.click(950,562)
            time.sleep(1)
            Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
            if Button1.exists:
                Button1.click()
            time.sleep(1)
            if not Browser_Icon.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(Browser_Icon.exists)

    def tearDown(self):
        Button1=self.d(resourceId='android:id/button1',className='android.widget.Button',packageName='android')
        if Button1.exists:
            Button1.click()
            self.adb_tools.adb_shell('am start -n org.chromium.chrome/.browser.ChromeTabbedActivity')
            start=time.time()
            while time.time()-start<constants.Time_Out:
                if  self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome").exists:
                    break
                else:
                    time.sleep(1)
        
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(1)
        if closeButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertFalse(closeButton.exists)
        self.adb_tools.adb_shell('am force-stop org.chromium.chrome')
        if os.path.exists(self.TmpImagePath):
            shutil.rmtree(self.TmpImagePath)
            
    def test_OpenAndExit(self):
        logger.info('Enter -- MUAT:BrowserTest:test_OpenAndExit')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  BrowserWindow.exists:
                break
            else:
                time.sleep(1)
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_OpenAndExit')
         
    def test_BlankPage(self):
        logger.info('Enter -- MUAT:BrowserTest:test_BlankPage')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  BrowserWindow.exists:
                break
            else:
                time.sleep(1)
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            #blankpage title cannot find
            # blankpage = self.d(resourceId="org.chromium.chrome:id/url_bar")
            # if blankpage.exists:
            #     logger.info(blankpage.info)
            #     self.assertEqual(blankpage.info['text'], u'搜索或输入网址')
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                 
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_BlankPage')
        
    def test_InputAddr(self):
        logger.info('Enter -- MUAT:BrowserTest:test_InputAddr')
        BrowserIcon = self.d(text=u"浏览器",resourceId='com.aliyun.lightdesk:id/tag_name', className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
   
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            blankpage = self.d(resourceId="org.chromium.chrome:id/ntp_scrollview")
            if blankpage.exists:
                self.assertEqual(blankpage.info['contentDescription'], u"打开新的标签页")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("www.baidu.com")
                self.d.press(0x42)
                StopButton=self.d(description=u'停止加载网页',resourceId='org.chromium.chrome:id/refresh_button')
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not StopButton.exists:
                        break
                    else:
                        time.sleep(1)
                   
                baiduPage = self.d(className="android.webkit.WebView", packageName="org.chromium.chrome")
                if baiduPage.exists:
                    self.assertEqual(baiduPage.info['contentDescription'], u'百度一下,你就知道')
                                
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_InputAddr')
        
    def test_RefreshPage(self):
        logger.info('Enter -- MUAT:BrowserTest:test_RefreshPage')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
   
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            self.assertTrue(self.d.press(0x8d))
            time.sleep(2)
            blankpage = self.d(resourceId="org.chromium.chrome:id/ntp_scrollview")
            if blankpage.exists:
                self.assertEqual(blankpage.info['contentDescription'], u"打开新的标签页")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("time")
                self.d.press(0x42)
                time.sleep(5)
                StopButton=self.d(description=u'停止加载网页',resourceId='org.chromium.chrome:id/refresh_button')
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not StopButton.exists:
                        break
                    else:
                        time.sleep(1)
                timebaiduPage = self.d(resourceId="org.chromium.chrome:id/url_bar")
                if timebaiduPage.exists:
                    if timebaiduPage.info['text'] == 'https://www.baidu.com/s?ie=UTF-8&wd=time':
                        name1 = "test_RefreshPage_%s.jpg" % time.strftime('%Y%m%d%H%M%S', time.localtime())
                        img = os.path.join(self.TmpImagePath, name1)
                        self.d.screenshot(img)
                        cropedImgPath1 = os.path.join(self.TmpImagePath, "croped", name1.replace(".jpg", "_croped.jpg"))
                        CropImage(img, cropedImgPath1, 125, 266, 470, 366)
     
                        refreshButton = self.d(resourceId="org.chromium.chrome:id/refresh_button", className="android.widget.ImageButton", packageName="org.chromium.chrome")
                        if refreshButton.exists:
                            refreshButton.click()
                            start=time.time()
                            while time.time()-start<constants.TIME_OUT:
                                if not StopButton.exists:
                                    break
                                else:
                                    time.sleep(1)
                             
                            name2 = "test_RefreshPage_%s.jpg" % time.strftime('%Y%m%d%H%M%S', time.localtime())
                            img = os.path.join(self.TmpImagePath, name2)
                            self.d.screenshot(img)
                            cropedImgPath2 = os.path.join(self.TmpImagePath, "croped", name2.replace(".jpg", "_croped.jpg"))
                            CropImage(img, cropedImgPath2, 125, 266, 470, 366)
                                 
                            if  CompareImage(cropedImgPath1, cropedImgPath2, 0.99):
                                shutil.copy(cropedImgPath1, os.path.join(self.FailureIamgePath, name1.replace(".jpg", "_failure.jpg")))
                                shutil.copy(cropedImgPath2, os.path.join(self.FailureIamgePath, name2.replace(".jpg", "_failure.jpg")))
                                path = os.path.join(self.FailureIamgePath, name1.replace(".jpg", "_failure.jpg"))
                                self.fail("The failure file path is %s" % path)
            # pageCloseBt = self.d(resourceId="com.android.browser:id/close")
            # if pageCloseBt.exists:
            #     pageCloseBt.click()
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_RefreshPage')
            
    def test_ForwardOrBackwrad(self):
        logger.info('Enter -- MUAT:BrowserTest:test_ForwardOrBackwrad')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            # blankpage = self.d(resourceId="com.android.browser:id/title")
            # if blankpage.exists:
            #     self.assertEqual(blankpage.info['text'], "about:blank")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("www.baidu.com")
                self.d.press(0x42)
                time.sleep(5)
   
            baiduPage = self.d(className='android.webkit.WebView', packageName='org.chromium.chrome')
            logger.info('assert baidu title....................................')
            if baiduPage.exists:
                if baiduPage.info['contentDescription'] == u'百度一下,你就知道':
   
                    address = self.d(resourceId="org.chromium.chrome:id/url_bar")
                    if address.exists:
                        address.click()
                        address.clear_text()
                        address.set_text("www.taobao.com")
                        self.d.press(0x42)
                        time.sleep(5)
                                
                taobaoPage = self.d(className='android.webkit.WebView', packageName='org.chromium.chrome')
                if taobaoPage.exists:
                    self.assertEqual(taobaoPage.info['contentDescription'], u'淘宝网 - 淘!我喜欢')
                    backButton = self.d(resourceId="org.chromium.chrome:id/back_button", className="android.widget.ImageButton", packageName="org.chromium.chrome")
                    if backButton.exists:
                        backButton.click()
                        time.sleep(5)
                        baiduPage = self.d(className='android.webkit.WebView', packageName='org.chromium.chrome')
                        if baiduPage.exists:
                            self.assertEqual(baiduPage.info['contentDescription'], u'百度一下,你就知道')
                    forwardButton = self.d(resourceId="org.chromium.chrome:id/forward_button", className="android.widget.ImageButton", packageName="org.chromium.chrome")
                    if forwardButton.exists:
                        forwardButton.click()
                        time.sleep(5)
                taobaoPage = self.d(className='android.webkit.WebView', packageName='org.chromium.chrome')
                if taobaoPage.exists:
                    self.assertEqual(taobaoPage.info['contentDescription'], u'淘宝网 - 淘!我喜欢')
                                                
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_ForwardOrBackwrad')
            
        
    def test_BaiduSearch(self):
        logger.info('Enter -- MUAT:BrowserTest:test_BaiduSearch')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        # StopButton=self.d(description=u'停止网页加载',resourceId='com.android.browser:id/stop')
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            blankpage = self.d(resourceId="org.chromium.chrome:id/ntp_scrollview")
            if blankpage.exists:
                self.assertEqual(blankpage.info['contentDescription'], u"打开新的标签页")
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                address.clear_text()
                address.set_text("time")
                self.d.press(0x42)
                StopButton=self.d(description=u'停止加载网页',resourceId='org.chromium.chrome:id/refresh_button')
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not StopButton.exists:
                        break
                    else:
                        time.sleep(1)
                timebaiduPage = self.d(className="android.webkit.WebView", packageName="org.chromium.chrome")
                if timebaiduPage.exists:
                    self.assertEqual(timebaiduPage.info['contentDescription'], u'time_百度搜索')
                         
            # pageCloseBt = self.d(resourceId="com.android.browser:id/close")
            # if pageCloseBt.exists:
            #     pageCloseBt.click()
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_BaiduSearch')
         
    def test_EmptyBookmark(self):
        logger.info('Enter -- MUAT:BrowserTest:test_EmptyBookmark')
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserWindow.exists)
        if BrowserWindow.exists:
            menuButton = self.d(resourceId="org.chromium.chrome:id/menu_button", className="android.widget.ImageButton", packageName="org.chromium.chrome")
            if menuButton.exists:
                menuButton.click()
                time.sleep(2)
                bookmarkbtn = self.d(resourceId="org.chromium.chrome:id/menu_item_text")
                if bookmarkbtn.exists:
                    bookmarkbtn.click()
                    time.sleep(1)
   
                bookmarkLabel = self.d(resourceId="org.chromium.chrome:id/eb_empty_view")
                if not bookmarkLabel.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self, name)
                self.assertTrue(bookmarkLabel.exists)
                     
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:BrowserTest:test_EmptyBookmark')
           
    def test_SearchWebPage(self):
        #调用logger模块进行log信息输出,此处是info级别,使用debug级别请使用:logger.debug("AAA")
        logger.info('Enter -- MUAT:BrowserTest:test_SearchWebPage')
        #调用py-uiautomator进行查找标题为“浏览器”,类名为“android.widget.TextView”的浏览器图标
        BrowserIcon = self.d(text=u"浏览器", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not BrowserIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(BrowserIcon.exists)
 
        #通过上一步获得浏览器图标的位置信息,计算出需要鼠标双击的位置,及图标的左坐标+5, 上坐标+5,这个坐标正好位于图标可单击范围之中
        click_x = BrowserIcon.info['visibleBounds']['left'] +5
        click_y = BrowserIcon.info['visibleBounds']['top'] +5
        #调用mouse模块的双击函数,对上面计算到的坐标进行双击操作,打开浏览器窗口
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome").exists:
                break
            else:
                time.sleep(1)
        #调用py-uiautomator进行查找类名为"android.widget.FrameLayout",包名"com.android.browser"的浏览器窗口
        BrowserWindow = self.d(className="android.widget.FrameLayout", packageName="org.chromium.chrome")
        #断言检查浏览器窗口是否存在,若存在,BrowserWindow.exists会返回true,反之false
        if not BrowserWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(BrowserWindow.exists)
        #当浏览器窗口存在时
        if BrowserWindow.exists:
            #按下0x8d的键值,此键值在android中的含义是F11按键,具体的keycode请参考:http://developer.android.com/reference/android/view/KeyEvent.html
            self.assertTrue(self.d.press(0x8d))
            #断言检查是否存在资源ID为"com.android.browser:id/title"的浏览器页面
            blankpage = self.d(resourceId="org.chromium.chrome:id/ntp_scrollview")
            if blankpage.exists:
                #断言检查上面存在的浏览器页面的标题是否为“about:blank”
                self.assertEqual(blankpage.info['contentDescription'], u"打开新的标签页")
            #查找浏览器地址栏
            address = self.d(resourceId="org.chromium.chrome:id/url_bar")
            if address.exists:
                self.assertEqual(address.info['text'], u"搜索或输入网址")
                #清空地址栏
                address.clear_text()
                #地址栏输入“www.baidu.com”
                address.set_text("www.baidu.com")
                #按键0x24,即回车键
                self.d.press(0x42)
                StopButton=self.d(description=u'停止加载网页',resourceId='org.chromium.chrome:id/refresh_button')
#                 time.sleep(5)
                start=time.time()
                while time.time()-start<constants.TIME_OUT:
                    if not StopButton.exists:
                        break
                    else:
                        time.sleep(1)
                baiduPage = self.d(className="android.webkit.WebView", packageName="org.chromium.chrome")
                if baiduPage.exists:
                    #断言检查浏览器页面标题是否为:“百度一下,你就知道”,注意中文要用u修饰,表示此为utf8编码中文
                    self.assertEqual(baiduPage.info['contentDescription'], u'百度一下,你就知道')
                    #在浏览器中查找选项按钮
                    # menubtn = self.d(resourceId="org.chromium.chrome:id/menu_button")
                    # self.assertEqual(menubtn.info['contentDescription'], u'更多选项')
                    # if menubtn.exists:
                    #     menubtn.click()
                    #     time.sleep(1)
                    for button in self.d(resourceId="org.chromium.chrome:id/menu_button"):
                        if button.info['contentDescription'] == u'更多选项':
                            #按下“更多选项”按钮
                            button.click()
                            searchButton = self.d(text=u"在网页中查找", resourceId="org.chromium.chrome:id/menu_item_text")
                            if searchButton.exists:
                                #按下“在网页上查找”按钮
                                searchButton.click()
                                editView = self.d(text=u"在网页中查找", resourceId="org.chromium.chrome:id/find_query")
                                if editView.exists:
                                    #清空查找框
                                    editView.clear_text()
                                    # self.d.press(0x36, 0x71)
                                    #查找"About"字符
                                    editView.set_text(u"baidu")
                                    self.d.press(0x42)
                                    time.sleep(3)
                                    #截图,命名为test_SearchWebPage_%时间戳.jpg,此时截图是整个屏幕
                                    BaseImg = os.path.join(self.BaseImagePath, "test_SearchWebPage.jpg")
                                    name = "test_SearchWebPage_%s.jpg" % time.strftime('%Y%m%d%H%M%S', time.localtime())
                                    img = os.path.join(self.TmpImagePath, name)
                                    self.d.screenshot(img)
                                    #裁剪图片,与基准图大小一致,位置一致
                                    cropedImgPath = os.path.join(self.TmpImagePath, "croped", name.replace(".jpg", "_croped.jpg"))
                                    # CropImage(img, cropedImgPath, 1000, 945, 1090, 970)
                                    CropImage(img, cropedImgPath, 1200,950,1290,975)
                                    #比较上一步裁剪后的图片与基准图片
                                    if not CompareImage(cropedImgPath, BaseImg, 0.99):
                                        shutil.copy(cropedImgPath, os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg")))
                                        path = os.path.join(self.FailureIamgePath, name.replace(".jpg", "_failure.jpg"))
                                        self.fail("The failure file path is %s" % path)
                            break
            #点击关闭按钮,关闭浏览器
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="org.chromium.chrome")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        #输出测试用例退出log信息        
        logger.info('Exit -- MUAT:BrowserTest:test_SearchWebPage')
class PrintScreenTest(ParametrizedTestCase):
    def setUp(self):
        # check monitor running status
        if self.mon and not self.mon.running_status:
            self.skipTest('process monitor stop')

        self.d      = AutomationDevice().get_device()
        self.account = Account(self.d)
        self.mouse = AdbMouse()
        self.adb_tools = AdbTools()
        
        self.BaseImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "dependency", "BaseImage")
        self.FailureIamgePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "FailureImage")
        self.TmpImagePath = os.path.join(os.path.abspath(os.path.dirname("__file__")), "test-reports", "TmpImage")
        
        if not os.path.exists(self.TmpImagePath):
            os.mkdir(self.TmpImagePath)
        if not os.path.exists(os.path.join(self.TmpImagePath, "croped")):
            os.mkdir(os.path.join(self.TmpImagePath, "croped"))

#         self.account.sleep()
#         self.account.wakeup()
#         self.account.login()
        Button1=self.d(resourceId='com.yunpc.yunosloginui:id/avatar')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if not Button1.exists:
                break
            else:
                time.sleep(1)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.ali.screenshot")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            self.adb_tools.adb_shell('am force-stop com.ali.screenshot')
        
    def tearDown(self):
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.ali.screenshot")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(1)
        if closeButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
            self.adb_tools.adb_shell('am force-stop com.ali.screenshot')
            self.assertFalse(closeButton.exists)
            if os.path.exists(self.TmpImagePath):
                shutil.rmtree(self.TmpImagePath)
            
    def test_OpenAndExit(self):
        logger.info('Enter -- MUAT:PrintScreenTest:test_OpenAndExit')
        ScreenIcon = self.d(text=u"截屏", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not ScreenIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(ScreenIcon.exists)
        click_x = ScreenIcon.info['visibleBounds']['left'] +5
        click_y = ScreenIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        time.sleep(1)
        ScreenTitle = self.d(resourceId="android:id/pc_titlebar", packageName="com.ali.screenshot")
        self.assertTrue(ScreenTitle.exists)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.ali.screenshot")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            time.sleep(1)
        logger.info('Exit -- MUAT:PrintScreenTest:test_OpenAndExit')
        
#     def test_StartByShortcut(self):
#         logger.info('Enter -- MUAT:PrintScreenTest:test_StartByShortcut')
    def test_FullScreenShot(self):
        logger.info('Enter -- MUAT:PrintScreenTest:test_FullScreenShot')
        ScreenIcon = self.d(text=u"截屏", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not ScreenIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(ScreenIcon.exists)
        click_x = ScreenIcon.info['visibleBounds']['left'] +5
        click_y = ScreenIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        time.sleep(1)
        ScreenTitle = self.d(resourceId="android:id/pc_titlebar", packageName="com.ali.screenshot")
        self.assertTrue(ScreenTitle.exists)
        full_screenshot=self.d(resourceId='com.ali.screenshot:id/m_connect_win_button',packageName='com.ali.screenshot')
        if full_screenshot.exists:
            full_screenshot.click()
            time.sleep(2)
            self.mouse.click(1690,10,constants.MouseLeftKey)
            self.mouse.click(1690,90,constants.MouseLeftKey)
            time.sleep(1)
            FileManagePic=self.d(resourceId='com.yunpc.filemanager:id/paraList_imgHead',packageName='com.yunpc.filemanager')
            self.assertTrue(FileManagePic.exists)
            self.d(resourceId='android:id/pc_close',packageName='com.yunpc.filemanager').click()
        logger.info('Exit -- MUAT:PrintScreenTest:test_FullScreenShot')
        
    def test_AreaScreenShot(self):
        logger.info('Enter -- MUAT:PrintScreenTest:test_AreaScreenShot')
        ScreenIcon = self.d(text=u"截屏", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not ScreenIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(ScreenIcon.exists)
        click_x = ScreenIcon.info['visibleBounds']['left'] +5
        click_y = ScreenIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        time.sleep(1)
        ScreenTitle = self.d(resourceId="android:id/pc_titlebar", packageName="com.ali.screenshot")
        self.assertTrue(ScreenTitle.exists)
        area_screenshot=self.d(resourceId='com.ali.screenshot:id/m_connect_rect_button',packageName='com.ali.screenshot')
        if area_screenshot.exists:
            area_screenshot.click()
            time.sleep(1)
            self.d.swipe(300,250,800,750,20)
            time.sleep(1)
            self.d(resourceId='com.ali.screenshot:id/s_crop_ok_button',packageName='com.ali.screenshot').click()
            time.sleep(1)
            self.mouse.click(1690,10,constants.MouseLeftKey)
            self.mouse.click(1690,90,constants.MouseLeftKey)
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.yunpc.filemanager:id/paraList_imgHead',packageName='com.yunpc.filemanager').exists)
            self.d(resourceId='android:id/pc_close',packageName='com.yunpc.filemanager').click()
        logger.info('Exit -- MUAT:PrintScreenTest:test_AreaScreenShot')
        
    def test_Cancle(self):
        logger.info('Enter -- MUAT:test_PrintScreen:test_Cancle')
        ScreenIcon = self.d(text=u"截屏", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not ScreenIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(ScreenIcon.exists)
        click_x = ScreenIcon.info['visibleBounds']['left'] +5
        click_y = ScreenIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        time.sleep(1)
        ScreenTitle = self.d(resourceId="android:id/pc_titlebar", packageName="com.ali.screenshot")
        self.assertTrue(ScreenTitle.exists)
        area_screenshot=self.d(resourceId='com.ali.screenshot:id/m_connect_rect_button',packageName='com.ali.screenshot')
        if area_screenshot.exists:
            area_screenshot.click()
            time.sleep(1)
            self.d.swipe(300,250,800,750,20)
            time.sleep(1)
            self.d(resourceId='com.ali.screenshot:id/s_crop_cancel_button',packageName='com.ali.screenshot').click()
            time.sleep(1)
            self.mouse.click(1690,10,constants.MouseLeftKey)
            self.mouse.click(1670,90,constants.MouseLeftKey)
            self.assertFalse(self.d(resourceId='com.yunpc.filemanager:id/paraList_imgHead',packageName='com.yunpc.filemanager').exists)
            time.sleep(1)
        logger.info('Exit -- MUAT:PrintScreenTest:test_Cancle')
        
    def test_DragScreen(self):
        logger.info('Enter -- MUAT:test_PrintScreen:test_DragScreen') 
        ScreenIcon = self.d(text=u"截屏", resourceId='com.aliyun.lightdesk:id/tag_name',className="android.widget.TextView")
        if not ScreenIcon.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(ScreenIcon.exists)
        click_x = ScreenIcon.info['visibleBounds']['left'] +5
        click_y = ScreenIcon.info['visibleBounds']['top'] +5
        self.mouse.doubleclick(click_x, click_y, constants.MouseLeftKey)
        time.sleep(1)
        ScreenTitle = self.d(resourceId="android:id/pc_titlebar", packageName="com.ali.screenshot")
        self.assertTrue(ScreenTitle.exists)
        area_screenshot=self.d(resourceId='com.ali.screenshot:id/m_connect_rect_button',packageName='com.ali.screenshot')
        if area_screenshot.exists:
            area_screenshot.click()
            time.sleep(1)
            self.d.swipe(300,250,800,750,20)
            time.sleep(1)
            self.d.drag(500,400,900,700,10)
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.ali.screenshot:id/s_crop_ok_button',packageName='com.ali.screenshot').exists)
            self.d(resourceId='com.ali.screenshot:id/s_crop_ok_button',packageName='com.ali.screenshot').click()
            time.sleep(1)
            self.mouse.click(1690,10,constants.MouseLeftKey)
            self.mouse.click(1670,90,constants.MouseLeftKey)
            time.sleep(0.5)
            self.assertTrue(self.d(resourceId='com.yunpc.filemanager:id/paraList_imgHead',packageName='com.yunpc.filemanager').exists)
            time.sleep(1)
            self.d(resourceId='android:id/pc_close',packageName='com.yunpc.filemanager').click()
        
        logger.info('Exit -- MUAT:PrintScreenTest:test_DragScreen')