from robot.api.deco import keyword
from robot.api import logger
def decorator():
....
do something
....
class Tester(object):
@keyword
def run_hello(self):
self.hello()
@decorator
def hello(self):
logger.info("hello word")
*** Settings ***
Library Test.py
*** Test Cases ***
Run Hello
Run Hello
当机器人运行关键字run_hello
时,python函数hello()
是否可以像机器人用户关键字一样登录到log.html?如何编写decorator
函数?
我希望log.html像图像log.html images
答案 0 :(得分:0)
我已经解决了。还有我的python代码
from functools import wraps
from robot.libraries.BuiltIn import register_run_keyword
from robot.libraries.BuiltIn import BuiltIn
def robot_run_keyword(func):
@wraps(func)
def func_wrapper(self,*args, **kwargs):
if not hasattr(func, "second"):
setattr(func, "second", True)
ar = list(args)
for key, value in kwargs.items():
ar.append("%s=%s"%(key,value))
register_run_keyword("WiseLibrary",func.__name__,len(ar),deprecation_warning=False)
return BuiltIn().run_keyword(func.__name__, *ar)
else:
delattr(func, "second")
return func(self,*args, **kwargs)
return func_wrapper