Robotframework-Appiumlibrary-长按扩
2017-06-20 本文已影响0人
御剑逍遥
Robot framework 降低了使用的门槛,同时也降低了代码的灵活性,扩展起来不那么方便,到底还能不能扩展,答案的肯定。

robotframework-appiumlibrary是基于Appium-Python-Client的关键字封装,我们扩展的是关键字的时长,所以我们需要找到robotframework-appiumlibrary的源码进行修改
1.github下载源码
https://github.com/serhatbolsu/robotframework-appiumlibrary
通过git或者直接下载压缩包都是可以的
git clone https://github.com/jollychang/robotframework-appiumlibrary.git
2.修改源码
用pycharm把robotframework-appiumlibrary工程打开,我们在keywords包下找到_touch.py就可以找到long_press的相关代码

3.分析源码
查看如下源码我们发现long_press(element)只有一个参数是界面元素,压根没有时间时间相关的参数设置,所以我们基本确定在这里动手了基本可以解决问题
def long_press(self, locator):
""" Long press the element """
driver = self._current_application()
element = self._element_find(locator, True, True)
long_press = TouchAction(driver).long_press(element)
long_press.perform()
4.修改源码
查看Appium-Python-Client的API之后我们会发现TouchAction(driver).long_press(element)方法有一个duration的参数是来控制时长的,这样基本上找到解决问题的方法了
def long_press(self, locator,times):
""" Long press the element with times is second
Args:
- ``locator`` - find element by locator
- ``times`` - long press the element times is second
"""
driver = self._current_application()
element = self._element_find(locator, True, True)
TouchAction(driver).long_press(element,duration=int(times)*1000).perform()
5.安装修改的代码
卸载已经安装的robotframework-appiumlibrary
#卸载
pip uninstall robotframework-appiumlibrary
#查看是否已经卸载
pip list
安装修改后的robotframework-appiumlibrary
#进入工程的根目录
cd robotframework-appiumlibrary
#执行安装命令
python setup.py install
6.验证是否安装成功
打开RIDE,F5就可以查看,我们会发现关键字的注释与参数都发生了改变,也就是我们对源码的改动产生了效果

7.跑一下微信发送语音看看效果
脚本编写

脚本采用分层实现,TestCase->业务关键字->基础关键字

最后来一张微信截图
