Python中屏幕截图的自定义错误处理程序
我创建了一个自定义错误处理程序来处理失败时的屏幕截图Python中屏幕截图的自定义错误处理程序,python,selenium,bdd,python-behave,Python,Selenium,Bdd,Python Behave,我创建了一个自定义错误处理程序来处理失败时的屏幕截图 #error_handler.py def screenshot_handler(func): def func_wrapper(self): try: return func(self) except Exception as e: print("screenshot") return func(self) retur
#error_handler.py
def screenshot_handler(func):
def func_wrapper(self):
try:
return func(self)
except Exception as e:
print("screenshot")
return func(self)
return func_wrapper
我想获取step参数“map should display”,因此我用它创建了文件名。最明显的选择是复制字符串,但这将是低效的,是否有我可以调用的behave函数来处理此操作我在environments.py的
after_步骤
函数中执行此操作:
def after_step(context, step):
if step.status == 'failed':
step_str = step.name
# Take screen shot and upload to s3
您可以立即访问测试状态和步骤名称,并且不必包含自己的错误处理装饰程序
step
变量中有许多有趣的东西:
(Pdb) pp(dir(step))
['__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'duration',
'error_message',
'exc_traceback',
'exception',
'filename',
'keyword',
'line',
'location',
'name',
'replay',
'reset',
'run',
'set_values',
'status',
'step_type',
'store_exception_context',
'table',
'text',
'type']
步骤字符串只是
test.name
步骤字符串如何访问that@teddybear123更新了答案
def after_step(context, step):
if step.status == 'failed':
step_str = step.name
# Take screen shot and upload to s3
(Pdb) pp(dir(step))
['__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'duration',
'error_message',
'exc_traceback',
'exception',
'filename',
'keyword',
'line',
'location',
'name',
'replay',
'reset',
'run',
'set_values',
'status',
'step_type',
'store_exception_context',
'table',
'text',
'type']