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: ...
随机推荐
- ng-repeat 的重复问题
如果ng-repeat绑定的数组中元素有重复, 如 $scope.data = [1,2,2] ng-repeat="value in data" //这种写法就会报错,ngRe ...
- 微信小程序——动态设置swiper的高度
根据小程序的设定,swiper组件默认高度为150px,无法根据内容来撑高.如果里面的内容固定还好说,直接设置一个高度就可以了.要是里面内容是动态变化的,这个特性使得我们使用这个组件的时候感到诸多不便 ...
- Netty 学习笔记(1)通信原理
前言 本文主要从 select 和 epoll 系统调用入手,来打开 Netty 的大门,从认识 Netty 的基础原理 —— I/O 多路复用模型开始. Netty 的通信原理 Netty 底层 ...
- 《effective Go》读后记录:GO基础
一个在线的Go编译器 如果还没来得及安装Go环境,想体验一下Go语言,可以在Go在线编译器 上运行Go程序. 格式化 让所有人都遵循一样的编码风格是一种理想,现在Go语言通过gofmt程序,让机器来处 ...
- AT&T汇编指令
GAS中每个操作都是有一个字符的后缀,表明操作数的大小. C声明 GAS后缀 大小(字节) char b 1 short w 2 (unsigned) int / long / char* l 4 f ...
- 定时 清理 elasticsearch 6.5.4 的 索引 文件
#!/bin/sh ip='127.0.0.1' port=' day=`date -d "2 days ago" +%Y%m%d` #day=`date -d "5 h ...
- [Vue warn]: Attribute "id" is ignored on component <div> because the component is a fragment instanc
今天在使用vue框架搭建环境时,遇到这个错误提示: [Vue warn]: Attribute "id" is ignored on component <div> b ...
- jQuery UI =>jquery-ui.js中sortable方法拖拽对象位置偏移问题
今天要处理sortable方法处理的对象,拖拽的时候,位置偏移的问题. 按理应该是鼠标在哪,对象就跟着在哪的 百度了一下问题,http://blog.csdn.net/samed/article/de ...
- 12 postgresql数据库备份和恢复
数据表结构备份与恢复 备份 1.找到postgres 安装目录,在找到bin文件夹,会看到一堆exe后缀的文件,用win+r 打开cmd,将pg_dump.exe 拖进cmd黑窗口中 2.基本语法:- ...
- python API whoami
import getpass print getpass.getuser() See the documentation of the getpass module. getpass.getuser( ...