Robot Framework自动化测试过程中,运行多次后会出现RIDE没有log的情况。

造成这种现象的原因是:

执行失败的测试用例,chrome.exe和chromedriver.exe进程没有关闭。

解决方法:手动关闭chromedriver进程,ride就可以正常运行。

但是每次手动去关闭chromedriver进程比较麻烦,

---------------------------------------------------------------------------------------------------------

下面给大家介绍一种自动化关闭进程的方法:

在执行测试用例时,先调用关闭进程的批处理文件,关闭进程后再接着去执行下一步测试用例。

1.       创建关闭进程的批处理文件

将下面的代码保存为批处理文件killChrome.bat(存放路径:D:\RobotTest\测试项目)。

创建批处理比较简单,难的是如何封装系统关键字

关键字需求:接收一个目录路径,自动遍历目录下以及子目录下的所有批处理(.bat)文件并执行。

2.       封装系统关键字

在..\Python2.7\Lib\site-packages目录下创建CustomLibrary目录,用于放自定义的library库。在其下面创建runbat.py文件(其中的path路径为killChrome.bat的存放路径):

 # -*- coding: UTF-8 -*-
# 作用:执行批处理文件
#
# 创建者:大道OA团队 大东哥
#
# 创建时间:2017-09-21
# __version__ = "1.0" from robot.api import logger
import os class Runbat(object): def run_all_bat(self,path):
"""
接收一个目录的路径,并执行目录下的所有bat文件. Usage is:
| run all bat | filepath |
"""
for root,dirs,files in os.walk(path):
for f in files:
if os.path.splitext(f)[1] == '.bat':
os.chdir(root)
os.system(f) def __execute_sql(self, path):
logger.debug("Executing : %s" % path)
print path def decode(self,customerstr):
return customerstr.decode('utf-8') if __name__ == '__main__':
path = u'D:\\RobotTest\\测试项目'
run = Runbat()
run.run_all_bat(path)

注意在run_all_bat()方法下面加上清晰的注释,最好给个实例。这样在robot framework 的帮助中能看到这些信息,便于使用者理解这个关键字的使用。

对于创建普通的模块来说这样已经ok了。但要想在robot framework启动后加载这个关键字,还需要在CustomLibrary目录下创建__init__.py文件,并且它不是空的。

 # Copyright 2009-2015 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. from CustomLibrary.runbat import Runbat __version__ = "1.0" class CustomLibrary(Runbat): ROBOT_LIBRARY_SCOPE = 'GLOBAL'

这个文件中其实有用的信息就四行,但必不可少。robot framwork 在启动时会加载这个文件,因为在这个文件里指明了有个runbat文件下面有个Runbat类。从而加载类里的方法(run_all_bat())。注意.py文件的编码(utf-8编码)和缩进格式,不然无法导入库。

下面,启动robot framework RIDE,按F5:

找到了我们创建的关键字,下面就是在具体的项目或测试套件中引用CustomLibrary

然后,在具体的测试用例中使用“run all bat” 关键字。(关键字后面需填入killChrome.bat的存放路径,注意斜杠)

这样在每次执行用例时,ride会先去关闭Chrome和ChromeDriver进程,然后再去执行测试用例。

最新文章

  1. ASP.NET Core CORS 简单使用
  2. 还有 3 天,苹果就要关上 HTTP 大门了
  3. PLSQL win7 64位
  4. 使用phantomjs操作DOM并对页面进行截图需要注意的几个问题
  5. struts2标签获取parameter,request,session,application中的值
  6. hive 面试题 转载
  7. ORA-04091: 表 发生了变化, 触发器/函数不能读它
  8. Shredding Company(dfs)
  9. UVA_Digit Puzzle UVA 12107
  10. mysql中判断表中是否存在某条记录
  11. Bootstrap-table使用记录(转)
  12. python高级编程
  13. go语言的运算符
  14. Linux shell(5)
  15. 进程通信方式-管道pipe
  16. python-全栈开发-前方高能-内置函数
  17. selenium 各种很奇葩的异常
  18. linux tcp调优
  19. 【离散数学】 SDUT OJ 谁是作案嫌疑人?
  20. Mysql 求时间 between 昨天 and 上个月的今天 等时间函数

热门文章

  1. Eclipse导入Maven项目出现:Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.2
  2. ubuntu 16.04上安装php5.6
  3. iOS中MRC和ARC混编
  4. hdu 3853(数学期望入门)
  5. HDU 2795 Billboard(宣传栏贴公告,线段树应用)
  6. window.location.hashs属性介绍
  7. Handlebars.js 中文文档
  8. 1 TypeScript 简介与安装
  9. 【leetcode】Word Break(python)
  10. HttpWebRequest中的ContentType详解