當前位置: 首頁>>代碼示例>>Python>>正文


Python Device.click方法代碼示例

本文整理匯總了Python中uiautomator.Device.click方法的典型用法代碼示例。如果您正苦於以下問題:Python Device.click方法的具體用法?Python Device.click怎麽用?Python Device.click使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在uiautomator.Device的用法示例。


在下文中一共展示了Device.click方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ModelInfo

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]

#.........這裏部分代碼省略.........
    def pressCenter(self):
        return self.mstrDevice.press.center()
    
    ######################################################################    
        
    def pressMenu(self):
        return self.mstrDevice.press.menu()
        
    def pressSearch(self):
        return self.mstrDevice.press.search()
           
    def pressEnter(self):
        return self.mstrDevice.press.enter()
            
    def pressDelete(self):
        return self.mstrDevice.press.delete() # or del
        
    def pressRecent(self):
        return self.mstrDevice.press.recent()
            
    def pressVol_Up(self):
        return self.mstrDevice.press.volume_up()
            
    def pressVol_Down(self):
        return self.mstrDevice.press.volume_down()
            
    def pressVol_Mute(self):
        return self.mstrDevice.press.volume_mute()
            
    def pressPower(self):
        return self.mstrDevice.press.power()
            
    def clik(self, x, y):
        return self.mstrDevice.click(x, y)
            
    def longClik(self,x, y):
        '''
            Description:
                
            param:
                x, y : start first point x, y
                
            return : Boolean
        '''
        return self.mstrDevice.long_click(x, y)
            
    def swipe(self, sx, sy, ex, ey, steps=10):
        '''
            Description:
                
            param:
                sx, xy : start first x, y
                ex, ey : move to x, y
            return : Boolean
        '''
        return self.mstrDevice.swipe(sx, sy, ex, ey, steps)
           
    def drage(self,sx, sy, ex, ey, steps=10):
        '''
            Description:
                
            param:
                sx, xy : start first x, y
                ex, ey : move to x, y
            return : Boolean
        '''
開發者ID:sqler21c,項目名稱:Python,代碼行數:70,代碼來源:ModelInfo.py

示例2: Mobile

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]

#.........這裏部分代碼省略.........

    def press_recent(self):
        """
        press recent key
        """
        self.device.press.recent()

    def press_volume_up(self):
        """
        press volume up key
        """
        self.device.press.volume_up()

    def press_volume_down(self):
        """
        press volume down key
        """
        self.device.press.volume_down()

    def press_camera(self):
        """
        press camera key
        """
        self.device.press.camera()

    def press_power(self):
        """
        press power key
        """
        self.device.press.power()

#Gesture interaction of the device

    def click(self, x, y):
        """
        click (x, y) on screen
        """
        self.device.click(x, y)

    def swipe(self, sx, sy, ex, ey, steps=10):
        """
        swipe from (sx, sy) to (ex, ey) with steps
        """
        self.device.swipe(sx, sy, ex, ey, steps)

# Swipe from the center of the ui object to its edge

    def swipe_left(self, obj, steps=10):
        """
        swipe the *obj* from center to left
        """
        obj.swipe.left(steps=steps)

    def swipe_right(self, obj, steps=10):
        """
        swipe the *obj* from center to right
        """
        obj.swipe.right(steps=steps)

    def swipe_top(self, obj, steps=10):
        """
        swipe the *obj* from center to top
        """
        obj.swipe.top(steps=steps)

    def swipe_bottom(self, obj, steps=10):
開發者ID:am01230123,項目名稱:parallelization,代碼行數:70,代碼來源:Mobile.py

示例3: AndroidDevice

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]

#.........這裏部分代碼省略.........
            shellcmd.append(str(kwargs['flags']))

        if 'uri' in keys:
            shellcmd.append(kwargs['uri'])
        #sys.stderr.write(str(shellcmd))            
        self.d.server.adb.cmd(*shellcmd).communicate()
        return self

    def instrument(self, **kwargs):
        keys = kwargs.keys()
        shellcmd = ['shell', 'am', 'instrument', '-w', '-r']
        pkgname = kwargs.pop('packagename')
        for k, v in kwargs.items():
            if k and v:
                shellcmd.append('-e')
                shellcmd.append(k)
                shellcmd.append(str(v))
        shellcmd.append(pkgname)
        result = self.d.server.adb.cmd(*shellcmd).communicate()
        return result

    def TODOinstallPackage(self, **kwargs):
        pass

    def TODOremovePackage(self, **kwargs):
        pass

    def press(self, keyname, waittime=1):
        #hard, soft key: home,back,up,down,right,left,center,menu,power or ANDROID_KEYEVENT
        self.d.press(keyname)
        time.sleep(waittime)
        return self

    def click(self, x, y, waittime=1):
        self.d.click(x, y)
        time.sleep(waittime)
        return self

    def click_image(self, imagename, waittime=1, threshold=0.01):
        '''
        if the wanted image found on current screen click it.
        if the wanted image not found raise exception and set test to be failure.
        '''
        expect_image_path = os.path.join(configer['right_dir_path'], imagename)
        assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % imagename
        current_image_path = os.path.join(configer['report_dir_path'], imagename)
        self.d.screenshot(current_image_path)
        assert os.path.exists(current_image_path), 'fetch current screen shot image %s failed!' % imagename
        pos = getMatchedCenterOffset(expect_image_path, current_image_path, threshold)
        assert pos, 'Fail Reason: The wanted image \'%s\' not found on screen!' % imagename
        self.d.click(pos[0], pos[1])
        time.sleep(waittime)
        return self

    def swipe(self, sx, sy, ex, ey, steps=100, waittime=1):
        self.d.swipe(sx, sy, ex, ey, steps)
        time.sleep(waittime)
        return self

    def drag(self, sx, sy, ex, ey, steps=100, waittime=1):
        self.d.drag(sx, sy, ex, ey, steps)
        time.sleep(waittime)
        return self

    #inspect
    def exists(self, **kwargs):
開發者ID:lucker6666,項目名稱:devicewrapper,代碼行數:70,代碼來源:android.py

示例4: AndroidDevice

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]
class AndroidDevice(object):
    '''
    wrapper for android uiautomator-server binding(pip install uiautomator).
    provide android device event inject, ui object inspect and image comparison.
    '''

    def __init__(self, seral=None):
        '''
        create device instance.
        '''
        self.serial = os.environ[ANDROID_SERIAL] if os.environ.has_key(ANDROID_SERIAL) else None
        self.working_dir_path = WORKING_DIR_PATH
        self.report_dir_path = REPORT_DIR_PATH
        self.right_dir_path = WORKING_DIR_PATH
        self._internal_storage_dir = DEFAULT_DEVICE_INTERNAL_STORAGE
        self.d = Device(self.serial)
        #try:
        #    if int(self.d.info['sdkInt']) <= 17:
        #        self.d.screenshot = self.screenshot_common
        #except:
        #    pass

    def set_internal_storage_dir(self, path):
        self._internal_storage_dir = path

    def __getattr__(self, attr):
        '''
        forward method/attrbuite to uiautomator device if method support by uiautomator.
        '''
        if hasattr(self.d, attr):
            if attr == 'screenshot':
                return self.screenshot_common
            m =  getattr(self.d, attr)
            if inspect.ismethod(m):
                def wrapper(*args, **kwargs):
                    return m(*args, **kwargs)
                return wrapper
            else:
                return m
        raise AttributeError(attr)

    def __call__(self, *args, **kwargs):
        '''
        selector support:
        d(text="Settings").click()
        '''
        return self.d(*args, **kwargs)

    @property
    def orientation(self):
        return self.d.orientation

    @orientation.setter
    def orientation(self, v):
        self.d.orientation = v

    def serial(self):
        '''
        device serial number from $ANDROID_SERIAL
        '''
        return self.serial

    def sleep(self, sec):
        time.sleep(sec)

    #device event inject
    def start_activity(self, **intent_params):
        '''
        Starts an Activity on the device by sending an Intent which constructed from the specified parameters.     
        The params of Intent supported from adb docs:
        <INTENT> specifications include these flags:
            [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
            [-c <CATEGORY> [-c <CATEGORY>] ...]
            [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
            [--esn <EXTRA_KEY> ...]
            [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
            [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
            [-n <COMPONENT>] [-f <FLAGS>]
            [<URI>]
        @type intent_params: dictionary 
        @param intent_params: the properties of an Intent. 
                              property support: component/action/data/mimetype/categories/extras/flags/uri
        @rtype: AndroidDevice
        @return: a instance of AndroidDevice.
        '''
        
        #d.server.adb.cmd('shell','am', 'start', '-a', 'android.intent.action.DIAL','tel:13581739891').communicate()
        #sys.stderr.write(str(intent_params))
        keys = intent_params.keys()
        shellcmd = ['shell', 'am', 'start']
        if 'component' in keys:
            shellcmd.append('-n')
            shellcmd.append(intent_params['component'])

        if 'action' in keys:  
            shellcmd.append('-a')
            shellcmd.append(intent_params['action'])

        if 'data' in keys:
            shellcmd.append('-d')
#.........這裏部分代碼省略.........
開發者ID:miboxdemo,項目名稱:uiautomatorplug,代碼行數:103,代碼來源:android.py

示例5:

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]
     continue
 for package in applist:
     os.popen('adb -s ' + series + ' shell am start -n fu.hao.uidroid/.TaintDroidNotifyController')
     current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
     os.popen('adb -s ' + series + ' shell "su 0 date -s `date +%Y%m%d.%H%M%S`"')
     os.popen('adb -s ' + series + ' shell monkey -p com.lexa.fakegps --ignore-crashes 1')
     flag = True
     while flag:
         try:
             dev.info
             flag = False
         except:
             pass
     dev.screen.on()
     #dev(text='Set location').click()
     dev.click(300, 150)
     dev.press.back()
     os.popen('adb kill-server')
     os.popen('adb start-server')
     cmd = 'adb -s ' + series + ' shell "nohup /data/local/tcpdump -w /sdcard/' + package + current_time + '.pcap"'
     #os.system(cmd)
     subprocess.Popen(cmd, stdout=subprocess.PIPE,
                      stderr=subprocess.STDOUT, shell=True)
     logger.info('tcpdump begins')
     os.popen('adb -s ' + series + ' logcat -c')
     logger.info('clear logcat')
     dir_data = appdir + 'data/' + package + '/'
     os.popen('mkdir ' + dir_data)
     #os.popen('adb -s ' + series + ' shell "logcat -v threadtime | grep --line-buffered UiDroid_Taint > /sdcard/' + package + current_time +'.log " &')
     cmd = 'adb -s ' + series + ' shell "nohup logcat -v threadtime -s "UiDroid_Taint" > /sdcard/' + fline + current_time +'.log"'
     #os.system(cmd)
開發者ID:majestyhao,項目名稱:Traffic_UI,代碼行數:33,代碼來源:privicy_pcap.py

示例6: AdbDevice

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]
class AdbDevice(object):
    hiddenService = 'com.fuhu.settingshelper/.SettingsHelperService'
    LIST_SYSTEM = 'system'
    LIST_ALL = 'all'
    LIST_3RD_PARTY = '3rd'
    LIST_RECENT = 'recent'
    orientation = ['natural', 'left', 'upsidedown', 'right']

    def __init__(self, serialno=None):
        self.lock = threading.Semaphore()
        self.cmd = AdbCmd(serialno)
        self.serialno = serialno

    def connect(self):
        self.d = Device(self.serialno)
        self.d.orientation # notify to connect

        #         self.d, self.serialno = ViewClient.connectToDeviceOrExit(serialno=self.serialno)
    #         self.vc = ViewClient(self.d, self.serialno, compresseddump=False, ignoreuiautomatorkilled=True, autodump=False)

    def startActivity(self, component):
        component = component.replace('$', '\$')
        self.cmd.shell(['am', 'start', '-n', component, '--activity-clear-task'])

    def isConnected(self):
        if self.__getDevices(self.serialno):
            return True
        else:
            return False

    def listPackages(self):
        return self.cmd.shell(['pm', 'list', 'package'], output=True)

    def reboot(self):
        self.cmd.reboot()

    def dump(self, compressed=False):
        return self.d.dump(compressed=compressed).encode('utf-8')

    @staticmethod
    def retrieveSelector(point, selectors):
        shortestDistance = 500000
        result = None
        for selector in selectors:
            print selector.className
            bounds = selector.info['bounds']
            if bounds['right'] >= point[0] >= bounds['left'] and bounds['top'] >= point[1] >= bounds['bottom']:
                return selector

        for selector in selectors:

            bounds = selector.info['bounds']
            distance = (((bounds['left'] + bounds['top']) / 2 - point[0]) ** 2 + (
                (bounds['left'] + bounds['bottom']) / 2 - point[1]) ** 2) ** 0.5
            if shortestDistance > distance:
                shortestDistance = distance
                result = selector
        return result

    def checkSamePoint(self, point, info, isLongClick=False):
        if not self.isScreenOn():
            self.powerBtn()
            if self.isLocked():
                self.unlock()

        if len(info) == 2:
            if self.d.info['currentPackageName'] == info['packageName']:
                self.cmd.shell(['input', 'tap', str(point[0]), str(point[1])])
                return {'answer': True, 'reason': 'it is the navigation bar'}
            else:
                return {'answer': False, 'reason': 'unknown view'}

        if info['content-desc'] != '':
            uiObject = self.d(description=info['content-desc'])
            if self.__checkIncludePoint(uiObject, point):
                self.cmd.shell(['input', 'tap', str(point[0]), str(point[1])])
            else:
                uiObject.click()

            return {'answer': True, 'reason': 'find by description'}

        if info['text'] != '':
            uiObject = self.d(text=info['text'])
            if self.__checkIncludePoint(uiObject, point):
                self.cmd.shell(['input', 'tap', str(point[0]), str(point[1])])
            else:
                uiObject.click()
            return {'answer': True, 'reason': 'find by text'}

        currentViewMap = self.getTouchViewInfo(point)
        if currentViewMap:
            if currentViewMap['package'] == info['package']:
                if currentViewMap['class'] == info['class']:
                    self.d.click(point[0], point[1])
                    return {'answer': True, 'reason': 'Find the similar view'}
                else:
                    return {'answer': False, 'reason': 'the view doesn\'t be found.'}
            else:
                return {'answer': False, 'reason': 'In the wrong page'}
        else:
#.........這裏部分代碼省略.........
開發者ID:ChenYuTingJerry,項目名稱:AutoSense_2,代碼行數:103,代碼來源:Adb.py

示例7: Mobile

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]

#.........這裏部分代碼省略.........

    def press_recent(self):
        """
        Press recent key
        """
        self.device.press.recent()

    def press_volume_up(self):
        """
        Press volume up key
        """
        self.device.press.volume_up()

    def press_volume_down(self):
        """
        Press volume down key
        """
        self.device.press.volume_down()

    def press_camera(self):
        """
        Press camera key
        """
        self.device.press.camera()

    def press_power(self):
        """
        Press power key
        """
        self.device.press.power()

#Gesture interaction of the device

    def click_at_coordinates(self, x, y):
        """
        Click at (x,y) coordinates.
        """
        self.device.click(x, y)

    def swipe_by_coordinates(self, sx, sy, ex, ey, steps=10):
        """
        Swipe from (sx, sy) to (ex, ey) with *steps* .

        Example:
        | Swipe By Coordinates | 540 | 1340 | 940 | 1340 | | # Swipe from (540, 1340) to (940, 100) with default steps 10 |
        | Swipe By Coordinates | 540 | 1340 | 940 | 1340 | 100 | # Swipe from (540, 1340) to (940, 100) with steps 100 |
        """
        self.device.swipe(sx, sy, ex, ey, steps)

# Swipe from the center of the ui object to its edge

    def swipe_left(self, steps=10, *args, **selectors):
        """
        Swipe the UI object with *selectors* from center to left.

        Example:

        | Swipe Left | description=Home screen 3 | | # swipe the UI object left |
        | Swipe Left | 5 | description=Home screen 3 | # swipe the UI object left with steps=5 |

        See `introduction` for details about identified UI object.
        """
        self.device(**selectors).swipe.left(steps=steps)

    def swipe_right(self, steps=10, *args, **selectors):
        """
開發者ID:am01230123,項目名稱:furry-ironman,代碼行數:70,代碼來源:Mobile.py

示例8: UiTestLib

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]
class UiTestLib(object):
    """Ui Test Lib

    """

    def __init__(self, serial=None):
        """
        """
        logger.info("<p>Device=%s>" % serial, html=True)
        print "<p>Device=%s>" % serial
        self._result = ""
        self.starttime = 0
        self.d = Device(serial)
        self.adb = Adb(serial)
        self.debug = "True"

    def set_debugable(flag):
        self.debug = flag

    def set_serial(self, serial):
        """Specify given *serial* device to perform test.
        or export ANDROID_SERIAL=CXFS42343 if you have many devices connected but you don't use this
        interface

        When you need to use multiple devices, do not use this keyword to switch between devices in test execution.
        And set the serial to each library.
        Using different library name when importing this library according to
        http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.5.

        Examples:
        | Setting | Value |  Value |  Value |
        | Library | UiTestLib | WITH NAME | Mobile1 |
        | Library | UiTestLib | WITH NAME | Mobile2 |

        And set the serial to each library.
        | Test Case        | Action             | Argument           |
        | Multiple Devices | Mobile1.Set Serial | device_1's serial  |
        |                  | Mobile2.Set Serial | device_2's serial  |
        """
        self.d = Device(serial)
        self.adb = Adb(serial)

    def logmsg(self, msg):
        if self.debug == "True":
            print msg

    def exe_adb_command(self, cmd):
        """ Execute adb *cmd*
         Examples:
        | Exe Adb Command | shell getprop  |
        """
        return self.adb.cmd(cmd).wait()

    def exe_adb_and_result(self, cmd):
        """Execute adb *cmd* and return lines of the command"""
        lproc = self.adb.cmd(cmd)
        lproc.poll()
        lines = lproc.stdout.readlines()
        return lines

    def get_device_info(self):
        """Get Device information
        return info dictionary
        """
        return self.d.info

    def light_screen(self):
        """Light screen by wakeup.

        Examples:
        | Action     |
        |Light screen|

        Use `Light screen` to light screen.
        """

        self.d.wakeup()
        self._result = self.d.press.home()

    def open_application(self, appname):
        """Open application by it name `appname`.

        Example:
        | Action           | Argument      |
        | Open application | "com.android.settings/com.android.settings.Settings" |
        """
        appname = "shell am start -n " + appname
        print "Open Application:", appname
        self._result = self.exe_adb_command(appname)

    def click_text(self, text, instance=0):
        """Click text label on screen
        instance=0 is default, change when you needed.

        Example:
        | Action     | Argument   |  Argument  |
        | Click Text | text | instance |
        """

        return self.d(text=text, instance=instance).click.wait()
#.........這裏部分代碼省略.........
開發者ID:huaping,項目名稱:StabilityKPI,代碼行數:103,代碼來源:UiTestLib.py

示例9: asleep

# 需要導入模塊: from uiautomator import Device [as 別名]
# 或者: from uiautomator.Device import click [as 別名]
"""
    Keeps Android from falling asleep (warm!)
    by tapping every five seconds

    Usage:
        python warm.py [adb device id]
"""

import sys
import os
import time
from uiautomator import Device

DEVICE_NAME = sys.argv[1]
d = Device(DEVICE_NAME)

d.wakeup()

os.system("adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0")

while True:
    d.click(100, 100)
    time.sleep(5)
開發者ID:shbhrsaha,項目名稱:mobile-privacy-thesis,代碼行數:25,代碼來源:warm.py


注:本文中的uiautomator.Device.click方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。