selenium case报错重新执行
在做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报错重新执行的更多相关文章
- 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 ...
- PLSQL报错:"动态执行表不可访问,本会话的自动统计被禁止"
PLSQL报错:"动态执行表不可访问,本会话的自动统计被禁止" CreationTime--2018年7月16日19点26分 Author:Marydon 1.情景展示 2.解 ...
- selenium+phantomjs报错:Unable to find a free port的分析和解决
selenium+phantomjs报错:Unable to find a free port的分析和解决 Table of Contents 1. 现象 2. 分析 3. 解决办法 1 现象 在做项 ...
- selenium python 报错“ unable to find binary in default location”
selenium python 报错如下: raise exception_class(message, screen, stacktrace)selenium.common.exceptions.W ...
- 【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 ...
- 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 ...
- 使用Selenium模块报错的解决办法 (FileNotFound,WebDriverException)
添加Chrome浏览器程序的目录到系统Path变量中: C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application ,使用pip3 inst ...
- 【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 ...
- python selenium phantomjs 报错
报错: webdriver.PhantomJS() raise exception_class(value)selenium.common.exceptions.WebDriverException: ...
随机推荐
- 【交换机】交换机RLDP(环路检测&链路检测)功能介绍及配置说明
功能简介RLDP 全称是Rapid Link Detection Protocol,是锐捷网络自主开发的一个用于快速检测以太网链路故障的链路协议.一般的以太网链路检测机制都只是利用物理连接的状态,通过 ...
- C#字符串、字节数组和内存流间的相互转换
定义string变量为str,内存流变量为ms,比特数组为bt 1.字符串=>比特数组 (1)byte[] bt=System.Text.Encoding.Default.GetBytes(&q ...
- Python3 File
open() 方法 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OSError. 注意:使用 open() ...
- application.properties配置文件
SpringBoot可以识别两种格式的配置文件,分别是yml文件与properties文件,可以将application.properties文件换成application.yml applicati ...
- 深度学习中交叉熵和KL散度和最大似然估计之间的关系
机器学习的面试题中经常会被问到交叉熵(cross entropy)和最大似然估计(MLE)或者KL散度有什么关系,查了一些资料发现优化这3个东西其实是等价的. 熵和交叉熵 提到交叉熵就需要了解下信息论 ...
- java的ThreadLocal类的使用方法
java的ThreadLocal类的使用方法,ThreadLocal是一个支持泛型的类,用在多线程中用于防止并发冲突问题. 比如以下的一个样例,就是用于线程添加1,可是相互不冲突 package co ...
- DBeaver连接MySQL 8.0显示"Unable to load authentication plugin 'caching_sha2_password'."错误的问题
下载MySQL绿色版本mysql-8.0.12-winx64,手动安装完成后.使用DBeaver连接提示"Unable to load authentication plugin 'cach ...
- webpack简介与使用
欢迎小伙伴们为 前端导航仓库 点star https://github.com/pfan123/fr...前端导航平台访问 CommonJS 和 AMD 是用于 JavaScript 模块管理的两大规 ...
- linux部署的flask项目配置static
环境: Python2.7 flask nginx linux的系统是Ubantu Python:我的是linux已经有的. flask:pip install flask nginx:sudo ap ...
- L - Father Christmas flymouse
来源poj3160 After retirement as contestant from WHU ACM Team, flymouse volunteered to do the odds and ...