NO.7 appium-模拟键盘

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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没发现啥实际用途

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

菜齐了!!

以上是关于NO.7 appium-模拟键盘的主要内容,如果未能解决你的问题,请参考以下文章

如何在 iOS 模拟器上使用某种语言键盘启动 Appium 测试

appium键盘输入

iOS 模拟器 - 以编程方式禁用连接硬件键盘

Appium appium 基础之键盘处理

appium手机键盘实现方法

如何使用Java关闭appium中的键盘?