我正在尝试使用监听器来保存来自mi测试用例的数据(在robotFramework中开发),所以我开发了这个监听器:
from robot.libraries.BuiltIn import BuiltIn
import psycopg2
import datetime
class CustomListener:
ROBOT_LISTENER_API_VERSION = 3
def __init__(self):
self.conn = psycopg2.connect(
host= "....",
port= "...",
database = "...s",
user = "j....",
password = "......")
def end_test (self, data, result):
if result ['status'] == "PASS":
execution_result='PASSED'
else:
execution_result= 'FALLIED'
test_name = result['name']
execution_start = result['start_time']
execution_end = result['end_time']
execution_duration = result['elapsedtime']
cursor = self.conn.cursor()
cursor.execute(
"INSERT INTO test_results (test_name, excecution_star, execution_end, execution_duration, execution_result) VALUES (%s, %s, %s, %s, %s)",
(test_name, execution_start, execution_end, execution_duration.total_seconds(), execution_duration)
)
self.conn.commit()
cursor.close()
在 Eclipse 上,我开发了 mi testCase,并使用以下配置运行它: 运行为 -> 其他机器人框架参数:--listener CustomListener.py
测试用例通过,但我收到此错误:
错误] 调用侦听器“C:\Users oztelecom\Documents\CustomListener.py”的方法“end_test”失败:TypeError:“TestCase”对象不可订阅
有人知道会发生什么吗?
我希望这些数据保存在 mi Postgres 数据库上。
我尝试更改 def end_test (self, data, result):对于 def end_test (self, data, attrs):
def end_test(self, name, attrs):
# Accede a los atributos del objeto attrs correctamente
test_status = attrs['status']
test_name = attrs['longname']
execution_start = attrs['starttime']
execution_end = attrs['endtime']
execution_duration = attrs['elapsedtime
不工作-
我尝试添加一个setting.robot 文件,并添加我有 CustomListener.py 文件的路径-
还是不行
result
是robot.result.model.TestCase类的实例。您将其作为字典来引用。如果您检查侦听器文档的示例,这些示例显示您应该使用点表示法:
if result.status == "PASS":
execution_result='PASSED'
else:
execution_result= 'FALLIED'
test_name = result.name
execution_start = result.start_time
execution_end = result.end_time
execution_duration = result.elapsedtime