zoukankan      html  css  js  c++  java
  • NO.7 appium-模拟键盘

    最近又突发奇想,如果测试一个音乐类软件或者一个视频类软件,遇到增加音量或者快进的操作怎么办?就用"滑动"操作,拖着进度条或者音量条一点一点滑??于是乎就去搜索了一下,发现appium可以发送键码,模拟物理键的操作.嚯嚯~试一下~

    好嘞,上菜!

    1.keyevent(self, keycode, metastate=None)

    Sends a keycode to the device. Android only. Possible keycodes can be
    found in http://developer.android.com/reference/android/view/KeyEvent.html.
     
    :Args:
     - keycode - the keycode to be sent to the device
     - metastate - meta information about the keycode being sent

    这个API的大概意思是:发送一个键码到设备上

    键码表后面粘,现在我先试试    "KEYCODE_MENU":"菜单键":82


    执行代码:

    driver.keyevent(82)

    driver.keyevent('82')

    效果是一样的

    结果:

    没毛病~"菜单键",点击完,是这个效果.

    再试试另外一种写法:

    driver.keyevent(KEYCODE_MENU)

    结果:NameError: name 'KEYCODE_MENU' is not defined,报错了,说没有定义

     

    2.press_keycode(self, keycode, metastate=None)

    Sends a keycode to the device. Android only. Possible keycodes can be
    found in http://developer.android.com/reference/android/view/KeyEvent.html.
     
    :Args:
     - keycode - the keycode to be sent to the device
     - metastate - meta information about the keycode being
     sent

    这个API的大概意思是:发送一个键码到设备上


    悲催的发现press_keycode和keyevent用法是一样的,不重复写了`````也没找到,他两啥区别

     

    3.long_press_keycode(self, keycode, metastate=None)

    Sends a long press of keycode to the device. Android only. Possible keycodes can be
    found in http://developer.android.com/reference/android/view/KeyEvent.html.
     
    :Args:
     - keycode - the keycode to be sent to the device
     - metastate - meta information about the keycode being sent

    这个API的大概意思是:发送一个键码到设备上,长按

     

    driver.long_press_keycode(25)
    这个API没发现啥实际用途

    那个,键码表太长了``自己百度吧╮(╯▽╰)╭

    菜齐了!!
  • 相关阅读:
    flask 知识积累
    python中下划线
    pipenv知识积累
    shell知识积累
    AttributeError: type object 'testClass' has no attribute 'testMothod'
    python知识积累
    补全爬取的url
    linux 的基本命令
    Python里的拷贝
    关于第一次java课的感想
  • 原文地址:https://www.cnblogs.com/dianxiao2/p/5826887.html
Copyright © 2011-2022 走看看