如果在资源文件中使用,机器人框架记录器不会将信息添加到调试文件

时间:2019-03-07 05:38:41

标签: python logging robotframework

我的机器人套件具有以下结构

let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
button.backgroundColor = UIColor.green
button.setTitle("Test Button", for: .normal)
button.addTarget(self, action: #selector(buttonClicked), for: .touchUpInside)
self.view.addSubview(button)

dinesh.robot

S_SUITE
├── datasource.txt
├── dinesh.robot
├── __init__.py
└── test.py

datasource.txt

 *** Settings ***
Library        test.py
Resource    datasource.txt
*** Test Cases ***
DEMO
    Log    "Testcase start"
    sample
    Log    "Testcase end"

__ init __。py

*** Settings ***
Library   __init__.py

test.py

from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn
# These below messages are not seen in debug_record.txt
logger.info('Expected to see this!!!')
logger.error('At least this in debug_record')

def hai():
  # These below messages are also not seen in debug_record.txt
  BuiltIn().log("this is an info message", "INFO")
  logger.info('this is an info too')

hai()

我以

的身份运行此套件
from robot.api import logger
def sample():
    # Only the below logger.info is added into debug_record.txt
    logger.info('THIS IS INSIDE SAMPLE')

当我运行此套件时,单独的消息 robot --loglevel debug --debugfile debug_record.txt S_SUITE/ 被添加到THIS IS INSIDE SAMPLE中。 debug_record.txt中的datasource.txt包含dinesh.robot文件。该文件包含很少的__init__.py语句,这些语句从未登录到logger.info中。

除了debug_record.txt外,我还尝试了logger.infologger.error。但是没有运气。我注意到BuiltIn().log在控制台中打印错误,并且还将相同的信息发送到logger.error,但没有发送到log.html

似乎debug_record.txt仅在测试用例内部(即测试用例运行时)以及套件的logger使用记录器的地方才向debug_record.txt添加信息,则不会将信息添加到Resource

如何解决此问题?

debug_record.txt:

debug_record.txt

1 个答案:

答案 0 :(得分:0)

您的问题有很多方面。但是我认为您在调试文件中看到的是正确的。

1)使用静态库API导入库 当Robot Framework从您的库中找到关键字时,它不会执行代码。相反,Robot Framework使用反射来发现关键字。因此,当您导入静态库时,不会发生日志记录。

但是导入系统很复杂,因此上述情况并不总是正确的。根据所使用的库API以及您是否导入模块或类,关键字的发现以不同的方式发生。例如,如果您导入类并从应该出现在调试文件中的库 init 中进行登录。

2)从未执行的关键字登录。 未执行的关键字不会生成日志记录。

3)从执行关键字登录 如您所说,这已记录下来,并且有望出现在日志文件中。