When running a Robot Framework task directly, the logs are generated in the log.html file as expected. However, when the same task is registered as an APScheduler job and executed by the scheduled task, the logs do not appear in log.html.
Here is the code for the scheduled task:
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()
Here is the code for 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
If someone encounters a similar situation, you can change the executor type from threadpool to processpool, which should resolve the issue. However, the exact reason is still unclear.