robotframework基础入门:(3):找不到关键字的对应方法

版权声明:本文为博主原创文章,未经博主允许欢迎转载,但请注明出处。 https://blog.csdn.net/liumiaocn/article/details/82255614

这篇文章记录一下robotframe执行中出现No keyword with name的对应方法

现象

错误提示信息:No keyword with name ‘Title Should Be’ found.

sh-4.2# robot test.robot
==============================================================================
Test                                                                          
==============================================================================
Check something :: Check the page title                               | FAIL |
No keyword with name 'Title Should Be' found.
------------------------------------------------------------------------------
Test                                                                  | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  /tmp/output.xml
Log:     /tmp/log.html
Report:  /tmp/report.html
sh-4.2#

原因&确认方式

代码不用再贴了,因为这篇文章主要用来说明出现类似低级问题的确认内容和方法。

可能原因1:没有导入对应的库

robot的测试脚本中如果缺少关键字对应的库,自然会出错,唯一的一个例外就是BuildIn内置库可以不用写。因为此关键字在Selenium2Library中,所以需要检查脚本的Settings中是否有如下的内容

Library                     Selenium2Library

可能原因2:写错关键字名称

这看起来虽然很像一个笑话,但是请仔细检查一下,如果你却是将Library导入了,但是又认不出来,看看是不是多个空格什么的,仔细,仔细,仔细。

上面两种原因有可能有各种方式的变形,导致以为没有问题实际却有问题,那么长的英文关键字写错一点根本不好认,汉字的优势在这里显现的淋漓尽致,可以考虑使用汉字来写关键字可能会更加简练和有效率。

可能原因3:其他原因

从这个原因开始进入宿命论的角度,但是往往会存在,可能安装了多个版本,之间相互冲突,或者环境的问题,依赖的问题,网络的问题等。

确认方式

以下以Title Should Be关键字找不到为例,介绍一下如何进行问题定位。
首先确认Title Should Be关键字在那个库中,会写robot的测试脚本,自然知道这是robot使用selenium库中所提供的关键字,用于确认打开的页面的title与输入的参数是否一致的关键字,相关的库名为Selenium2Library

确认pip的package

robot本身是使用python开发的,robotframework本身就是使用pip进行安装的,其他相关的package也是一样。
因为Selenium2Library是以robotframework-selenium2library为载体的,首先看看此package是否进行了安装。

~ # pip show robotframework-selenium2library
Name: robotframework-selenium2library
Version: 3.0.0
Summary: Web testing library for Robot Framework
Home-page: https://github.com/robotframework/Selenium2Library
Author: Tatu Aalto
Author-email: aalto.tatu@gmail.com
License: Apache License 2.0
Location: /usr/lib/python2.7/site-packages
Requires: robotframework-seleniumlibrary
Required-by: 
~ # 

确认安装的库

python的库使用pip安装后,如果当前系统是python2.7的话,会被安装在如下目录:
/usr/lib/python2.7/site-packages/xxxx,比如

/usr/lib/python2.7/site-packages # ls
README                                           robotframework-3.0.4-py2.7.egg-info
Selenium2Library                                 robotframework_selenium2library-3.0.0.dist-info
SeleniumLibrary                                  robotframework_seleniumlibrary-3.1.1.dist-info
easy_install.py                                  selenium
easy_install.pyc                                 selenium-3.14.0.dist-info
pip                                              setuptools
pip-18.0.dist-info                               setuptools-33.1.1.post20171031-py2.7.egg-info
pkg_resources                                    urllib3
robot                                            urllib3-1.23.dist-info
/usr/lib/python2.7/site-packages # 

确认此目录:

  • 是否存在
  • 名字是否与robot脚本中的引用名一致

经过确认Selenium2Library确实存在,并且Selenium2Library的写法也与robot脚本一致。

确认是否能够进行import

在robot运行的OS上使用python确认是否能够正常import相关的库,比如此例中应该能够想如下这样正常import而不出error

~ # python
Python 2.7.15 (default, Aug 22 2018, 13:24:18) 
[GCC 6.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Selenium2Library
>>>

这样基本上就能说明环境本身没有问题,剩下的就多多检查一下robot的脚本或者robot的版本即可。

猜你喜欢

转载自blog.csdn.net/liumiaocn/article/details/82255614
今日推荐