这几天本想研究下用robotframework+HTTP library (Requests)来做接口测试(http协议), 安装完Requests库后,在RIDE里导入该库时显示是红色,即导入失败(正常导入应该显示为黑色),网上也没有搜索到有用的信息,于是这几天就不停的在公司的电脑和家里的电脑上反复折腾。今天在家休息,继续折腾,功夫不负有心人,终于搞定了,在此记录下。
一、问题现象描述:
我电脑上本来安装的有robotframework+Selenium2Library环境(robot framework环境搭建),于是我直接在命令行运行:pip install -U robotframework-requests 来安装RequestsLibrary,然后用RIDE导入时,如下图,Selenium2Library他DatabaseLibrary都是正常的,偏偏RequestsLibrary是红色的。
二、问题解决过程:
首先,我怀疑安装的有问题,于是到安装目录(我的是:C:\Python27\Lib\site-packages)下查看是否存在RequestsLibrary库,发现该目录下存在下面两个安装文件夹:
- RequestsLibrary
- robotframework_requests-0.3.8-py2.7.egg-info
安装的应该没问题,安装没问题那是什么有问题?我怀疑是与环境安装有关。
于是,为了排除一切可能的X因素,我就把电脑上之前安装的的环境全部卸载干净后,全部在重新安装。可惜这次安装完成后,问题依然没有解决。不过问题虽然没有解决,但可以排除与安装包和环境没有关系。到这时我又开始怀疑是缺少某个依赖包。(开源的就是这样, 安装时会依赖很多其它的包)
最后,RIDE有个Import Failed Help功能(上图中红色框的部分),点击一下这个按钮,弹出如下图提示,说的还是挺详细的:
1、导入失败显示红色
2、可以在 Tools / View RIDE Log 下查看详细的失败日志。
3、。。。
根据上面第2点找到的错误日志:
20150503 08:38:55.590 [INFO]: Started RIDE 1.3 using python version 2.7.8 with wx version 2.8.12.1 in win32. 20150503 08:38:59.105 [WARN]: Importing test library "RequestsLibrary" failed Traceback (most recent call last): Importing test library 'RequestsLibrary' failed: ImportError: No module named requests Traceback (most recent call last): File "C:\Python27\lib\site-packages\RequestsLibrary\__init__.py", line 1, infrom RequestsKeywords import RequestsKeywords File "C:\Python27\lib\site-packages\RequestsLibrary\RequestsKeywords.py", line 1, in import requests PYTHONPATH: C:\Python27\lib\site-packages\robotide\lib\robot\libraries C:\Python27\lib\site-packages\robotide\lib C:\Python27\lib\site-packages\wx-2.8-msw-unicode C:\Python27\lib\site-packages\wx-2.8-msw-unicode C:\Python27\lib\site-packages\setuptools-5.4.1-py2.7.egg C:\Python27\lib\site-packages\pip-6.1.1-py2.7.egg C:\Windows\system32\python27.zip D:\Program Files\VisualSVN Server\bin D:\Program Files\VisualSVN Server\PythonPackages C:\Python27\DLLs C:\Python27\lib C:\Python27\lib\plat-win C:\Python27\lib\lib-tk C:\Python27 C:\Python27\lib\site-packages . C:\Users\Administrator\Desktop C:\Python27\lib\site-packages\robotide\spec File "C:\Python27\lib\site-packages\robotide\spec\librarymanager.py", line 76, in _fetch_keywords return get_import_result(path, library_args) File "C:\Python27\lib\site-packages\robotide\spec\libraryfetcher.py", line 20, in get_import_result lib = TestLibrary(path, args) File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 37, in TestLibrary libcode = importer.import_class_or_module(name) File "C:\Python27\lib\site-packages\robotide\lib\robot\utils\importer.py", line 64, in import_class_or_module self._raise_import_failed(name, err) File "C:\Python27\lib\site-packages\robotide\lib\robot\utils\importer.py", line 102, in _raise_import_failed raise DataError('\n'.join(msg))
问题终于找到了,原来是少了 requests,安装地址:https://pypi.python.org/pypi/requests
命令行窗口运行:pip install requests
再次用RIDE导入RequestsLibrary,成功:
开启愉快的研究之旅了。。。。。。