在做web ui自动化的过程中,经常发现这样一种情况,执行时case报错啦,再重新执行一遍又成功了。

如果不解决这个问题,脚本稳定性就会变差,很让人蛋疼,怎么解决呢:

思路:

写一个装饰器,装饰在case方法上,case一但出错就抛出错误。能过装饰器去捕获,来控制重新执行case。

代码:

def replayCaseFail(num=3):
def _warpper(func):
def warpper(*args,**kwargs):
raise_info = None
rnum = 0
for i in range(num):
rnum +=1
try:
ret = func(*args,**kwargs)
if rnum > 1:
print('重试{}次成功'.format(rnum))
return ret
except Exception as ex:
raise_info = ex
print('重试{}次,全部失败'.format(rnum))
raise raise_info
return warpper
return _warpper

以上代码,经实际使用没有问题,也可以结合着unittest使用,或者ddt驱动装饰器使用,但要注意位置。

要放在最底层的,最靠近函数的位置。否则其它装饰器有可能会报错。

示例代码:

    @unittest.skipIf(getRunFlag('CHARGE', 'testCase2') == 'N', '验证执行配置')
@ddt.data(*FillData)
@replayCaseFail(num=3) #case执行失败后,重新执行num次
def testCase2(self,data):
"""储值并补开发票""" # 调用储值功能函数
self.chargeFunc(data) """补开发票"""
#单击 补开发票按钮
self.charge.clickFillReceipt
#获取 未开票金额
notFillPresent = self.charge.getNotFillPresent(data['txtName'])
#输入 开票金额
self.charge.inputFillPresent(notFillPresent)
#单击 确定 开发票
self.charge.clickFillConfirmBtn

selenium case报错重新执行的更多相关文章

  1. selenium启动报错“ incorrect JSON status mapping for 'unknown error' (500 expected)”

    前面讲了工程启动报错“selenium启动报错Unable to read VR Path Registry from C:\Users\clinva\AppData\Local\openvr\ope ...

  2. PLSQL报错:"动态执行表不可访问,本会话的自动统计被禁止"

      PLSQL报错:"动态执行表不可访问,本会话的自动统计被禁止" CreationTime--2018年7月16日19点26分 Author:Marydon 1.情景展示 2.解 ...

  3. selenium+phantomjs报错:Unable to find a free port的分析和解决

    selenium+phantomjs报错:Unable to find a free port的分析和解决 Table of Contents 1. 现象 2. 分析 3. 解决办法 1 现象 在做项 ...

  4. selenium python 报错“ unable to find binary in default location”

    selenium python 报错如下: raise exception_class(message, screen, stacktrace)selenium.common.exceptions.W ...

  5. 【Selenium】【BugList7】执行driver.find_element_by_id("kw").send_keys("Selenium"),报错:selenium.common.exceptions.InvalidArgumentException: Message: Expected [object Undefined] undefined to be a string

    [版本] selenium:3.11.0 firefox:59.0.3 (64 位) python:3.6.5 [代码] #coding=utf-8 from selenium import webd ...

  6. python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...

  7. 使用Selenium模块报错的解决办法 (FileNotFound,WebDriverException)

    添加Chrome浏览器程序的目录到系统Path变量中: C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application ,使用pip3 inst ...

  8. 【Selenium】【BugList11】启动selenium server报错:Unsupported major.minor version 52.0

    [环境信息] python:3.6.5 平台:win7 selenium:3.11.0 selenium server:selenium-server-standalone-3.11.0.jar jd ...

  9. python selenium phantomjs 报错

    报错: webdriver.PhantomJS() raise exception_class(value)selenium.common.exceptions.WebDriverException: ...

随机推荐

  1. Vuex详解

    一.什么是Vuex 官网解释如下: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex ...

  2. FlexCel 插入公式和插入新行

    //http://www.tmssoftware.biz/flexcel/doc/vcl/api/FlexCel.Core/TExcelFile/InsertAndCopyRange.html#tex ...

  3. JS中常用的Math方法

    1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); ...

  4. Rafy环境配置

    如果现在项目已经创建好啦,要使用Rafy框架进行存储,这里我简单的总结下配置的环境步骤: 一.添加引用Rafy的SDK,如下几个; 二.新建文件夹Entities 在此文件夹下创建rafy实体以及仓库 ...

  5. 一、Sql Server 基础培训《进度1-建库建数据表(实际操作)》

    知识点: 1.建数据库示例参考 --创建一个数据库名为‘dbtest’ create database dbtest go --打开数据库 dbtest use dbtest go 2.建表示例参考 ...

  6. Visual Studio 2010 VS IDE 编辑界面出现绿色的点 去掉绿色的空格点

    Visual Studio  2010 VS IDE 编辑界面出现绿色的点 去掉绿色的空格点 Vs乱按一顿忽然出现一堆绿色的点,我去好难看,还不知道什么鬼,查了查其实就是个 每个点表示一个空格 让他显 ...

  7. C#WinForm无边框窗体移动方法、模仿鼠标单击标题栏移动窗体位置

    C#WinForm无边框窗体移动方法.模仿鼠标单击标题栏移动窗体位置 这里介绍俩种办法 方法一:直接通过修改窗体位置从而达到移动窗体的效果 方法二:直接伪装发送单击任务栏消息,让应用程序误以为单击任务 ...

  8. PXC 57 二进制安装

    1.准备阶段 1.1 在三个节点上分别创建:用户组 用户组 目录 --用户组 用户组 #/usr/sbin/groupadd mysql #/usr/sbin/useradd -g mysql mys ...

  9. zhenya moves from parents

    Zhenya moved from his parents' home to study in other city. He didn't take any cash with him, he onl ...

  10. 最小生成树 prime+heap

    改一个错误真不容易,刚开始没有加上used数组,没有判断每个顶点是否已经加入到数组当中,结果同一个顶点被pop不止一次. struct edge{int to,cost;}; typedef pair ...