RobotFramework通过正则校验导出文件

背景:

robotframework自动化校验导出文件除了文件名之外还加上了时间标签,比如test_20250816172359.xlsx   

解决方案:

# 获取当天的日期

${date}=    Get Current Date    result_format=%Y%m%d

@{file_list}=    List Files In Directory    ${DOWNLOAD_DIR}

 # 循环校验文件名(FOR循环内部Set Variable设置的变量对外部不生效,因此用set test variable关键字)

${found}=    Set Variable    False

FOR    ${file}    IN    @{file_list}

        ${status}=    Run Keyword And Return Status    Should Match Regexp    ${file}    test-${date}\d{2}\d{2}\d{2}.xlsx

        Run Keyword If    ${status}    Run keywords    Log    Valid file found: ${file}    level=INFO    AND   Set Test Variable    ${found}    True    AND    Exit For Loop

END

# 检查是否找到有效文件

Run Keyword Unless    ${found}    Fail    No valid file found matching pattern: ${file_name_reg}

posted @ 2025-08-14 14:17  水库浪子9527  阅读(2)  评论(0)    收藏  举报  来源