• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python uiautomator.Device类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中uiautomator.Device的典型用法代码示例。如果您正苦于以下问题:Python Device类的具体用法?Python Device怎么用?Python Device使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Device类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, serialno=None, **kwargs):
        """Initial AndroidDevice
        Args:
            serialno: string specify which device

        Returns:
            AndroidDevice object

        Raises:
            EnvironmentError
        """
        self.__display = None
        serialno = serialno or getenv('ATX_ADB_SERIALNO', None)
        self._host = kwargs.get('host', getenv('ATX_ADB_HOST', '127.0.0.1'))
        self._port = kwargs.get('port', getenv('ATX_ADB_PORT', 5037, type=int))

        self._adb = adb.Adb(serialno, self._host, self._port)
        serialno = self._adb.device_serial()

        kwargs['adb_server_host'] = kwargs.pop('host', self._host)
        kwargs['adb_server_port'] = kwargs.pop('port', self._port)
        UiaDevice.__init__(self, serialno, **kwargs)
        DeviceMixin.__init__(self)

        self._randid = base.id_generator(5)
        self._serial = serialno
        self._uiauto = super(AndroidDevice, self)

        self.screen_rotation = None
        self.screenshot_method = consts.SCREENSHOT_METHOD_AUTO
        self.last_screenshot = None
开发者ID:917228145,项目名称:AutomatorX,代码行数:31,代码来源:android.py


示例2: __init__

 def __init__(self, seral=None):
     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)
开发者ID:hongbinbao,项目名称:uiautomatorplug,代码行数:7,代码来源:android.py


示例3: set_serial

 def set_serial(self, android_serial):
     """
     Set device serial
     """
     self.adb = ADB(android_serial)
     self.device = Device(android_serial)
     self.test_helper = TestHelper(android_serial)
开发者ID:am01230123,项目名称:parallelization,代码行数:7,代码来源:Mobile.py


示例4: __init__

    def __init__(self, android_serial = None):
#         logger.info("Importing Android library")
#         print "Importing Android library"
#         clm.message("Importing Android library")
        self.adb = ADB(android_serial)
        self.device = Device(android_serial)
        self.test_helper = TestHelper(android_serial)
开发者ID:am01230123,项目名称:parallelization,代码行数:7,代码来源:Mobile.py


示例5: __init__

 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"
开发者ID:huaping,项目名称:StabilityKPI,代码行数:10,代码来源:UiTestLib.py


示例6: __init__

 def __init__(self):
     '''
     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 = RIGHT_DIR_PATH
     self.d = Device(self.serial)
     self.d.screenshot = self.screenshot_common
开发者ID:EthanGuo,项目名称:devicewrapper,代码行数:10,代码来源:android.py


示例7: __init__

    def __init__(self, environment, monitor_serial):

        self.monitor_serial = monitor_serial
        self.specifying_monitor = '-s {}'.format(self.monitor_serial)
        self.device = Device(self.monitor_serial)
        self.build_location ="mon_test\Apps\monitor_build\dev-dell-release-SINK-0.0.3143.7736342\system"
        self.build_version = self.get_build_version()
        self.monitor_name = self.get_monitor_name_by_ui()
        self.find_command = " | findstr" if platform.platform() == "Windows" else "| grep"
        print 'Monitor:init - orientation=%s' % self.device.orientation
开发者ID:aaronrubin901,项目名称:sanity,代码行数:10,代码来源:monitor.py


示例8: Monitor

class Monitor():
    def __init__(self):
        self.serial = self._get_serial()
        self.automation_handle = Device(self.serial)
        self.name = self._get_monitor_name()


    def _get_serial(self):
        output = subprocess.check_output(["adb", "devices"])
        starting_time = time.time()
        while "offline" in output and time.time() < starting_time + 20:
            subprocess.check_output(["adb", "kill-server"])
            time.sleep(1)
            subprocess.check_output(["adb", "start-server"])
            time.sleep(5)
            output = subprocess.check_output(["adb", "devices"])

        serial = output.rsplit("\n")[1].rsplit("\t")[0].strip()
        print "Device serial: %s" % serial
        return serial


    def _get_monitor_name(self):
        output = subprocess.check_output(["adb", "shell", "dumpsys", "|", "findstr", "wifiP2pDevice=Device"], shell=True)
        start_index = output.rfind('Device: ', 0)
        start_index = start_index + 8
        end_index = output.rfind("\n", 0)
        name = output[start_index : end_index].strip()
        return name


    def is_mac_address(self, address):
        boo = False
        boo = self.automation_handle.exists(description='VideoView ' + address)
        return boo


    def reboot(self):
        checkBootComp = subprocess.check_output('adb {} shell getprop sys.boot_completed'.format(self.serial))
        print('start rebbot monitor')
        os.system('adb {} reboot'.format(self.serial))
        self.is_boot_completed(checkBootComp)
        print('reboot monitor completed')


    def is_boot_completed(self , bootCompCmd):
        screenUp = '-1'
        while screenUp != bootCompCmd:
            time.sleep(1)
            try:
                screenUp = subprocess.check_output('adb {} shell getprop sys.boot_completed'.format(self.serial))
            except Exception:
                print('waiting for monitor' )
        print('Screen up and fully loaded')
        return True
开发者ID:danielScreenovate,项目名称:ConnectionTime,代码行数:55,代码来源:Monitor.py


示例9: __init__

 def __init__(self, deviceserial):
     '''
     Constructor
     '''
 
 #sndLog = CLS("test", "test")
     self.osType = sys.platform
     
     self.mstrInfo = {}
     
     #self.devSerials = self.instAdb.device_serial()
     self.mstrDevice = Device(deviceserial)
     self.mstrInfo = self.mstrDevice.info
开发者ID:sqler21c,项目名称:Python,代码行数:13,代码来源:ModelInfo.py


示例10: __init__

 def __init__(self,sn,app):
     self.dev_sn = sn
     self.device = Device(self.dev_sn)
     self.dev_displayHeight = self.device.info['displayHeight']
     self.dev_displayWidth = self.device.info['displayWidth']
     self.icon_x = self.dev_displayWidth * 12 / 100
     self.icon_y = self.dev_displayHeight * 52 / 100
     self.is_app_settings_done = False
     if len(app) > 0 and app[0] != '':
         self.app_name = app[0]
     if len(app) > 1 and app[1] != '':
         self.app_path = app[1]
         self.app_package_name = self.get_package_name()
         self.install_app()
     if len(app) > 2 and app[2] != '':
         self.app_package_name = app[2]
     else:
         self.app_package_name = os.popen("adb -s %s shell pm list package | grep -i %s | awk -F ':' '{print$2}'"%(self.dev_sn,self.app_name)).read().strip("\r\n")
     self.set_app_settings_done_flag()
     self.clean_result()
     self.load_resource()
开发者ID:yangjiandagege,项目名称:AutoTestPython,代码行数:21,代码来源:test.py


示例11: set_serial

    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)
开发者ID:huaping,项目名称:StabilityKPI,代码行数:22,代码来源:UiTestLib.py


示例12: set_serial

    def set_serial(self, android_serial):
        """
        Specify given *android_serial* device to perform test.

        You do not have to specify the device when there is only one device connects to the computer.

        When you need to use multiple devices, do not use this keyword to switch between devices in test execution.

        Using different library name when importing this library according to http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.4#setting-custom-name-to-test-library.

        | ==Setting== | ==Value== |  ==Value== |  ==Value== | 
        | Library | Mobile | WITH NAME | Mobile1 |
        | Library | Mobile | 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.adb = ADB(android_serial)
        self.device = Device(android_serial)
        self.test_helper = TestHelper(self.adb)
开发者ID:am01230123,项目名称:furry-ironman,代码行数:24,代码来源:Mobile.py


示例13: AndroidDevice

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,代码行数:101,代码来源:android.py


示例14: enable_developer_setting

from uiautomator import Device
import utility.common as u
def enable_developer_setting(self, name):
	checkbox = self(className="android.widget.ListView",resourceId="android:id/list").\
			child_by_text(name,className="android.widget.LinearLayout").\
			child(className="android.widget.CheckBox")

	if checkbox.checked == False:
		print (name + " is not enabled, enabling it")
		checkbox.click()
	else:
		print(name + " enabled")
        
def ChangeDeveloper_settings(self):
	package = 'com.android.settings'
	activity = '.DevelopmentSettings'
	component_name = package + '/' + activity
	u.start_activity(self,component_name)
	self.wait.update()
	enable_developer_setting(self,u'Stay awake')
	enable_developer_setting(self,u'Allow mock locations')

if __name__ == '__main__':
	d = Device()
	d.wakeup()
    # Press the HOME button to start the test from the home screen
	d.press.home()
	ChangeDeveloper_settings(d) 
    # Press the HOME button to start the test from the home screen
#	d.press.home()
开发者ID:jimlin95,项目名称:android_automated_test,代码行数:30,代码来源:setdevelop.py


示例15: test

class test(object):
    dev_sn = ""
    dev_displayHeight = 0
    dev_displayWidth = 0
    icon_x = 0
    icon_y = 0
    app_name = ""
    app_path = ""
    app_package_name = ""
    class_name = ""
    result = ""
    install_time = ""
    device = Device();

    DIR_VERT, DIR_HORIZ ,DIR_NONE = range(3)
    SWIPE_DIR_UP, SWIPE_DIR_DOWN, SWIPE_DIR_LEFT, SWIPE_DIR_RIGHT = range(4)

    def __init__(self,sn,app):
        self.dev_sn = sn
        self.device = Device(self.dev_sn)
        self.dev_displayHeight = self.device.info['displayHeight']
        self.dev_displayWidth = self.device.info['displayWidth']
        self.icon_x = self.dev_displayWidth * 12 / 100
        self.icon_y = self.dev_displayHeight * 52 / 100
        self.is_app_settings_done = False
        if len(app) > 0 and app[0] != '':
            self.app_name = app[0]
        if len(app) > 1 and app[1] != '':
            self.app_path = app[1]
            self.app_package_name = self.get_package_name()
            self.install_app()
        if len(app) > 2 and app[2] != '':
            self.app_package_name = app[2]
        else:
            self.app_package_name = os.popen("adb -s %s shell pm list package | grep -i %s | awk -F ':' '{print$2}'"%(self.dev_sn,self.app_name)).read().strip("\r\n")
        self.set_app_settings_done_flag()
        self.clean_result()
        self.load_resource()

    def get_package_name(self):
        p = re.compile(r"package: name=\'([\w+.]*)\'")
        s = os.popen("./aapt dump badging  %s | grep -i package"%(self.app_path)).read()
        package_name = re.findall(p,s)
        return ''.join(package_name)

    def icon_click(self):
        os.system("adb -s %s shell input tap %s %s"%(self.dev_sn,self.icon_x,self.icon_y))

    def my_func_name(self):
        return inspect.stack()[1][3]

    def logout(self,function_name,log):
        print ">>> (%s) [%s.%s] :"%(self.app_name, self.__class__.__name__, function_name)+log

    def is_AppBench_root_page(self):
        if self.device(text="AppBench").exists and self.device(text="Tutorial").exists:
            return True
        else:
            return False

    def wait_for_fps_result(self):
        self.logout(self.my_func_name(),"...")
        while True:
            if self.is_AppBench_root_page() == False:
                if self.device(text="AppBench").exists:
                    return True
                else:
                    continue
            else:
                return False

    def swipe_vert(self,swipe_times,direction):
        if direction == self.SWIPE_DIR_UP:
            src_x = self.dev_displayWidth / 2
            src_y = self.dev_displayHeight * 4 / 5
            des_x = self.dev_displayWidth / 2
            des_y = self.dev_displayHeight * 1 / 5
        elif direction == self.SWIPE_DIR_DOWN:
            src_x = self.dev_displayWidth / 2
            src_y = self.dev_displayHeight * 1 / 5
            des_x = self.dev_displayWidth / 2
            des_y = self.dev_displayHeight * 4 / 5
        else:
            self.logout(self.my_func_name(),"direction is error...")
            return False
        for i in range(swipe_times):
            self.device.swipe(src_x,src_y,des_x,des_y,steps=20)
        return True


    def swipe_horiz(self,swipe_times,direction):
        if direction == self.SWIPE_DIR_RIGHT:
            src_x = self.dev_displayWidth  * 1 / 5
            src_y = self.dev_displayHeight / 3
            des_x = self.dev_displayWidth * 4 / 5
            des_y = self.dev_displayHeight  / 2
        elif direction == self.SWIPE_DIR_LEFT:
            src_x = self.dev_displayWidth  * 4 / 5
            src_y = self.dev_displayHeight / 3
            des_x = self.dev_displayWidth * 1 / 5
#.........这里部分代码省略.........
开发者ID:yangjiandagege,项目名称:AutoTestPython,代码行数:101,代码来源:test.py


示例16: asleep

"""
    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,代码行数:23,代码来源:warm.py


示例17: Device

# -*- coding: utf-8 -*-
'''
Created on 2014/3/31

@author: YuMing
'''
from uiautomator import Device
import time
import datetime
import os

if __name__ == '__main__':
    print 'start'

#     output_dir = 'C'
#     ts = time.time()
#     st = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S')
#     screenshot_path = '%s%s%s' % (output_dir, os.sep, st)
#     print screenshot_path
    d = Device('0489902425228ab9')
    d.orientation = "upsidedown"
#     print len(d(descriptionContains='Sync'))

    print 'end'
开发者ID:am01230123,项目名称:furry-ironman,代码行数:24,代码来源:MyPython.py


示例18: Mobile

class Mobile():

    def __init__(self):
        pass

    def set_serial(self, android_serial):
        """
        Specify given *android_serial* device to perform test.

        You do not have to specify the device when there is only one device connects to the computer.

        When you need to use multiple devices, do not use this keyword to switch between devices in test execution.

        Using different library name when importing this library according to http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.4#setting-custom-name-to-test-library.

        | ==Setting== | ==Value== |  ==Value== |  ==Value== | 
        | Library | Mobile | WITH NAME | Mobile1 |
        | Library | Mobile | 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.adb = ADB(android_serial)
        self.device = Device(android_serial)
        self.test_helper = TestHelper(self.adb)

    def get_device_info(self):
        """
        Retrieve the device info.

        The keyword will return a dictionary.

        You can log the information by using the log dictionary keyword in build in Collections library(http://robotframework.googlecode.com/hg/doc/libraries/Collections.html?r=2.8.4).

        Example:
        | ${device_info} | Get Device Info |
        | Log Dictionary | ${device_info}  |

        =>

        Dictionary size is 9 and it contains following items:\n
        currentPackageName: com.android.keyguard\n
        displayHeight: 1776\n
        displayRotation: 0\n
        displaySizeDpX: 360\n
        displaySizeDpY: 640\n
        displayWidth: 1080\n
        naturalOrientation: True\n
        productName: hammerhead\n
        sdkInt: 19\n

        Or get specific information of the device by giving the key.

        | ${device_info}  | Get Device Info | | |
        | ${product_name} | Get From Dictionary | ${device_info} | productName |

        =>

        ${product_name} = hammerhead

        """
        return self.device.info

#Key Event Actions of the device
    """
    Turn on/off screen
    """
    def turn_on_screen(self):
        """
        Turn on screen
        """
        self.device.screen.on()

    def turn_off_screen(self):
        """
        Turn off screen
        """
        self.device.screen.off()

    """
    Press hard/soft key
    """

    def press_key(self, *keys):
        """
        Press *key* keycode.

        You can find all keycode in http://developer.android.com/reference/android/view/KeyEvent.html

        """
        #not tested
        self.device.press(*keys)

    def press_home(self):
        """
        Press home key
#.........这里部分代码省略.........
开发者ID:am01230123,项目名称:furry-ironman,代码行数:101,代码来源:Mobile.py


示例19: connect

 def connect(self):
     self.d = Device(self.serialno)
开发者ID:yra99ary,项目名称:AutoSense_2,代码行数:2,代码来源:Adb.py


示例20: hold_call

def hold_call(callee):
    d=Device(callee.id,adb_server_host='127.0.0.1',adb_server_port=5037)
    print "finding the button"
    d(resourceId='com.asus.asusincallui:id/holdButton').click()
    d.screenshot('incall.png')
    print "pressed the button"
开发者ID:IqbalHassan,项目名称:Framework_0.1,代码行数:6,代码来源:AndroidUI.py



注:本文中的uiautomator.Device类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python myDevice.d函数代码示例发布时间:2022-05-27
下一篇:
Python uiautomator.AutomatorServer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap