예제 #1
0
class PaintTest(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.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            self.adb_tools.adb_shell('am force-stop com.paint.board')
        
    def tearDown(self):
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        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.paint.board')
            self.assertFalse(closeButton.exists)
        if os.path.exists(self.TmpImagePath):
            shutil.rmtree(self.TmpImagePath)
        self.account.sleep()
            
    def test_OpenAndExit(self):
        logger.info('Enter -- MUAT:PaintTest:test_OpenAndExit')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow = self.d(className="android.widget.FrameLayout", packageName="com.paint.board")
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  PaintWindow.exists:
                break
            else:
                time.sleep(1)
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(PaintWindow.exists)
        if PaintWindow.exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_OpenAndExit')
         
    def test_OpenPic(self):
        logger.info('Enter -- MUAT:PaintTest:test_OpenPic')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        #max window
        self.d(resourceId='android:id/pc_max',packageName='com.paint.board').click()
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            #open jpg
            fileButton.click()
            click_x = editButton.info['visibleBounds']['left']
            click_y = editButton.info['visibleBounds']['bottom'] +40
            self.d.click(click_x,click_y)
            time.sleep(1)
            customer=self.d(resourceId='android:id/custom',className='android.widget.FrameLayout')
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,10)
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,10)
            fileName=self.d(resourceId='com.paint.board:id/filedialogitem_name',text='jpg.jpg')
            self.assertTrue(fileName.exists)
            file_x=fileName.info['visibleBounds']['left']+5
            file_y=fileName.info['visibleBounds']['top']+5
            self.d.click(file_x,file_y)
            #self.mouse.doubleclick(file_x, file_y, constants.MouseLeftKey)
            time.sleep(1)
            #self.d(resourceId='com.paint.board:id/filedialogitem_img',packageName='com.paint.board').click()
            self.d(text=u'打开',resourceId='com.paint.board:id/dia_postive').click()
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/t_tab',text='jpg.jpg').exists)
            #open png
            fileButton.click()
            click_x = editButton.info['visibleBounds']['left']
            click_y = editButton.info['visibleBounds']['bottom'] +40
            self.d.click(click_x,click_y)
            time.sleep(1)
            customer=self.d(resourceId='android:id/custom',className='android.widget.FrameLayout')
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,20)
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,20)
            fileName=self.d(resourceId='com.paint.board:id/filedialogitem_name',text='png.png')
            self.assertTrue(fileName.exists)
            file_x=fileName.info['visibleBounds']['left']+5
            file_y=fileName.info['visibleBounds']['top']+5
            self.d.click(file_x,file_y)
            time.sleep(1)
            self.d(text=u'打开',resourceId='com.paint.board:id/dia_postive').click()
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/t_tab',text='png.png').exists)
            
        if PaintWindow.exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_OpenPic')
 
    def test_NewFile(self):
        logger.info('Enter -- MUAT:PaintTest:test_NewFile')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_x = editButton.info['visibleBounds']['left']
            click_y = editButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_x,click_y)
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
        if PaintWindow.exists:
            closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
            if closeButton.exists:
                logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
                closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_NewFile')
         
    def test_CloseFile(self):
        logger.info('Enter -- MUAT:PaintTest:test_CloseFile')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_x = editButton.info['visibleBounds']['left']
            click_y = editButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_x,click_y)
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            swipe_start_x=paint_board.info['visibleBounds']['left']+50
            swipe_start_y=paint_board.info['visibleBounds']['top']+50
            swipe_end_x=swipe_start_x + 200
            swipe_end_y=swipe_start_y + 200
            self.d.swipe(swipe_start_x,swipe_start_y,swipe_end_x,swipe_end_y,10)
            closeButton=self.d(resourceId='com.paint.board:id/b_tab')
            if closeButton.exists:
                closeButton.click()
                time.sleep(2)
                self.assertTrue(self.d(resourceId='android:id/message',text=u'是否保存?').exists)
                self.d(resourceId='android:id/button2',text=u'是').click()
                time.sleep(1)
                saveButton=self.d(resourceId='com.paint.board:id/dia_postive')
                if saveButton.exists:
                    saveButton.click()
                    time.sleep(1)
                    ok=self.d(resourceId='android:id/button1',text=u'确认')
                    if ok.exists:
                        ok.click()
                        time.sleep(1)
                        self.assertFalse(self.d(resourceId='com.paint.board:id/paint_view').exists)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_CloseFile')
              
    def test_SaveFile(self):
        logger.info('Enter -- MUAT:PaintTest:test_SaveFile')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            time.sleep(1)
            click_new_x = fileButton.info['visibleBounds']['right']
            click_new_y = fileButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_new_x, click_new_y)
            time.sleep(2)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            swipe_start_x=paint_board.info['visibleBounds']['left']+50
            swipe_start_y=paint_board.info['visibleBounds']['top']+50
            swipe_end_x=swipe_start_x + 200
            swipe_end_y=swipe_start_y + 300
            self.d.swipe(swipe_start_x,swipe_start_y,swipe_end_x,swipe_end_y,10)
            time.sleep(1)
            fileButton.click()
            time.sleep(1)
            click_save_x = fileButton.info['visibleBounds']['right']
            click_save_y = fileButton.info['visibleBounds']['bottom'] +60
            self.d.click(click_save_x,click_save_y)
            time.sleep(1)
            saveButton=self.d(resourceId='com.paint.board:id/dia_postive')
            if saveButton.exists:
                saveButton.click()
                time.sleep(1)
                ok=self.d(resourceId='android:id/button1',text=u'确认')
                if ok.exists:
                    ok.click()
                    time.sleep(1)
            closeButton=self.d(resourceId='com.paint.board:id/b_tab')
            if closeButton.exists:
                closeButton.click()
                time.sleep(2)
                self.assertFalse(self.d(resourceId='android:id/message',text=u'是否保存?').exists)
                self.assertFalse(self.d(resourceId='com.paint.board:id/paint_view').exists)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_SaveFile')
         
    def test_CopyPic(self):
        logger.info('Enter -- MUAT:PaintTest:test_CopyPic')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        self.assertTrue(self.d.press(0x8d))
        time.sleep(1)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_open_x = fileButton.info['visibleBounds']['right']
            click_open_y = fileButton.info['visibleBounds']['bottom'] +35
            self.d.click(click_open_x,click_open_y)
            time.sleep(1)
            customer=self.d(resourceId='android:id/custom',className='android.widget.FrameLayout')
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,10)
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,10)
            fileName=self.d(resourceId='com.paint.board:id/filedialogitem_name',text='jpg.jpg')
            self.assertTrue(fileName.exists)
            file_x=fileName.info['visibleBounds']['left']+5
            file_y=fileName.info['visibleBounds']['top']+5
            self.d.click(file_x,file_y)
            #self.mouse.doubleclick(file_x, file_y, constants.MouseLeftKey)
            time.sleep(1)
            #self.d(resourceId='com.paint.board:id/filedialogitem_img',packageName='com.paint.board').click()
            self.d(text=u'打开',resourceId='com.paint.board:id/dia_postive').click()
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/t_tab',text='jpg.jpg').exists)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            choose_button=self.d(resourceId='com.paint.board:id/b_choose',packageName='com.paint.board')
            choose_button.click()
            self.d.click(choose_button.info['visibleBounds']['right'],choose_button.info['visibleBounds']['bottom']+10)
            time.sleep(1)
#             swipe_start_x=paint_board.info['visibleBounds']['left']+50
#             swipe_start_y=paint_board.info['visibleBounds']['top']+50
#             swipe_end_x=swipe_start_x + 200
#             swipe_end_y=swipe_start_y + 200
            self.d.swipe(500,500,750,750,10)
            time.sleep(1)
            editButton.click()
            self.d.click(editButton.info['visibleBounds']['right'],editButton.info['visibleBounds']['bottom']+40)
            fileButton.click()
            time.sleep(1)
            self.d.click(fileButton.info['visibleBounds']['right'],fileButton.info['visibleBounds']['bottom']+10)
            editButton.click()
            time.sleep(1)
            self.d.click(editButton.info['visibleBounds']['right'],editButton.info['visibleBounds']['bottom']+60)
            time.sleep(1)
            BaseImg = os.path.join(self.BaseImagePath, "test_CopyPic.jpg")
            name = "test_CopyPic_%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, 360,147,1560,1047)
            #比较上一步裁剪后的图片与基准图片
            if not CompareImage(cropedImgPath, BaseImg, 0.5):
                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)
            self.assertTrue(self.d.press(0x8d))
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_CopyPic')
         
    def test_CutPic(self):
        logger.info('Enter -- MUAT:PaintTest:test_CutPic')
        # 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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        self.assertTrue(self.d.press(0x8d))
        time.sleep(1)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_new_x = fileButton.info['visibleBounds']['right']
            click_new_y = fileButton.info['visibleBounds']['bottom'] +35
            self.d.click(click_new_x,click_new_y)
            time.sleep(1)
            customer=self.d(resourceId='android:id/custom',className='android.widget.FrameLayout')
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,10)
            self.d.drag(customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['bottom']-170,customer.info['visibleBounds']['right']-100,customer.info['visibleBounds']['top']+10,10)
            fileName=self.d(resourceId='com.paint.board:id/filedialogitem_name',text='jpg.jpg')
            self.assertTrue(fileName.exists)
            file_x=fileName.info['visibleBounds']['left']+5
            file_y=fileName.info['visibleBounds']['top']+5
            self.d.click(file_x,file_y)
            #self.mouse.doubleclick(file_x, file_y, constants.MouseLeftKey)
            time.sleep(1)
            #self.d(resourceId='com.paint.board:id/filedialogitem_img',packageName='com.paint.board').click()
            self.d(text=u'打开',resourceId='com.paint.board:id/dia_postive').click()
            time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/t_tab',text='jpg.jpg').exists)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            choose_button=self.d(resourceId='com.paint.board:id/b_choose',packageName='com.paint.board')
            choose_button.click()
            self.d.click(choose_button.info['visibleBounds']['right'],choose_button.info['visibleBounds']['bottom']+10)
            time.sleep(1)
#             swipe_start_x=paint_board.info['visibleBounds']['left']+50
#             swipe_start_y=paint_board.info['visibleBounds']['top']+50
#             swipe_end_x=swipe_start_x + 200
#             swipe_end_y=swipe_start_y + 200
            self.d.swipe(500,500,750,750,10)
            time.sleep(1)
            editButton.click()
            self.d.click(editButton.info['visibleBounds']['right'],editButton.info['visibleBounds']['bottom']+10)
            time.sleep(1)
            BaseImg = os.path.join(self.BaseImagePath, "test_CutPic.jpg")
            name = "test_CutPic_%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, 360,147,1560,1047)
            #比较上一步裁剪后的图片与基准图片
            if not CompareImage(cropedImgPath, BaseImg, 0.5):
                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)
            self.assertTrue(self.d.press(0x8d))
                 
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_CutPic')
        
    def test_Pen(self):
        logger.info('Enter -- MUAT:PaintTest:test_Pen')
        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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_new_x = editButton.info['visibleBounds']['left']
            click_new_y = editButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_new_x,click_new_y)
            #time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            pencil=self.d(resourceId='com.paint.board:id/b_status',packageName='com.paint.board')
            pencil.click()
            time.sleep(1)
            #choose pencil
            choose_pencil_x=pencil.info['visibleBounds']['right']
            choose_pencil_y=pencil.info['visibleBounds']['bottom']+74
            self.d.click(choose_pencil_x,choose_pencil_y)
            time.sleep(1)
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            swipe_start_x=paint_board.info['visibleBounds']['left']+50
            swipe_start_y=paint_board.info['visibleBounds']['top']+50
            swipe_end_x=swipe_start_x + 200
            swipe_end_y=swipe_start_y + 200
            self.d.swipe(swipe_start_x,swipe_start_y,swipe_end_x,swipe_end_y,20)
            time.sleep(0.5)
            #compare cutpic with baseimage
            BaseImg = os.path.join(self.BaseImagePath, "test_Pencil.jpg")
            name = "test_Pencil_%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, paint_board.info['visibleBounds']['left'],paint_board.info['visibleBounds']['top'],paint_board.info['visibleBounds']['right'],paint_board.info['visibleBounds']['bottom'])
            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)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_Pen')
        
    def test_FullScreen(self):
        logger.info('Enter -- MUAT:PaintTest:test_FullScreen')
        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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        self.assertTrue(self.d.press(0x8d))
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_new_x = editButton.info['visibleBounds']['left']
            click_new_y = editButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_new_x,click_new_y)
            #time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
        self.assertTrue(self.d.press(0x8d))
        self.assertTrue(PaintWindow.exists)
        
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
        logger.info('Exit -- MUAT:PaintTest:test_FullScreen')
        
    def test_InsertText(self):
        logger.info('Enter -- MUAT:PaintTest:test_InsertText')
        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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_new_x = editButton.info['visibleBounds']['left']
            click_new_y = editButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_new_x,click_new_y)
            #time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            self.d(resourceId='com.paint.board:id/b_7',packageName='com.paint.board').click()
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            drag_start_x=paint_board.info['visibleBounds']['left']+50
            drag_start_y=paint_board.info['visibleBounds']['top']+50
            drag_end_x=drag_start_x + 200
            drag_end_y=drag_start_y + 200
            self.d.drag(drag_start_x,drag_start_y,drag_end_x,drag_end_y,20)
            time.sleep(0.5)
            self.d.click(drag_start_x + 5,drag_start_y + 5)
            time.sleep(1)
            self.d.press(48)
            self.d.press(48)
            self.d.press(62)
            self.d.click(drag_end_x,drag_end_y)
            time.sleep(1)
            #compare cutpic with baseimage
            BaseImg = os.path.join(self.BaseImagePath, "test_Paint_Text.jpg")
            name = "test_Paint_Text_%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, paint_board.info['visibleBounds']['left'],paint_board.info['visibleBounds']['top'],paint_board.info['visibleBounds']['right'],paint_board.info['visibleBounds']['bottom'])
            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)
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            logger.info('Exit -- MUAT:PaintTest:test_InsertText')
            
    def test_DrawCircle(self):
        logger.info('Enter -- MUAT:PaintTest:test_DrawCircle')
        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)
        paint=self.d(resourceId='com.aliyun.lightdesk:id/gv_item_appname',text=u'画图')
        click_x = paint.info['visibleBounds']['left'] +5
        click_y = paint.info['visibleBounds']['top'] +5
        self.mouse.click(click_x, click_y, constants.MouseLeftKey)
        time.sleep(2)
        PaintWindow=self.d(resourceId='android:id/pc_title',packageName='com.paint.board')
        if not PaintWindow.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self, name)
        self.assertTrue(PaintWindow.exists)
        fileButton=self.d(resourceId='com.paint.board:id/b_file',text=u'文件')
        editButton=self.d(resourceId='com.paint.board:id/b_edit',text=u'编辑')
        if fileButton.exists:
            fileButton.click()
            click_new_x = editButton.info['visibleBounds']['left']
            click_new_y = editButton.info['visibleBounds']['bottom'] +10
            self.d.click(click_new_x,click_new_y)
            #time.sleep(1)
            self.assertTrue(self.d(resourceId='com.paint.board:id/paint_view').exists)
            circle_button=self.d(resourceId='com.paint.board:id/b_shape',packageName='com.paint.board')
            circle_button.click()
            self.d.click(circle_button.info['visibleBounds']['right']+10,circle_button.info['visibleBounds']['bottom']+10)
            time.sleep(0.5)
            paint_board=self.d(resourceId='com.paint.board:id/paint_view')
            swipe_start_x=paint_board.info['visibleBounds']['left']+50
            swipe_start_y=paint_board.info['visibleBounds']['top']+50
            swipe_end_x=swipe_start_x + 200
            swipe_end_y=swipe_start_y + 200
            self.d.swipe(swipe_start_x,swipe_start_y,swipe_end_x,swipe_end_y,20)
            time.sleep(0.5)
            #compare cutpic with baseimage
            BaseImg = os.path.join(self.BaseImagePath, "test_Circle.jpg")
            name = "test_Circle_%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, paint_board.info['visibleBounds']['left'],paint_board.info['visibleBounds']['top'],paint_board.info['visibleBounds']['right'],paint_board.info['visibleBounds']['bottom'])
            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)
        
        closeButton = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.paint.board")
        if closeButton.exists:
            logger.debug('click close button: (%s)' % (closeButton.info['packageName']))
            closeButton.click()
            logger.info('Exit -- MUAT:PaintTest:test_DrawCircle')
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')
        
        
        
        
        
        
        
        
        
        
        
예제 #3
0
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 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')