通过 APScheduler 运行 Robot Framework 任务时,log.html 中未生成日志

问题描述 投票:0回答:1

直接运行Robot Framework任务时,日志会按预期生成在log.html文件中。但是,当同一任务注册为 APScheduler 作业并由计划任务执行时,日志不会出现在 log.html 中。

这是计划任务的代码:

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
import robot
from datetime import datetime, timedelta

# Define the function to execute the Robot Framework task
def run_robot_task(robot_file_path):
    # Generate report directory
    report_dir = "./"

    # Run the Robot Framework task
    robot.run(robot_file_path, outputdir=report_dir)

# Create the APScheduler background scheduler
scheduler = BackgroundScheduler()

# Define the scheduling time, using IntervalTrigger to execute every 60 seconds
job_trigger = IntervalTrigger(seconds=60)

# Provide the actual Robot Framework file path
robot_file_path = "./3.robot"

# Register the job
scheduler.add_job(run_robot_task, job_trigger, args=[robot_file_path], id="robot_task",
                  name="Execute Robot Framework Task", next_run_time=datetime.now() + timedelta(seconds=5))

# Start the scheduler
scheduler.start()

# Keep the main thread running to ensure the task continues to schedule
try:
    while True:
        pass
except (KeyboardInterrupt, SystemExit):
    # Shutdown the scheduler
    scheduler.shutdown()

这是3.robot的代码

*** Settings ***
Library    Collections
Library    SeleniumLibrary
Library    DateTime
Library    OperatingSystem
Library    BuiltIn


*** Variables ***

${DETAILS_BUTTON_XPATH}    //*[@id="details-button"]
${PROCEED_LINK_XPATH}    //*[@id="proceed-link"]
${SRARCH_SHOW_HIDE}    //*[@id="search_show_hide"]

*** Test Cases ***
Open Browser With Custom Proxy
    ${version}=    Evaluate    robot.__version__
    Log    Robot Framework version: ${version}  console=True
    Log    Robot Framework version: ${version}    level=INFO
    Log    This is an info message    level=INFO
    Log    This is a debug message    level=DEBUG
    Log    This is a trace message    level=TRACE

btw这是log.html,只有第一步有log enter image description here

robotframework apscheduler
1个回答
0
投票

如果有人遇到类似的情况,您可以将执行器类型从线程池更改为进程池,这应该可以解决问题。但具体原因尚不清楚。

© www.soinside.com 2019 - 2024. All rights reserved.