码迷,mamicode.com
首页 > 移动开发 > 详细

NO.7 appium-模拟键盘

时间:2016-11-24 11:47:15      阅读:340      评论:0      收藏:0      [点我收藏+]

标签:alt   音乐   send   视频   family   define   lock   分享   sel   

最近又突发奇想,如果测试一个音乐类软件或者一个视频类软件,遇到增加音量或者快进的操作怎么办?就用"滑动"操作,拖着进度条或者音量条一点一点滑??于是乎就去搜索了一下,发现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没发现啥实际用途

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

菜齐了!!

NO.7 appium-模拟键盘

标签:alt   音乐   send   视频   family   define   lock   分享   sel   

原文地址:http://www.cnblogs.com/dianxiao2/p/5826887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!