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 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 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.account.sleep()
        self.account.wakeup()
        self.account.login()
Esempio n. 4
0
    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 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 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()
		time.sleep(5)
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')
        
        
        
        
        
        
        
        
        
        
        
Esempio n. 8
0
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 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 MobileImTest(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)
        self.adb_tools.adb_shell('am force-stop com.alibaba.mobileim')
        time.sleep(2)
        # self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
        self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/.ui.tab.MainTabActivity')
#        /.ui.tab.MainTabActivity  /com.alibaba.mobileim.SplashActivity
        mobileimdialog = self.d(resourceId='android:id/pc_title', className='android.widget.TextView', packageName='com.alibaba.mobileim')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  mobileimdialog.exists:
                break
            else:
                time.sleep(1)
        if not mobileimdialog.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(mobileimdialog.exists)
        if mobileimdialog.exists:
            if self.d(resourceId="com.alibaba.mobileim:id/guide_image_one", className="android.widget.ImageView").exists:
                CustomViewPager = self.d(resourceId="com.alibaba.mobileim:id/container", className="com.alibaba.mobileim.fundamental.widget.CustomViewPager")
                if CustomViewPager.exsits:
                    #startX = CustomViewPager.info
                    logger.debug('CustomViewPager: (%s)' % (CustomViewPager.info['className']))
            else:
                #input wangxin login account:
                wx_account = self.d(resourceId="com.alibaba.mobileim:id/accountCompleteTextView", className="android.widget.EditText")
                if wx_account.exists and wx_account.info['text'] == constants.TEST_WX_USERNAME:
                    pass

                elif wx_account.exists and wx_account.info['text'] == u'淘宝帐号/手机号':
                    #self.assertEqual(wx_account.info['text'], u"淘宝帐号/手机号")
                    wx_account.clear_text()
                    time.sleep(2)
                    wx_account.set_text(constants.TEST_WX_USERNAME)
                    time.sleep(2)

                #input wangxin login password
                wx_password = self.d(resourceId="com.alibaba.mobileim:id/content", className="android.widget.EditText")
                if wx_password.exists:
                    # self.assertEqual(password.info['text'], u'密码')
                    wx_password.clear_text()
                    wx_password.set_text(constants.TEST_WX_PASSWD)
                    time.sleep(2)

                wx_loginbtn = self.d(resourceId="com.alibaba.mobileim:id/loginButton", className="android.widget.Button")
                if wx_loginbtn.exists:
                    self.assertEqual(wx_loginbtn.info['text'], u'登录')
                    wx_loginbtn.click()
                    #mobileimimg = self.d(resourceId='com.alibaba.mobileim:id/wxheadImage', className='android.widget.TextView', packageName='com.alibaba.mobileim')
                    start=time.time()
                    while time.time()-start<constants.Time_Out:
                        if self.d(resourceId='com.alibaba.mobileim:id/tab_me_text').exists:
                            break
                        else:
                            time.sleep(1)

                #whether update dialog appear, if click cancel button, if not run else operation
                if self.d(resourceId="com.alibaba.mobileim:id/pcenterPanel", className="android.widget.LinearLayout").exists:
                    update_cancelBtn = self.d(resourceId="com.alibaba.mobileim:id/button2", className="android.widget.Button")
                    if not update_cancelBtn.exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(update_cancelBtn.exists)
                    if update_cancelBtn.exists:
                        update_cancelBtn.click()
                        time.sleep(1)
  
    def test_SendMessage(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendMessage')
        tab_friends = self.d(resourceId="com.alibaba.mobileim:id/tab_friends_text", className="android.widget.ImageView")
        self.assertTrue(tab_friends.info["clickable"])
        if tab_friends.exists:
            tab_friends.click()
            time.sleep(1)
            FriendTag=self.d(resourceId='com.alibaba.mobileim:id/friends_layout',packageName='com.alibaba.mobileim')
            FriendTag.click()
            time.sleep(2)
            Friends=self.d(text='tb3489593',resourceId='com.alibaba.mobileim:id/select_name')
            self.assertTrue(Friends.exists)
            Friends.click()
            time.sleep(1)
            
            #进入发送消息对话框
            #check friend's ID
            chat_title = self.d(resourceId="com.alibaba.mobileim:id/chat_title", className="android.widget.TextView")
            self.assertEqual(chat_title.info['text'], constants.TEST_REMOTE_USERNAME)
            #send text message
            chat_inputtext = self.d(resourceId="com.alibaba.mobileim:id/chat_inputtext", className="android.widget.EditText")
            if not chat_inputtext.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(chat_inputtext.exists)
            if chat_inputtext.exists:
                chat_inputtext.click()
                chat_inputtext.clear_text()
                #切换输入法
#                 self.d.press(113,1)
  
                chat_inputtext.set_text("hello, nice to meet you ")
                time.sleep(1)
                if self.d(text="发送", className="android.widget.Button").exists:
                    self.d(text="发送", className="android.widget.Button").click()
                else:
                    logger.info(u"发送按钮不存在")
                    pass
            #send emotion image
            #进入表情选择界面
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                emotion = self.d(text=u"表情", className="android.widget.TextView")
                if not emotion.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(emotion.exists)
                if emotion.exists:
                    emotion.click()
                    time.sleep(1)
                    if self.d(text=u"阿里旺旺表情").exists:
                        self.d(text=u"阿里旺旺表情").click()
                        time.sleep(1)
                    # smily_scroller = self.d(resourceId="com.alibaba.mobileim:id/smily_scroller",className="android.widget.FrameLayout")
                    # if not smily_scroller.exists:
                    #     name = sys._getframe().f_code.co_name
                    #     screen_shot.ScreenShot(self,name)
                    # self.assertTrue(smily_scroller.exists)
                    # if smily_scroller.exists:
                    #     # 表情选取坐标起始值:Sx = 655 , Sy = 830 表情间距: Dx = 102, Dy = 55
                    #     Sx = 655
                    #     Sy = 830
                    #     Dx = 102
                    #     Dy = 55
                    #     # 表情页滑动起始和结束坐标点
                    #     startx = smily_scroller.info['visibleBounds']['left'] + 50
                    #     starty = smily_scroller.info['visibleBounds']['top'] + 80
                    #     endx = smily_scroller.info['visibleBounds']['left'] + 660
                    #     endy = starty
                    #
                    #     Nx = random.randint(0, 6)
                    #     Ny = random.randint(0, 2)
                    #     if Ny == 2 and Nx == 6:
                    #         Nx = Nx - 1
                    #     else:
                    #         pass
                    #
                    #     for i in range(random.randint(0, 4)):
                    #         self.d.drag(startx, starty, endx, endy, steps=10)
                    #         time.sleep(1)
                    #     self.d.click(Sx + Nx * Dx, Sy + Ny * Dy)
                    #
                        #select emotion
                        emotion_icon = self.d(resourceId='com.alibaba.mobileim:id/image', className='android.widget.ImageView')
                        self.assertTrue(emotion_icon.info['enabled'])
                        if emotion_icon.exists:
                            emotion_icon.click()
                            time.sleep(1)
                        if self.d(text="发送", className="android.widget.Button").exists:
                            self.d(text="发送", className="android.widget.Button").click()
                        else:
                            logger.info(u"发送按钮不存在")
                            pass
                    #淘公仔表情
                    if self.d(text="淘公仔表情", className="android.widget.RadioButton").exists:
                        self.d(text="淘公仔表情", className="android.widget.RadioButton").click()
                        smile_layout = self.d(resourceId="com.alibaba.mobileim:id/smile_layout", className="android.widget.LinearLayout")
                        if not smile_layout.exists:
                            name = sys._getframe().f_code.co_name
                            screen_shot.ScreenShot(self,name)
                        self.assertTrue(smile_layout.exists)
                        #logger.info("click the emotion.")
                        if smile_layout.exists:
                            time.sleep(1)
                            #获取第一个淘公仔的坐标点
                            x = smile_layout.info['visibleBounds']['left'] +80
                            y = smile_layout.info['visibleBounds']['top'] +40
                            self.d.click(x, y)
                            time.sleep(1)
            #返回主界面
            title_back = self.d(resourceId="com.alibaba.mobileim:id/title_back", className="android.widget.TextView")
            # self.assertTrue(title_back.info['clickable'])
            if title_back.exists:
                title_back.click()
                time.sleep(1)
                title_back.click()
                time.sleep(1)
 
        logger.info('Exit --  MUAT:MobileImTest:test_SendMessage')
  
    def test_SendtakePhoto(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendtakePhoto')
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.ImageView")
        # self.assertTrue(tab_message.info['enabled'])
        if tab_message.exists:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择拍照发送
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                takepic = self.d(text=u"拍照", className="android.widget.TextView")
                if not takepic.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(takepic.exists)
                if takepic.exists:
                    takepic.click()
                    camera = self.d(resourceId="com.android.camera2:id/shutter_button", className="android.widget.ImageView", packageName="com.android.camera2")
                    start=time.time()
                    while time.time()-start<constants.Time_Out:
                        if  camera.exists:
                            break
                        else:
                            time.sleep(1)
                    #调用系统的相机拍摄照片
                    self.assertEqual(camera.info['contentDescription'], u'快门')
                    if camera.exists:
                        camera.click()
                        btn_done = self.d(resourceId="com.android.camera2:id/btn_done", className="android.widget.ImageView", packageName="com.android.camera2")
                        start=time.time()
                        while time.time()-start<constants.Time_Out:
                            if  btn_done.exists:
                                break
                            else:
                                time.sleep(1)
                        #确认完成拍照
                        self.assertEqual(btn_done.info['contentDescription'], u'完成')
                        if btn_done.exists:
                            btn_done.click()
                            btn_confirm = self.d(resourceId="com.alibaba.mobileim:id/confirm", className="android.widget.Button", packageName="com.alibaba.mobileim")
                            start=time.time()
                            while time.time()-start<constants.Time_Out:
                                if  btn_confirm.exists:
                                    break
                                else:
                                    time.sleep(1)
                            #点击确定按钮,发送照片
                            self.assertEqual(btn_confirm.info['text'], u'确定')
                            if btn_confirm.exists:
                                btn_confirm.click()
                                time.sleep(2)
            #返回主界面
            title_back = self.d(resourceId="com.alibaba.mobileim:id/title_back", className="android.widget.TextView")
            # self.assertTrue(title_back.info['clickable'])
            if title_back.exists:
                title_back.click()
                time.sleep(1)
                title_back.click()
                time.sleep(1)
  
  
        logger.info('Exit --  MUAT:MobileImTest:test_SendtakePhoto')
 
    def test_SendCard(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendCard')
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.ImageView")
        self.assertTrue(tab_message.info['enabled'])
        if tab_message.info['clickable']:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择名片
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                card_btn = self.d(text=u"名片", className="android.widget.TextView")
                if not card_btn.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(card_btn.exists)
                if card_btn.exists:
                    card_btn.click()
                    time.sleep(3)
                    #进入选择好友界面,选择好友,并发送
                    wx_friends_btn = self.d(resourceId="com.alibaba.mobileim:id/wx_friends_button", className="android.widget.Button")
                    self.assertEqual(wx_friends_btn.info['text'], u'旺旺好友')
                    if wx_friends_btn.exists:
                        wx_friends_btn.click()
                        time.sleep(1)
                        #选择 景止、洗石、云渡
                        # self.d(text=u"景止").click()
                        self.d(text=u'旺信团队').click()
#                         time.sleep(1)
#                         self.d(text=u"洗石").click()
#                         time.sleep(1)
#                         self.d(text=u"云渡").click()
#                         time.sleep(1)
                        #点击确定按钮
                        startbtn = self.d(resourceId="com.alibaba.mobileim:id/start", className="android.widget.Button")
                        if not startbtn.exists:
                            name = sys._getframe().f_code.co_name
                            screen_shot.ScreenShot(self,name)
                        self.assertTrue(startbtn.exists)
                        if startbtn.exists:
                            startbtn.click()
                            time.sleep(1)
            #返回主界面
            # chat_back = self.d(resourceId="com.alibaba.mobileim:id/chat_back", className="android.widget.TextView")
            # self.assertTrue(chat_back.info['enabled'])
            # if chat_back.info['clickable']:
            #     chat_back.click()
            #     time.sleep(1)
            title_back = self.d(resourceId="com.alibaba.mobileim:id/title_back", className="android.widget.TextView")
            # self.assertTrue(title_back.info['clickable'])
            if title_back.exists:
                title_back.click()
                time.sleep(1)
                title_back.click()
                time.sleep(1)
 
        logger.info('Exit --  MUAT:MobileImTest:test_SendCard')
 
    def test_SendPicture(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendPicture')
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.ImageView")
        self.assertTrue(tab_message.info['enabled'])
        if tab_message.info['clickable']:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            PlusButton = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not PlusButton.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(PlusButton.exists)
            if PlusButton.exists:
                PlusButton.click()
                selectpic_btn = self.d(text=u"选择照片", className="android.widget.TextView")
                if not selectpic_btn.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(selectpic_btn.exists)
                if selectpic_btn.exists:
                    selectpic_btn.click()
                    time.sleep(1)
                    pic = self.d(resourceId="com.alibaba.mobileim:id/image_item", className="android.widget.ImageView")
                    if not pic.exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(pic.exists)
                    self.d(resourceId='com.alibaba.mobileim:id/image_check',packageName='com.alibaba.mobileim').click()
                        #点击完成, 发送图片
#                             self.d(resourceId="com.alibaba.mobileim:id/select_finish", className="android.widget.Button").click()
                    TitleBar=self.d(resourceId='android:id/pc_titlebar',packageName='com.alibaba.mobileim')
                    click_x=TitleBar.info['visibleBounds']['right']-30
                    click_y=TitleBar.info['visibleBounds']['bottom']+20
                    self.mouse.click(click_x, click_y, constants.MouseLeftKey)
                    
#                     select_finish = self.d(resourceId="com.alibaba.mobileim:id/finish", className="android.widget.Button")
#                     self.assertEqual(select_finish.info['text'], u'发送')
#                     select_finish.click()
                    time.sleep(2)
            #返回主界面
            title_back = self.d(resourceId="com.alibaba.mobileim:id/title_back", className="android.widget.TextView")
            # self.assertTrue(title_back.info['clickable'])
            if title_back.exists:
                title_back.click()
                time.sleep(1)
                title_back.click()
                time.sleep(1)
  
        logger.info('Exit --  MUAT:MobileImTest:test_SendPicture')
  
    def test_SendVoice(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendVoice')
  
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.ImageView")
        self.assertTrue(tab_message.info['enabled'])
        if tab_message.info['clickable']:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择名片
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                voice_btn = self.d(text=u"语音消息", className="android.widget.TextView")
                if not voice_btn.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(voice_btn.exists)
                if voice_btn.exists:
                    voice_btn.click()
                    time.sleep(3)
                #长按,启动语音录音
                chat_record = self.d(resourceId="com.alibaba.mobileim:id/chat_record", className="android.widget.Button")
                self.assertEqual(chat_record.info['text'], u'请长按讲话')
                if chat_record.exists:
                    '''
                    还没有解决长按的方法,暂时用long_click()
                    '''
                    chat_record.long_click()
                    time.sleep(2)
        #返回主界面
            title_back = self.d(resourceId="com.alibaba.mobileim:id/title_back", className="android.widget.TextView")
            # self.assertTrue(title_back.info['clickable'])
            if title_back.exists:
                title_back.click()
                time.sleep(1)
                title_back.click()
                time.sleep(1)
  
        logger.info('Exit --  MUAT:MobileImTest:test_SendVoice')
 
    def test_ModifyInfo(self):
        logger.info('Enter -- MUAT:MobileImTest:test_ModifyInfo')
        meButton=self.d(resourceId='com.alibaba.mobileim:id/tab_me_text')
        if meButton.exists:
            meButton.click()
            time.sleep(2)
#                 moreButton=self.d(text=u'更多',packageName='com.alibaba.mobileim')
#                 if moreButton.exists:
#                     moreButton.click()
#                     time.sleep(2)
            if not self.d(text=u'设置', packageName='com.alibaba.mobileim').exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(self.d(text=u'设置', packageName='com.alibaba.mobileim').exists)
            profileButton = self.d(text=u'个人资料', packageName='com.alibaba.mobileim')
            #modify profile
            if profileButton.exists:
                profileButton.click()
                time.sleep(2)
                profileName=self.d(resourceId='com.alibaba.mobileim:id/profile_name')
                profileName.click()
                time.sleep(2)
                ModifyName=self.d(resourceId='com.alibaba.mobileim:id/modify_group_name',className='android.widget.EditText')
                cancelButton=self.d(resourceId='com.alibaba.mobileim:id/modify_cancel',className='android.widget.ImageView')
                cancelButton.click()
                #ModifyName.clear_text()
                #切换输入法
#                 self.d.press(113,1)
                ModifyName.set_text("who are you")
                time.sleep(2)
                okButton=self.d(text=u'完成',resourceId='com.alibaba.mobileim:id/title_button')
                if okButton.exists:
                    okButton.click()
                    time.sleep(2)
                    self.assertEqual(profileName.info['text'], "who are you")
                    profileName.click()
                    time.sleep(2)
                    cancelButton.click()
                    #切换输入法
#                     self.d.press(113,1)
                    ModifyName.set_text("tester_1")
                    time.sleep(2)
                    okButton.click()
                    self.assertEqual(profileName.info['text'], "tester_1")
                #modify male
                profileSex=self.d(resourceId='com.alibaba.mobileim:id/setting_profile_gender')
                if profileSex.exists:
                    if not profileSex.info['text'] == u'男':
                        profileSex.click()
                        time.sleep(2)
                        self.d(resourceId='com.alibaba.mobileim:id/profile_gender_male').click()
                        time.sleep(2)
                        self.assertEqual(profileSex.info['text'], u'男')
                    else:
                        profileSex.click()
                        time.sleep(2)
                        self.d(resourceId='com.alibaba.mobileim:id/profile_gender_female').click()
                        time.sleep(2)
                        self.assertEqual(profileSex.info['text'], u'女')
                #modify area
                profileAddress=self.d(resourceId='com.alibaba.mobileim:id/setting_profile_address')
                area_title=self.d(resourceId='com.alibaba.mobileim:id/title')
                bj1_x=area_title.info['visibleBounds']['right'] - 20
                bj1_y=area_title.info['visibleBounds']['bottom'] + 20
                bj2_x=bj1_x
                bj2_y=bj1_y + 44
                tj1_x=bj1_x
                tj1_y=bj2_y
                tj2_x=bj1_x
                tj2_y=bj2_y + 44
                if profileAddress.exists:
                    profileAddress.click()
                    time.sleep(2)
                    self.d.click(bj1_x,bj1_y)
                    time.sleep(2)
                    self.d.click(bj2_x,bj2_y)
                    time.sleep(2)
                    self.assertEqual(profileAddress.info['text'], u'北京 北京')
                    profileAddress.click()
                    time.sleep(2)
                    self.d.click(tj1_x,tj1_y)
                    time.sleep(2)
                    self.d.click(tj2_x,tj2_y)
                    time.sleep(2)
                    self.assertEqual(profileAddress.info['text'], u'天津 天津')
                    time.sleep(2)
                        
                #更换头像
                self.d(resourceId='com.alibaba.mobileim:id/title_back').click()
                profileHead=self.d(resourceId='com.alibaba.mobileim:id/people_head')
                if profileHead.exists:
                    profileHead.click()
                    TakePicture=self.d(text=u'拍照',resourceId='android:id/text1')
                    if TakePicture.exists:
                        TakePicture.click()
                        start=time.time()
                        while time.time()-start<constants.Time_Out:
                            if  self.d(resourceId='com.android.camera2:id/shutter_button').exists:
                                break
                            else:
                                time.sleep(1)
                        self.d(resourceId='com.android.camera2:id/shutter_button').click()
                        doneButton=self.d(resourceId='com.android.camera2:id/btn_done')
                        start=time.time()
                        while time.time()-start<constants.Time_Out:
                            if  doneButton.exists:
                                break
                            else:
                                time.sleep(1)
                        doneButton.click()
                        saveButton=self.d(resourceId='com.alibaba.mobileim:id/save')
                        start=time.time()
                        while time.time()-start<constants.Time_Out:
                            if  saveButton.exists:
                                break
                            else:
                                time.sleep(1)
                        saveButton.click()
                        time.sleep(2)
        logger.info('Exit -- MUAT:MobileImTest:test_ModifyInfo')
 
    def test_CheckInfo(self):
        logger.info('Enter -- MUAT:MobileImTest:test_CheckInfo')
  
        MobileimTitle=self.d(resourceId='android:id/pc_title')
        if not MobileimTitle.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(MobileimTitle.exists)
        if MobileimTitle.exists:
            MobileimTitle.click()
            logger.info('MobileimTitle is here')
            time.sleep(1)
  
        MessageButton=self.d(resourceId='com.alibaba.mobileim:id/tab_message_text')
        if not MessageButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(MessageButton.exists)
        if MessageButton.exists:
            MessageButton.click()
            logger.info('Message is here')
            time.sleep(1)
        FriendsButton=self.d(resourceId='com.alibaba.mobileim:id/tab_friends_text')
        if not FriendsButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(FriendsButton.exists)
        if FriendsButton.exists:
            FriendsButton.click()
            logger.info('Friends is here')
            SearchButton=self.d(resourceId='com.alibaba.mobileim:id/search_layout')
            if not SearchButton.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(SearchButton.exists)
            ShopButton=self.d(resourceId='com.alibaba.mobileim:id/shop_layout')
            if not ShopButton.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(ShopButton.exists)
            if ShopButton.exists:
                ShopButton.click()
                logger.info('Shop is here')
                time.sleep(1)
            GuyBtton=self.d(resourceId='com.alibaba.mobileim:id/friends_layout')
            self.assertTrue(GuyBtton.exists)
            if GuyBtton.exists:
                GuyBtton.click()
                logger.info('Guys is here')
                time.sleep(1)
            GruopButton=self.d(resourceId='com.alibaba.mobileim:id/tribe_layout')
            self.assertTrue(GruopButton.exists)
            if GruopButton.exists:
                GruopButton.click()
                logger.info('Gruop is here')
                time.sleep(1)
  
        CornerButton=self.d(resourceId='com.alibaba.mobileim:id/hangjia_iv')
        self.assertTrue(CornerButton.exists)
        if CornerButton.exists:
            CornerButton.click()
            logger.info('hangjia is here')
            CancelButton=self.d(text=u'取消',resourceId='com.alibaba.mobileim:id/button2')
            if CancelButton.exists:
                CancelButton.click()
                time.sleep(1)
            
#         MJX=self.d(resourceId='com.alibaba.mobileim:id/mjx_iv')
#         self.assertTrue(MJX.exists)
#         if MJX.exists:
#             MJX.click()
#             logger.info('MJX is here')
#             time.sleep(1)
#             self.d.press(0x42)
            
  
        MeButton=self.d(resourceId='com.alibaba.mobileim:id/tab_me_text')
        self.assertTrue(MeButton.exists)
        if MeButton.exists:
            MeButton.click()
            logger.info('Me is here')
            time.sleep(1)
  
        MaxBtton=self.d(resourceId='android:id/pc_max')
        if not MaxBtton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(MaxBtton.exists)
        if MaxBtton.exists:
            MaxBtton.click()
            time.sleep(2)
            MaxBtton.click()
            time.sleep(2)
 
        # closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        # if closeButton.exists:
        #     closeButton.click()
        #     time.sleep(3)
        logger.info('Exit -- MUAT:MobileImTest:test_CheckInfo')

#     def test_Drag(self):
#         logger.info('Enter -- MUAT:MobileImTest:test_Drag')
#         self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
#         time.sleep(5)
#         Button2=self.d(text=u'取消',resourceId='com.alibaba.mobileim:id/button2')
#         if Button2.exists:
#             Button2.click()
#         #登陆
#         LoginButton=self.d(resourceId='com.alibaba.mobileim:id/login')
#         if LoginButton.exists:
#             LoginButton.click()
#             LoginButton.click()
#             time.sleep(5)
#         #拖拉窗口
#         meButton=self.d(resourceId='com.alibaba.mobileim:id/tab_me_text')
#         start_x=meButton.info['visibleBounds']['right']
#         start_y=meButton.info['visibleBounds']['bottom']
#         end_x  =start_x + 100
#         end_x0 =start_x - 100
#         end_y  =start_y + 50
#         self.d.drag(start_x,start_y,end_x,end_y,steps=1)
#         self.d.drag(start_x,start_y,end_x0,end_y)
#         time.sleep(3)

        # closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        # if closeButton.exists:
        #     closeButton.click()
        #     time.sleep(3)
        # logger.info('Exit -- MUAT:SettingsSystemTest:test_Drag')

    def tearDown(self):
        # tab_me test
        tab_me = self.d(resourceId="com.alibaba.mobileim:id/tab_me_text", className="android.widget.ImageView")
        # self.assertTrue(tab_me.info['clickable'])

#         if tab_me.exists:
#             tab_me.click()
#             time.sleep(1)
# 
#             myname = self.d(resourceId="com.alibaba.mobileim:id/title_text", className="android.widget.TextView")
#             self.assertEqual(myname.info['text'], 'tester_1')
# 
#             # setting button
#             setting_btn = self.d(resourceId="com.alibaba.mobileim:id/setting", className="android.widget.Button")
#             self.assertEqual(setting_btn.info['text'], u'设置')
# 
#             if setting_btn.exists:
#                 setting_btn.click()
#                 time.sleep(2)
# 
#             # account logout
#             logout_btn = self.d(resourceId='com.alibaba.mobileim:id/setting_logout')
#             self.assertEqual(logout_btn.info['text'], u'退出登录')
# 
#             if logout_btn.exists:
#                 logout_btn.click()
#                 time.sleep(1)
# 
#             exit_massege = self.d(resourceId="com.alibaba.mobileim:id/message", className="android.widget.TextView")
#             self.assertEqual(exit_massege.info['text'], u'退出后您将收不到新消息通知,是否确认退出?')
#             time.sleep(1)
#             if exit_massege.exists:
#                 self.d(resourceId="com.alibaba.mobileim:id/button1", className="android.widget.Button").click()
#                 time.sleep(2)
# 
#             accountClearButton = self.d(resourceId="com.alibaba.mobileim:id/accountClearButton", className="android.widget.TextView")
#             if not accountClearButton.exists:
#                 name = sys._getframe().f_code.co_name
#                 screen_shot.ScreenShot(self, name)
#                 time.sleep(3)
#             elif accountClearButton.exists:
#                 accountClearButton.click()
#                 time.sleep(1)

        closebtn = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        #self.assertTure(closebtn.exists)

        if closebtn.exists:
            logger.debug('click close button: (%s)' % (closebtn.info['packageName']))
            closebtn.click()
        #logger.info("EXIT -- MUAT:MobileImTest:close_mobileim")
        self.adb_tools.adb_shell('am force-stop com.alibaba.mobileim')
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")
    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)
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 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 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 ChromeTest(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()
		time.sleep(5)

	def tearDown(self):
		BaseImg = os.path.join(self.BaseImagePath, "test_TaskBar1.jpg")
		name = "test_TaskBar1_%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, 125,1040,710,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"))
		
		#open youku
		logger.info('close the youku application................')
		self.adb_tools.adb_shell('am force-stop com.youku.phone.x86')
		time.sleep(2)
		#open ttpod
		logger.info('close the ttpod application................')
		self.adb_tools.adb_shell("am force-stop com.sds.android.ttpod")
		time.sleep(2)
		#open QQ
		logger.info('close QQ application.......................')
		self.adb_tools.adb_shell("am force-stop com.tencent.mobileqq")
		time.sleep(2)
		#open xiami
		logger.info('close xiami application.......................')
		self.adb_tools.adb_shell("am force-stop fm.xiami.main")
		time.sleep(2)
		#open qianniu
		logger.info('close qianniiu application.......................')
		self.adb_tools.adb_shell('am force-stop com.taobao.qianniu')
		time.sleep(2)
		#open 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)
		#open gaode map
		logger.info('close minimap application.......................')
		self.adb_tools.adb_shell("am force-stop com.autonavi.minimap")
		time.sleep(2)
		#open wangxin
		logger.info('close mobileim application.......................')
		self.adb_tools.adb_shell("am force-stop com.alibaba.mobileim")
		time.sleep(2)
		#open taobao
		logger.info('close taobaoHD application.......................')
		self.adb_tools.adb_shell("am force-stop com.taobao.apad")
		time.sleep(2)
		#open alilang
		logger.info('close alilang application.......................')
		self.adb_tools.adb_shell("am force-stop com.alibaba.android.security.activity")
		time.sleep(2)
		self.account.logout()

	def test_OpenChromeTab(self):
		logger.info('Enter -- MUAT:ChromeTest:test_OpenChromeTab')
		#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 alilang
# 		logger.info('open alilang application.......................')
# 		self.adb_tools.adb_shell("am start -n com.alibaba.android.security.activity/.WelcomeActivity")
# 		time.sleep(3)
		getcpuinfo("after open 10 app.....\n")
		time.sleep(10)
		#browser
		self.adb_tools.adb_shell("am start -n com.android.browser/.BrowserActivity")
		time.sleep(3)
		url = self.d(resourceId='com.android.browser:id/url', className='android.widget.EditText', packageName='com.android.browser')
		url.clear_text()
		url.set_text('cun.taobao.com')
		self.d.press(0x42)
		time.sleep(3)
		getcpuinfo("after open 1 tab....\n")
		for i in range(15):
			tabbtn = self.d(resourceId='com.android.browser:id/newtab')
			tabbtn.click()
			time.sleep(2)
			url = self.d(resourceId='com.android.browser:id/url')
			url.clear_text()
			url.set_text("cun.taobao.com")
			self.d.press(0x42)
			time.sleep(3)
			info = "open %s tab...\n" % (i+2)
			getcpuinfo(info)


		time.sleep(10)
		closebtn = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.android.browser")
		closebtn.click()
		time.sleep(3)
		getcpuinfo("after close the browser......\n")
		time.sleep(10)
		#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)
		# url_bar = self.d(resourceId='org.chromium.chrome:id/url_bar')
		# url_bar.click()
		# url_bar.clear_text()
		# url_bar.set_text("cun.taobao.com")
		# self.d.press(0x42)
		# time.sleep(5)
		getcpuinfo("after open chrome 1 tab.....\n")
		# d = Device('F3YMD3000812')
		# d.press(0x3e, 0x71)
		time.sleep(10)
		for i in range(15):
			# d.press(0x30, 0x71)
			# new_tab = self.d(resourceId='empty_new_tab_button')
			# new_tab.click()
			# time.sleep(3)
			# url_bar = self.d(resourceId='org.chromium.chrome:id/url_bar')
			# url_bar.click()
			# url_bar.clear_text()
			# url_bar.set_text("cun.taobao.com")
			# self.d.press(0x42)
			# time.sleep(5)
			# self.d(className='android.view.View').child(index=0).click()
			#self.mouse.click(940, 466, constants.MouseLeftKey)
			time.sleep(1)
			self.d(resourceId='org.chromium.chrome:id/menu_button', className='android.widget.ImageButton').click()
			time.sleep(2)
			self.d(resourceId='org.chromium.chrome:id/menu_item_text').click()
			time.sleep(1)
			url_bar = self.d(resourceId='org.chromium.chrome:id/url_bar')
			url_bar.clear_text()
			url_bar.set_text("cun.taobao.com")
			self.d.press(0x42)
			time.sleep(2)
# 			self.d(resourceId='org.chromium.chrome:id/title').click()
# 			time.sleep(10)
			str ='after open chrome %s tab...\n' % (i+2)
			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 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)
        self.adb_tools.adb_shell('am force-stop com.alibaba.mobileim')
        time.sleep(2)
        # self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
        self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/.ui.tab.MainTabActivity')
#        /.ui.tab.MainTabActivity  /com.alibaba.mobileim.SplashActivity
        mobileimdialog = self.d(resourceId='android:id/pc_title', className='android.widget.TextView', packageName='com.alibaba.mobileim')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  mobileimdialog.exists:
                break
            else:
                time.sleep(1)
        if not mobileimdialog.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(mobileimdialog.exists)
        if mobileimdialog.exists:
            if self.d(resourceId="com.alibaba.mobileim:id/guide_image_one", className="android.widget.ImageView").exists:
                CustomViewPager = self.d(resourceId="com.alibaba.mobileim:id/container", className="com.alibaba.mobileim.fundamental.widget.CustomViewPager")
                if CustomViewPager.exsits:
                    #startX = CustomViewPager.info
                    logger.debug('CustomViewPager: (%s)' % (CustomViewPager.info['className']))
            else:
                #input wangxin login account:
                wx_account = self.d(resourceId="com.alibaba.mobileim:id/accountCompleteTextView", className="android.widget.EditText")
                if wx_account.exists and wx_account.info['text'] == constants.TEST_WX_USERNAME:
                    pass

                elif wx_account.exists and wx_account.info['text'] == u'淘宝帐号/手机号':
                    #self.assertEqual(wx_account.info['text'], u"淘宝帐号/手机号")
                    wx_account.clear_text()
                    time.sleep(2)
                    wx_account.set_text(constants.TEST_WX_USERNAME)
                    time.sleep(2)

                #input wangxin login password
                wx_password = self.d(resourceId="com.alibaba.mobileim:id/content", className="android.widget.EditText")
                if wx_password.exists:
                    # self.assertEqual(password.info['text'], u'密码')
                    wx_password.clear_text()
                    wx_password.set_text(constants.TEST_WX_PASSWD)
                    time.sleep(2)

                wx_loginbtn = self.d(resourceId="com.alibaba.mobileim:id/loginButton", className="android.widget.Button")
                if wx_loginbtn.exists:
                    self.assertEqual(wx_loginbtn.info['text'], u'登录')
                    wx_loginbtn.click()
                    #mobileimimg = self.d(resourceId='com.alibaba.mobileim:id/wxheadImage', className='android.widget.TextView', packageName='com.alibaba.mobileim')
                    start=time.time()
                    while time.time()-start<constants.Time_Out:
                        if self.d(resourceId='com.alibaba.mobileim:id/tab_me_text').exists:
                            break
                        else:
                            time.sleep(1)

                #whether update dialog appear, if click cancel button, if not run else operation
                if self.d(resourceId="com.alibaba.mobileim:id/pcenterPanel", className="android.widget.LinearLayout").exists:
                    update_cancelBtn = self.d(resourceId="com.alibaba.mobileim:id/button2", className="android.widget.Button")
                    if not update_cancelBtn.exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(update_cancelBtn.exists)
                    if update_cancelBtn.exists:
                        update_cancelBtn.click()
                        time.sleep(1)
class SettingTest(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.account.sleep()
        self.account.wakeup()
        self.account.login()

    def tearDown(self):
        self.account.sleep()

    def test_mpc_settings(self):
        logger.info('Enter -- MPT:SettingsTest:test_mpc_settings')
        value = {}
        report = MuatReport()
        serial_number = None
        if self.param and self.param.parameters and self.param.parameters.serial_number:
            serial_number = self.param.parameters.serial_number

        apk_manager = ApkManager()
        apk = constants.MPT_SETTING_APK
        apk_info = apk_manager.get_apk_info(apk)

        if apk in apk_manager.local_apks_info:
            while True:
                for i in range(constants.MPT_SETTING_COUNT):
                    # check monitor running status
                    if self.mon and not self.mon.running_status:
                        break

                    # start apk
                    apk_manager.start_apk(apk, serial_number=serial_number)
                    time.sleep(1)

                    for resource_id in constants.MPT_SETTING_APK_RESOURCEIDS:
                        # check monitor running status
                        if self.mon and not self.mon.running_status:
                            break

                        # start adb log capture thread
                        detect_re = re.compile(r'MPT click UiSelector.PACKAGE NAME=%s, RESOURCE_ID=(%s:id/%s). at (.*)$' % (apk_info.package_name, apk_info.package_name, resource_id))
                        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 setting items
                        button = self.d(packageName=apk_info.package_name, resourceId='%s:id/%s' % (apk_info.package_name, resource_id))
                        if button.exists:
                            logger.debug('click item (%s)' % (resource_id))
                            button.click()
                            time.sleep(2)
                        else:
                            logger.warning('not found item(%s)' % (resource_id))

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

                        # store the result
                        click_item = ''
                        start_time = 0
                        end_time = 0
                        cost_time = 0
                        try:
                            click_item      = adb_log.result[0][0]
                            start_time      = int(adb_log.result[0][1])
                            end_time        = int(adb_log.result[1][0])
                            if click_item == '%s:id/%s' % (apk_info.package_name, resource_id):
                                cost_time = end_time - start_time
                            else:
                                logger.error('detect_re detect the wrong item: (%s)' % (adb_log.result[0]))
                        except:
                            logger.error('retrieve time from (%s) error' % (adb_log.result))

                        logger.info('setting item(%s) cost: %s' % (resource_id, cost_time))

                        if resource_id in value:
                            value[resource_id].append(cost_time)
                        else:
                            value[resource_id] = [cost_time]

                        # report message
                        report.add_message(data_name='muat_setting', MON_Time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), item=resource_id, unit='ms', value=cost_time, item_name=constants.MPT_SETTING_APK_RESOURCEIDS_CN[resource_id].decode('gb2312'))

                        adb_log.join()

                    # close apk
                    apk_manager.close_apk(apk)

                if self.mon and not self.mon.running_status:
                    break

                if self.param and self.param.parameters and self.param.parameters.special_keys and 'run_one_cycle' in self.param.parameters.special_keys:
                    break

        if value:
            logger.debug('setting test : %s' % (value))
            #result_items = []
            summary = {}
            for resource_id in value:
                summary[resource_id] = sum(value[resource_id]) / len(value[resource_id])
                #result_items.append(summary[resource_id])
            #summary[constants.MPT_SETTING_RESULT_TOTAL] = sum(result_items) / len(result_items)
            logger.debug('setting test - summary: %s' % (summary))

            result = GenerateResult(case=os.path.basename(os.path.abspath(__file__)), unit='ms', standard=0, summary=summary, value=value)
            if result.result:
                report.add_result(result.result)
        else:
            logger.error('setting test failed')
    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)
class MobileImTest(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)
        # if self.adb_tools.adb_shell('ls -al /mydata/app/com.alibaba.mobileim-1.apk'):
        #     self.adb_tools.adb_push('')
        self.adb_tools.adb_shell('am force-stop com.alibaba.mobileim')
        time.sleep(2)
        self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
        mobileimdialog = self.d(resourceId='android:id/pc_title', className='android.widget.TextView', packageName='com.alibaba.mobileim')
        start=time.time()
        while time.time()-start<constants.Time_Out:
            if  mobileimdialog.exists:
                break
            else:
                time.sleep(1)
        if not mobileimdialog.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(mobileimdialog.exists)
        #if wangxin start , run login
        #  @wb-zhaoxinjian
        if mobileimdialog.exists:
            if self.d(resourceId="com.alibaba.mobileim:id/guide_image_one", className="android.widget.ImageView").exists:
                CustomViewPager = self.d(resourceId="com.alibaba.mobileim:id/container", className="com.alibaba.mobileim.fundamental.widget.CustomViewPager")
                if CustomViewPager.exsits:
                    #startX = CustomViewPager.info
                    logger.debug('CustomViewPager: (%s)' % (CustomViewPager.info['className']))
            else:
                #input wangxin login account:
                wx_account = self.d(resourceId="com.alibaba.mobileim:id/account", className="android.widget.EditText")
                if wx_account.exists and wx_account.info['text'] == u'淘宝帐号/手机号':
                    #self.assertEqual(wx_account.info['text'], u"淘宝帐号/手机号")
                    wx_account.clear_text()
                    time.sleep(2)
                    wx_account.set_text(constants.TEST_WX_USERNAME)
                    time.sleep(2)
                elif wx_account.exists and wx_account.info['text'] == constants.TEST_WX_USERNAME:
                    pass

                #input wangxin login password
                wx_password = self.d(resourceId="com.alibaba.mobileim:id/password", className="android.widget.EditText")
                if wx_password.exists:
                    # self.assertEqual(password.info['text'], u'密码')
                    wx_password.clear_text()
                    wx_password.set_text(constants.TEST_WX_PASSWD)
                    time.sleep(2)

                wx_loginbtn = self.d(resourceId="com.alibaba.mobileim:id/login", className="android.widget.Button")
                if wx_loginbtn.exists:
                    self.assertEqual(wx_loginbtn.info['text'], u'登录')
                    wx_loginbtn.click()
                    start=time.time()
                    while time.time()-start<constants.Time_Out:
                        if not wx_loginbtn.exists:
                            break
                        else:
                            time.sleep(1)

                #whether update dialog appear, if click cancel button, if not run else operation
                if self.d(resourceId="com.alibaba.mobileim:id/pcenterPanel", className="android.widget.LinearLayout").exists:
                    update_cancelBtn = self.d(resourceId="com.alibaba.mobileim:id/button2", className="android.widget.Button")
                    if not update_cancelBtn.exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(update_cancelBtn.exists)
                    if update_cancelBtn.exists:
                        update_cancelBtn.click()
                        time.sleep(1)

    def test_LoginAndLogout(self):
        logger.info('Enter -- MUAT:MobileImTest:test_LoginAndLogout')
        #这部分内容已经移到tearUp()函数中了
        # self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
        # time.sleep(5)
        # mobileimdialog = self.d(resourceId='android:id/pc_decor_content', className='android.widget.RelativeLayout', packageName='com.alibaba.mobileim')
        # self.assertTrue(mobileimdialog.exists)
        # #if wangxin start , run login
        # #  @wb-zhaoxinjian
        # if mobileimdialog.exists:
        #     if self.d(resourceId="com.alibaba.mobileim:id/guide_image_one", className="android.widget.ImageView").exists:
        #         CustomViewPager = self.d(resourceId="com.alibaba.mobileim:id/container", className="com.alibaba.mobileim.fundamental.widget.CustomViewPager")
        #         if CustomViewPager.exsits:
        #             #startX = CustomViewPager.info
        #             logger.debug('CustomViewPager: (%s)' % (CustomViewPager.info['className']))
        #     else:
        #         #input wangxin login account:
        #         wx_account = self.d(resourceId="com.alibaba.mobileim:id/account", className="android.widget.EditText")
        #         if wx_account.exists and wx_account.info['text'] == u'淘宝帐号/手机号':
        #             #self.assertEqual(wx_account.info['text'], u"淘宝帐号/手机号")
        #             wx_account.clear_text()
        #             time.sleep(2)
        #             wx_account.set_text(constants.TEST_WX_USERNAME)
        #             time.sleep(2)
        #         elif wx_account.exists and wx_account.info['text'] == constants.TEST_WX_USERNAME:
        #             pass
        #
        #         #input wangxin login password
        #         wx_password = self.d(resourceId="com.alibaba.mobileim:id/password", className="android.widget.EditText")
        #         if wx_password.exists:
        #             # self.assertEqual(password.info['text'], u'密码')
        #             wx_password.clear_text()
        #             wx_password.set_text("test1234")
        #             time.sleep(2)
        #
        #         wx_loginbtn = self.d(resourceId="com.alibaba.mobileim:id/login", className="android.widget.Button")
        #         if wx_loginbtn.exists:
        #             self.assertEqual(wx_loginbtn.info['text'], u'登录')
        #             wx_loginbtn.click()
        #             time.sleep(5)
        #
        #         #whether update dialog appear, if click cancel button, if not run else operation
        #         if self.d(resourceId="com.alibaba.mobileim:id/pcenterPanel", className="android.widget.LinearLayout").exists:
        #             update_cancelBtn = self.d(resourceId="com.alibaba.mobileim:id/button2", className="android.widget.Button")
        #             self.assertTrue(update_cancelBtn.exists)
        #             if update_cancelBtn.exists:
        #                 update_cancelBtn.click()
        #                 time.sleep(1)
 
        # check more infomation
        self_btn = self.d(resourceId="com.alibaba.mobileim:id/title_self_button", className="android.widget.TextView")
        self.assertEqual(self_btn.info['text'], u'更多')
 
        if self_btn.exists:
            self_btn.click()
            time.sleep(1)
            # more info screenshot and compare
 
            self_btn.click()
 
            # enter contact tab
        tab_friends = self.d(resourceId="com.alibaba.mobileim:id/tab_friends_text", className="android.widget.TextView")
        self.assertEqual(tab_friends.info["text"], u"联系人")
 
        if tab_friends.exists:
            tab_friends.click()
            time.sleep(1)
 
            # search friends
        friends_search = self.d(resourceId="com.alibaba.mobileim:id/friends_search_text",
                                className="android.widget.TextView")
        self.assertEqual(friends_search.info["text"], u"搜索")
 
        if friends_search.exists:
            friends_search.click()
            time.sleep(1)
 
            search_key = self.d(resourceId="com.alibaba.mobileim:id/search_key", className="android.widget.EditText")
            self.assertEqual(search_key.info['text'], u'搜索')
            if search_key.exists:
                search_key.clear_text()
                search_key.set_text('tester_1')
                time.sleep(2)
 
                searched_friend = self.d(resourceId="com.alibaba.mobileim:id/select_name",className="android.widget.TextView")
                self.assertEqual(searched_friend.info['text'], 'tester_1')
                time.sleep(2)
 
                if searched_friend.exists:
                    self.d(resourceId="com.alibaba.mobileim:id/title_button",className="android.widget.TextView").click()
 
         # tab_corner test
        tab_corner = self.d(resourceId="com.alibaba.mobileim:id/tab_corner_text", className="android.widget.TextView")
        self.assertEqual(tab_corner.info['text'], u'行家')
 
        if tab_corner.exists:
            tab_corner.click()
            time.sleep(1)
            start_x = tab_corner.info['visibleBounds']['left']
            start_y = tab_corner.info['visibleBounds']['top'] - 20
            end_x = start_x
            end_y = start_y - 820
 
            for i in range(5):
                self.d.drag(start_x, start_y, end_x, end_y, steps=20)
                time.sleep(1)
 
 
        logger.info("Exit --  MUAT:MobileImTest:test_LoginAndLogout")
 
    def test_SendMessage(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendMessage')
        #Add friends
        tab_friends = self.d(resourceId="com.alibaba.mobileim:id/tab_friends_text", className="android.widget.TextView")
        self.assertEqual(tab_friends.info["text"], u"联系人")
 
        if tab_friends.exists:
            tab_friends.click()
            time.sleep(1)
            #add_friends_btn
            add_contacts_btn = self.d(resourceId="com.alibaba.mobileim:id/title_button")
            if not add_contacts_btn.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(add_contacts_btn.exists)
            if add_contacts_btn.exists:
                add_contacts_btn.click()
                time.sleep(1)
            #添加好友界面
            title = self.d(resourceId="com.alibaba.mobileim:id/title_text", className="android.widget.TextView")
            self.assertEqual(title.info['text'], u'添加好友') #assert the dialog title
            if title.exists:
                search_text = self.d(resourceId="com.alibaba.mobileim:id/search_keyword", className="android.widget.EditText")
                self.assertEqual(search_text.info['text'], u'淘宝帐号')
                if search_text.exists:
                    search_text.clear_text()
                    search_text.set_text(constants.TEST_REMOTE_USERNAME)
 
                    search_btn = self.d(resourceId="com.alibaba.mobileim:id/search_btn", className="android.widget.Button")
                    self.assertEqual(search_btn.info['text'], u'搜索')
                    if search_btn.exists:
                        search_btn.click()
                        time.sleep(2)
            #名片页
            # add_friend_btn = self.d(text=u'添加好友', className="android.widget.Button")
            # self.assertTure(add_friend_btn.exists)
            # if add_friend_btn.exists:
            #     add_friend_btn.click()
            #     time.sleep(1)
            # #添加好友页面
            # if self.d(resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView").info['text'] == constants.TEST_REMOTE_USERNAME:
            #     confirm_msg = self.d(resourceId="com.alibaba.mobileim:id/confirm_msg", className="android.widget.EditText")
            #     self.assertTrue(confirm_msg.exists)
            #     if confirm_msg.exists:
            #         confirm_msg.clear_text()
            #         confirm_msg.set_text("Hello")
            # send_btn = self.d(text="发送", className="android.widget.TextView")
            # self.assertTrue(send_btn.exists)
            # if send_btn.exists:
            #     send_btn.click()
            #     time.sleep(2)
            btn_send_msg = self.d(resourceId="com.alibaba.mobileim:id/btn_send_message", className="android.widget.Button")
            if not btn_send_msg.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(btn_send_msg.exists)
            if btn_send_msg.exists:
                btn_send_msg.click()
            #进入发送消息对话框
            #check friend's ID
            chat_title = self.d(resourceId="com.alibaba.mobileim:id/chat_title", className="android.widget.TextView")
            self.assertEqual(chat_title.info['text'], constants.TEST_REMOTE_USERNAME)
            #send text message
            chat_inputtext = self.d(resourceId="com.alibaba.mobileim:id/chat_inputtext", className="android.widget.EditText")
            if not chat_inputtext.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(chat_inputtext.exists)
            if chat_inputtext.exists:
                chat_inputtext.click()
                chat_inputtext.clear_text()
 
                chat_inputtext.set_text("hello, nice to meet you.")
                time.sleep(1)
                if self.d(text="发送", className="android.widget.Button").exists:
                    self.d(text="发送", className="android.widget.Button").click()
                else:
                    logger.info(u"发送按钮不存在")
                    pass
            #send emotion image
            #进入表情选择界面
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                emotion = self.d(text=u"表情", className="android.widget.TextView")
                if not emotion.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(emotion.exists)
                if emotion.exists:
                    emotion.click()
                    time.sleep(1)
                    if self.d(text=u"阿里旺旺表情").exists:
                        self.d(text=u"阿里旺旺表情").click()
                        time.sleep(1)
                    smily_scroller = self.d(resourceId="com.alibaba.mobileim:id/smily_scroller",className="android.widget.FrameLayout")
                    if not smily_scroller.exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(smily_scroller.exists)
                    if smily_scroller.exists:
                        # 表情选取坐标起始值:Sx = 655 , Sy = 830 表情间距: Dx = 102, Dy = 55
                        Sx = 655
                        Sy = 830
                        Dx = 102
                        Dy = 55
                        # 表情页滑动起始和结束坐标点
                        startx = smily_scroller.info['visibleBounds']['left'] + 50
                        starty = smily_scroller.info['visibleBounds']['top'] + 80
                        endx = smily_scroller.info['visibleBounds']['left'] + 660
                        endy = starty
 
                        Nx = random.randint(0, 6)
                        Ny = random.randint(0, 2)
                        if Ny == 2 and Nx == 6:
                            Nx = Nx - 1
                        else:
                            pass
 
                        for i in range(random.randint(0, 4)):
                            self.d.drag(startx, starty, endx, endy, steps=10)
                            time.sleep(1)
                        self.d.click(Sx + Nx * Dx, Sy + Ny * Dy)
 
                        if self.d(text="发送", className="android.widget.Button").exists:
                            self.d(text="发送", className="android.widget.Button").click()
                        else:
                            logger.info(u"发送按钮不存在")
                            pass
                    #淘公仔表情
                    if self.d(text="淘公仔表情", className="android.widget.RadioButton").exists:
                        self.d(text="淘公仔表情", className="android.widget.RadioButton").click()
                        smile_layout = self.d(resourceId="com.alibaba.mobileim:id/smile_layout", className="android.widget.LinearLayout")
                        if not smile_layout.exists:
                            name = sys._getframe().f_code.co_name
                            screen_shot.ScreenShot(self,name)
                        self.assertTrue(smile_layout.exists)
                        #logger.info("click the emotion.")
                        if smile_layout.exists:
                            time.sleep(1)
                            #获取第一个淘公仔的坐标点
                            x = smile_layout.info['visibleBounds']['left'] +80
                            y = smile_layout.info['visibleBounds']['top'] +40
                            self.d.click(x, y)
                            time.sleep(1)
            #返回主界面
            chat_back = self.d(resourceId="com.alibaba.mobileim:id/chat_back", className="android.widget.TextView")
            self.assertEqual(chat_back.info['text'], u'返回')
            if chat_back.exists:
                chat_back.click()
                time.sleep(1)
            title_back = self.d(resourceId="com.alibaba.mobileim:id/title_back", className="android.widget.TextView")
            self.assertEqual(title_back.info['text'], u'返回')
            if title_back.exists:
                title_back.click()
                time.sleep(1)
 
 
        logger.info('Exit --  MUAT:MobileImTest:test_SendMessage')
 
    def test_SendtakePhoto(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendtakePhoto')
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.TextView")
        self.assertEqual(tab_message.info['text'], u'消息')
        if tab_message.exists:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择拍照发送
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                takepic = self.d(text=u"拍照", className="android.widget.TextView")
                if not takepic.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(takepic.exists)
                if takepic.exists:
                    takepic.click()
                    camera = self.d(resourceId="com.android.camera2:id/shutter_button", className="android.widget.ImageView", packageName="com.android.camera2")
                    start=time.time()
                    while time.time()-start<constants.Time_Out:
                        if  camera.exists:
                            break
                        else:
                            time.sleep(1)
                    #调用系统的相机拍摄照片
                    self.assertEqual(camera.info['contentDescription'], u'快门')
                    if camera.exists:
                        camera.click()
                        btn_done = self.d(resourceId="com.android.camera2:id/btn_done", className="android.widget.ImageView", packageName="com.android.camera2")
                        start=time.time()
                        while time.time()-start<constants.Time_Out:
                            if  btn_done.exists:
                                break
                            else:
                                time.sleep(1)
                        #确认完成拍照
                        self.assertEqual(btn_done.info['contentDescription'], u'完成')
                        if btn_done.exists:
                            btn_done.click()
                            btn_confirm = self.d(resourceId="com.alibaba.mobileim:id/confirm", className="android.widget.Button", packageName="com.alibaba.mobileim")
                            start=time.time()
                            while time.time()-start<constants.Time_Out:
                                if  btn_confirm.exists:
                                    break
                                else:
                                    time.sleep(1)
                            #点击确定按钮,发送照片
                            self.assertEqual(btn_confirm.info['text'], u'确定')
                            if btn_confirm.exists:
                                btn_confirm.click()
                                time.sleep(2)
            #返回主界面
            chat_back = self.d(resourceId="com.alibaba.mobileim:id/chat_back", className="android.widget.TextView")
            self.assertEqual(chat_back.info['text'], u'返回')
            if chat_back.exists:
                chat_back.click()
                time.sleep(1)
 
 
        logger.info('Exit --  MUAT:MobileImTest:test_SendtakePhoto')

    def test_SendCard(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendCard')
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.TextView")
        self.assertEqual(tab_message.info['text'], u'消息')
        if tab_message.exists:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择名片
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                card_btn = self.d(text=u"名片", className="android.widget.TextView")
                if not card_btn.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(card_btn.exists)
                if card_btn.exists:
                    card_btn.click()
                    time.sleep(3)
                    #进入选择好友界面,选择好友,并发送
                    wx_friends_btn = self.d(resourceId="com.alibaba.mobileim:id/wx_friends_button", className="android.widget.Button")
                    self.assertEqual(wx_friends_btn.info['text'], u'旺旺好友')
                    if wx_friends_btn.exists:
                        wx_friends_btn.click()
                        time.sleep(1)
                        #选择 景止、洗石、云渡
                        self.d(text=u"景止").click()
                        time.sleep(1)
                        self.d(text=u"洗石").click()
                        time.sleep(1)
                        self.d(text=u"云渡").click()
                        time.sleep(1)
                        #点击确定按钮
                        startbtn = self.d(resourceId="com.alibaba.mobileim:id/start", className="android.widget.Button")
                        if not startbtn.exists:
                            name = sys._getframe().f_code.co_name
                            screen_shot.ScreenShot(self,name)
                        self.assertTrue(startbtn.exists)
                        if startbtn.exists:
                            startbtn.click()
                            time.sleep(1)
            #返回主界面
            chat_back = self.d(resourceId="com.alibaba.mobileim:id/chat_back", className="android.widget.TextView")
            self.assertEqual(chat_back.info['text'], u'返回')
            if chat_back.exists:
                chat_back.click()
                time.sleep(1)


        logger.info('Exit --  MUAT:MobileImTest:test_SendCard')

    def test_SendPicture(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendPicture')
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.TextView")
        self.assertEqual(tab_message.info['text'], u'消息')
        if tab_message.exists:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择名片
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                selectpic_btn = self.d(text=u"选择照片", className="android.widget.TextView")
                if not selectpic_btn.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(selectpic_btn.exists)
                if selectpic_btn.exists:
                    selectpic_btn.click()
                    time.sleep(3)
                    pic = self.d(resourceId="com.alibaba.mobileim:id/image_item", className="android.widget.ImageView")
                    if not pic.exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(pic.exists)
                    if pic.exists:
                        # logger.info("pic--->(s%)" %(type(pic)))
                        pic.click()
                        time.sleep(1)
                        #选择图片
                        img_check = self.d(resourceId="com.alibaba.mobileim:id/image_check", className="android.widget.ImageView")
                        if not img_check.exists:
                            name = sys._getframe().f_code.co_name
                            screen_shot.ScreenShot(self,name)
                        self.assertTrue(img_check.exists)
                        if img_check.exists:
                            img_check.click()
                            time.sleep(2)
                        #点击完成, 发送图片
                        select_finish = self.d(resourceId="com.alibaba.mobileim:id/select_finish", className="android.widget.Button")
                        self.assertEqual(select_finish.info['text'], u'完成')
                        if select_finish.exists:
                            select_finish.click()
                            time.sleep(2)
        #返回主界面
        chat_back = self.d(resourceId="com.alibaba.mobileim:id/chat_back", className="android.widget.TextView")
        self.assertEqual(chat_back.info['text'], u'返回')
        if chat_back.exists:
            chat_back.click()
            time.sleep(1)
 
        logger.info('Exit --  MUAT:MobileImTest:test_SendPicture')
 
    def test_SendVoice(self):
        logger.info('Enter -- MUAT:MobileImTest:test_SendVoice')
 
        #点击消息栏
        tab_message = self.d(resourceId="com.alibaba.mobileim:id/tab_message_text", className="android.widget.TextView")
        self.assertEqual(tab_message.info['text'], u'消息')
        if tab_message.exists:
            tab_message.click()
            time.sleep(1)
            #查找历史消息找到wb-zhaoxinjian, 点击进入消息对话框
            friend = self.d(text=constants.TEST_REMOTE_USERNAME, resourceId="com.alibaba.mobileim:id/name", className="android.widget.TextView")
            if not friend.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(friend.exists)
            if friend.exists:
                friend.click()
                time.sleep(2)
            # else:
            #     #如果不存在则寻找另外的联系人
            #     pass
            #进入扩展选择界面,选择名片
            reply_bar_expand = self.d(resourceId="com.alibaba.mobileim:id/reply_bar_expand", className="android.widget.CheckBox")
            if not reply_bar_expand.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(reply_bar_expand.exists)
            if reply_bar_expand.exists:
                reply_bar_expand.click()
                voice_btn = self.d(text=u"语音消息", className="android.widget.TextView")
                if not voice_btn.exists:
                    name = sys._getframe().f_code.co_name
                    screen_shot.ScreenShot(self,name)
                self.assertTrue(voice_btn.exists)
                if voice_btn.exists:
                    voice_btn.click()
                    time.sleep(3)
                #长按,启动语音录音
                chat_record = self.d(resourceId="com.alibaba.mobileim:id/chat_record", className="android.widget.Button")
                self.assertEqual(chat_record.info['text'], u'请长按讲话')
                if chat_record.exists:
                    '''
                    还没有解决长按的方法,暂时用long_click()
                    '''
                    chat_record.long_click()
                    time.sleep(2)
        #返回主界面
        chat_back = self.d(resourceId="com.alibaba.mobileim:id/chat_back", className="android.widget.TextView")
        self.assertEqual(chat_back.info['text'], u'返回')
        if chat_back.exists:
            chat_back.click()
            time.sleep(1)
 
        logger.info('Exit --  MUAT:MobileImTest:test_SendVoice')
 
    def test_ModifyInfo(self):
        logger.info('Enter -- MUAT:MobileImTest:test_ModifyInfo')
 
        MobileimTitle=self.d(resourceId='android:id/pc_title', className='android.widget.TextView', packageName='com.alibaba.mobileim')
        if MobileimTitle.exists:
            self.assertEqual(MobileimTitle.info['text'], u'旺信')
            meButton=self.d(resourceId='com.alibaba.mobileim:id/tab_me_text')
            if meButton.exists:
                meButton.click()
                time.sleep(2)
                moreButton=self.d(text=u'更多',packageName='com.alibaba.mobileim')
                if moreButton.exists:
                    moreButton.click()
                    time.sleep(2)
                    if not self.d(text=u'设置', packageName='com.alibaba.mobileim').exists:
                        name = sys._getframe().f_code.co_name
                        screen_shot.ScreenShot(self,name)
                    self.assertTrue(self.d(text=u'设置', packageName='com.alibaba.mobileim').exists)
                    profileButton = self.d(text=u'个人资料', packageName='com.alibaba.mobileim')
                    #modify profile
                    if profileButton.exists:
                        profileButton.click()
                        time.sleep(2)
                        profileName=self.d(resourceId='com.alibaba.mobileim:id/profile_name')
                        profileName.click()
                        time.sleep(2)
                        ModifyName=self.d(resourceId='com.alibaba.mobileim:id/modify_group_name',className='android.widget.EditText')
                        cancelButton=self.d(resourceId='com.alibaba.mobileim:id/modify_cancel',className='android.widget.ImageView')
                        cancelButton.click()
                        #ModifyName.clear_text()
                        ModifyName.set_text("who are you")
                        time.sleep(2)
                        okButton=self.d(text=u'完成',resourceId='com.alibaba.mobileim:id/title_button')
                        if okButton.exists:
                            okButton.click()
                            time.sleep(2)
                            self.assertEqual(profileName.info['text'], "who are you")
                            profileName.click()
                            time.sleep(2)
                            cancelButton.click()
                            ModifyName.set_text("tester_1")
                            time.sleep(2)
                            okButton.click()
                            self.assertEqual(profileName.info['text'], "tester_1")
                        #modify male
                        profileSex=self.d(resourceId='com.alibaba.mobileim:id/setting_profile_gender')
                        if profileSex.exists:
                            if not profileSex.info['text'] == u'男':
                                profileSex.click()
                                time.sleep(2)
                                self.d(resourceId='com.alibaba.mobileim:id/profile_gender_male').click()
                                time.sleep(2)
                                self.assertEqual(profileSex.info['text'], u'男')
                            else:
                                profileSex.click()
                                time.sleep(2)
                                self.d(resourceId='com.alibaba.mobileim:id/profile_gender_female').click()
                                time.sleep(2)
                                self.assertEqual(profileSex.info['text'], u'女')
                        #更换头像
                        profileHead=self.d(resourceId='com.alibaba.mobileim:id/people_head')
                        if profileHead.exists:
                            profileHead.click()
                            TakePicture=self.d(text=u'拍照',resourceId='android:id/text1')
                            if TakePicture.exists:
                                TakePicture.click()
                                start=time.time()
                                while time.time()-start<constants.Time_Out:
                                    if  self.d(resourceId='com.android.camera2:id/shutter_button').exists:
                                        break
                                    else:
                                        time.sleep(1)
                                self.d(resourceId='com.android.camera2:id/shutter_button').click()
                                doneButton=self.d(resourceId='com.android.camera2:id/btn_done')
                                start=time.time()
                                while time.time()-start<constants.Time_Out:
                                    if  doneButton.exists:
                                        break
                                    else:
                                        time.sleep(1)
                                doneButton.click()
                                saveButton=self.d(resourceId='com.alibaba.mobileim:id/save')
                                start=time.time()
                                while time.time()-start<constants.Time_Out:
                                    if  saveButton.exists:
                                        break
                                    else:
                                        time.sleep(1)
                                saveButton.click()
                                time.sleep(3)
 
                        #modify area
                        profileAddress=self.d(resourceId='com.alibaba.mobileim:id/setting_profile_address')
                        area_title=self.d(resourceId='com.alibaba.mobileim:id/title')
                        bj1_x=area_title.info['visibleBounds']['right'] - 20
                        bj1_y=area_title.info['visibleBounds']['bottom'] + 20
                        bj2_x=bj1_x
                        bj2_y=bj1_y + 44
                        tj1_x=bj1_x
                        tj1_y=bj2_y
                        tj2_x=bj1_x
                        tj2_y=bj2_y + 44
                        if profileAddress.exists:
                            profileAddress.click()
                            time.sleep(2)
                            self.d.click(bj1_x,bj1_y)
                            time.sleep(2)
                            self.d.click(bj2_x,bj2_y)
                            time.sleep(3)
                            self.assertEqual(profileAddress.info['text'], u'北京 北京')
                            profileAddress.click()
                            time.sleep(2)
                            self.d.click(tj1_x,tj1_y)
                            time.sleep(2)
                            self.d.click(tj2_x,tj2_y)
                            time.sleep(3)
                            self.assertEqual(profileAddress.info['text'], u'天津 天津')
 
                    #退出登陆
                    backButton=self.d(text=u'返回',resourceId='com.alibaba.mobileim:id/title_back')
                    backButton.click()
                    time.sleep(1)
                    backButton.click()
                    time.sleep(1)
        #             logoutButton=self.d(resourceId='com.alibaba.mobileim:id/setting_logout',className='android.widget.TextView')
        #             self.assertTrue(logoutButton.exists)
        #             if logoutButton.exists:
        #                 logoutButton.click()
        #                 time.sleep(1)
        #                 self.d.press(66)
        #                 self.d.press(66)
        #                 time.sleep(3)
        #             self.assertTrue(LoginButton.exists)
        #
        # closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        # if closeButton.exists:
        #     closeButton.click()
        #     time.sleep(3)
        logger.info('Exit -- MUAT:MobileImTest:test_ModifyInfo')
 
    def test_CheckInfo(self):
        logger.info('Enter -- MUAT:MobileImTest:test_CheckInfo')
        # self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
        # time.sleep(5)
        # #登陆
        # LoginButton=self.d(resourceId='com.alibaba.mobileim:id/login')
        # if LoginButton.exists:
        #     LoginButton.click()
        #     LoginButton.click()
        #     time.sleep(5)
 
        MobileimTitle=self.d(resourceId='android:id/pc_title')
        if not MobileimTitle.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(MobileimTitle.exists)
        if MobileimTitle.exists:
            MobileimTitle.click()
            logger.info('MobileimTitle is here')
 
        MessageButton=self.d(resourceId='com.alibaba.mobileim:id/tab_message_text')
        if not MessageButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(MessageButton.exists)
        if MessageButton.exists:
            MessageButton.click()
            logger.info('Message is here')
 
        FriendsButton=self.d(resourceId='com.alibaba.mobileim:id/tab_friends_text')
        if not FriendsButton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(FriendsButton.exists)
        if FriendsButton.exists:
            FriendsButton.click()
            logger.info('Friends is here')
            SearchButton=self.d(resourceId='com.alibaba.mobileim:id/search_layout')
            if not SearchButton.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(SearchButton.exists)
            ShopButton=self.d(resourceId='com.alibaba.mobileim:id/shop_layout')
            if not ShopButton.exists:
                name = sys._getframe().f_code.co_name
                screen_shot.ScreenShot(self,name)
            self.assertTrue(ShopButton.exists)
            if ShopButton.exists:
                ShopButton.click()
                logger.info('Shop is here')
            GuyBtton=self.d(resourceId='com.alibaba.mobileim:id/friends_layout')
            self.assertTrue(GuyBtton.exists)
            if GuyBtton.exists:
                GuyBtton.click()
                logger.info('Guys is here')
            GruopButton=self.d(resourceId='com.alibaba.mobileim:id/tribe_layout')
            self.assertTrue(GruopButton.exists)
            if GruopButton.exists:
                GruopButton.click()
                logger.info('Gruop is here')
 
        CornerButton=self.d(resourceId='com.alibaba.mobileim:id/tab_corner_text')
        self.assertTrue(CornerButton.exists)
        if CornerButton.exists:
            CornerButton.click()
            logger.info('Corner is here')
 
        MeButton=self.d(resourceId='com.alibaba.mobileim:id/tab_me_text')
        self.assertTrue(MeButton.exists)
        if MeButton.exists:
            MeButton.click()
            logger.info('Me is here')
 
        MaxBtton=self.d(resourceId='android:id/pc_max')
        if not MaxBtton.exists:
            name = sys._getframe().f_code.co_name
            screen_shot.ScreenShot(self,name)
        self.assertTrue(MaxBtton.exists)
        if MaxBtton.exists:
            MaxBtton.click()
            time.sleep(2)
            MaxBtton.click()
            time.sleep(2)
             
 
 
        # closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        # if closeButton.exists:
        #     closeButton.click()
        #     time.sleep(3)
        logger.info('Exit -- MUAT:MobileImTest:test_CheckInfo')

#     def test_Drag(self):
#         logger.info('Enter -- MUAT:MobileImTest:test_Drag')
#         self.adb_tools.adb_shell('am start -n com.alibaba.mobileim/com.alibaba.mobileim.ui.login.LoginActivity')
#         time.sleep(5)
#         Button2=self.d(text=u'取消',resourceId='com.alibaba.mobileim:id/button2')
#         if Button2.exists:
#             Button2.click()
#         #登陆
#         LoginButton=self.d(resourceId='com.alibaba.mobileim:id/login')
#         if LoginButton.exists:
#             LoginButton.click()
#             LoginButton.click()
#             time.sleep(5)
#         #拖拉窗口
#         meButton=self.d(resourceId='com.alibaba.mobileim:id/tab_me_text')
#         start_x=meButton.info['visibleBounds']['right']
#         start_y=meButton.info['visibleBounds']['bottom']
#         end_x  =start_x + 100
#         end_x0 =start_x - 100
#         end_y  =start_y + 50
#         self.d.drag(start_x,start_y,end_x,end_y,steps=1)
#         self.d.drag(start_x,start_y,end_x0,end_y)
#         time.sleep(3)





        # closeButton=self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        # if closeButton.exists:
        #     closeButton.click()
        #     time.sleep(3)
        # logger.info('Exit -- MUAT:SettingsSystemTest:test_Drag')

    def tearDown(self):
        # tab_me test
        tab_me = self.d(resourceId="com.alibaba.mobileim:id/tab_me_text", className="android.widget.TextView")
        self.assertEqual(tab_me.info['text'], u'我')

        if tab_me.exists:
            tab_me.click()
            time.sleep(1)

            myname = self.d(resourceId="com.alibaba.mobileim:id/title_text", className="android.widget.TextView")
            self.assertEqual(myname.info['text'], 'tester_1')

            # logout test
            title_btn = self.d(resourceId="com.alibaba.mobileim:id/title_button")
            self.assertEqual(title_btn.info['text'], u'更多')

            if title_btn.exists:
                title_btn.click()
                time.sleep(2)

            # account logout
            logout_btn = self.d(resourceId='com.alibaba.mobileim:id/setting_logout')
            self.assertEqual(logout_btn.info['text'], u'退出登录')

            if logout_btn.exists:
                logout_btn.click()

            exit_massege = self.d(resourceId="com.alibaba.mobileim:id/message", className="android.widget.TextView")
            self.assertEqual(exit_massege.info['text'], u'退出后您将收不到新消息通知,是否确认退出?')
            time.sleep(1)
            if exit_massege.exists:
                self.d(resourceId="com.alibaba.mobileim:id/button1", className="android.widget.Button").click()

        #clear the account
        select_account = self.d(resourceId="com.alibaba.mobileim:id/select_account", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        if select_account.exists:
            select_account.click()
            if self.d(resourceId='com.alibaba.mobileim:id/delete').exists:
                self.d(resourceId='com.alibaba.mobileim:id/delete').click()

                delete_massage = self.d(resourceId='com.alibaba.mobileim:id/message', className='android.widget.TextView')
                self.assertEqual(delete_massage.info['text'], u'确认删除该帐号记录?')
                if delete_massage.exists:
                    self.d(resourceId="com.alibaba.mobileim:id/button1", className="android.widget.Button").click()

        closebtn = self.d(resourceId="android:id/pc_close", className="android.widget.ImageView", packageName="com.alibaba.mobileim")
        #self.assertTure(closebtn.exists)

        if closebtn.exists:
            logger.debug('click close button: (%s)' % (closebtn.info['packageName']))
            closebtn.click()
        #logger.info("EXIT -- MUAT:MobileImTest:close_mobileim")
        self.adb_tools.adb_shell('am force-stop com.alibaba.mobileim')
        self.account.sleep()