pycharm 如果测试用例中的验证点失败,则测试执行不应停止,应记录失败并继续执行robot框架中的剩余脚本

6qftjkof  于 2023-04-20  发布在  PyCharm
关注(0)|答案(1)|浏览(159)

我的测试用例中有一些验证点。即使验证部分失败,测试用例的执行也不应该停止,它应该记录失败消息并继续执行剩余的脚本

*** Test Cases ***
Validating Dropdown
    ${sums}=  ['1234','455','4689','9837']
    ${sum2}=  ['1234','455','46','9837']

    ${sum_count}=  Get Length  ${sums}
    FOR  ${i}  IN RANGE  ${sum_count}
        ${sums}[${i}]==${sum2}[${i}]
    END

    ${sums3}=  ['12','455','4689','9837']
    ${sum4}=  ['34','455','46','9837']

    ${sum_count1}=  Get Length  ${sums3}
    FOR  ${i}  IN RANGE  ${sum_count}
        ${sums3}[${i}]==${sum4}[${i}]
    END
    ${sums5}=  ['1234','455','4689','9837']
    ${sum6}=  ['1234','455','4689','9837']

    ${sum_count2}=  Get Length  ${sums5}
    FOR  ${i}  IN RANGE  ${sum_count}
        ${sums5}[${i}]==${sum6}[${i}]
    END

整个脚本将在for循环中运行它不应该停止即使特定的验证失败它应该继续执行脚本并记录每个验证的结果无论它是失败还是通过
整个脚本将在for循环中运行,即使特定验证失败,也不应停止执行,应继续执行脚本并记录每次验证的结果,无论其在Robot Framework中是失败还是通过

ffscu2ro

ffscu2ro1#

由于语法错误,您的测试失败。错误如下:

========================================================================================
Validating Dropdown                                                             | FAIL |
No keyword with name '${sums}= ['1234','455','4689','9837']' found.
----------------------------------------------------------------------------------------
Validate Continue                                                               | FAIL |
1 test, 0 passed, 1 failed
=======================================================================================

在每个循环中,你并没有调用关键字,它也会失败。
这应该是一个可能的纠正测试用例:

*** Settings ***
Library           Collections

*** Test Cases ***
Validating Dropdown
    ${collector}=    Create List
    Set Test Variable    \${collector}
    ${sums}=    Create List    '1234'    '455'    '4689'    '9837'
    ${sum2}=    Create List    '1234'    '455'    '46'    '9837'
    ${sum_count}=    Get Length    ${sums}
    FOR    ${i}    IN RANGE    ${sum_count}
        ${result}=    Run Keyword And Continue On Failure    Validate Equal    ${sums}[${i}]    ${sum2}[${i}]
        Run Keyword If    "${result[0]}" == "FAIL"    Append To List    ${collector}    ${result}
    END
    # Report
    ${sums3}=    Create List    '12'    '455'    '4689'    '9837'
    ${sum4}=    Create List    '34'    '455'    '46'    '9837'
    ${sum_count1}=    Get Length    ${sums3}
    FOR    ${i}    IN RANGE    ${sum_count1}
        ${result}=    Run Keyword And Continue On Failure    Validate Equal    ${sums3}[${i}]    ${sum4}[${i}]
        Run Keyword If    "${result[0]}" == "FAIL"    Append To List    ${collector}    ${result}
    END
    # Report
    ${sums5}=    Create List    '1234'    '455'    '4689'    '9837'
    ${sum6}=    Create List    '1234'    '455'    '4689'    '9837'
    ${sum_count2}=    Get Length    ${sums5}
    FOR    ${i}    IN RANGE    ${sum_count2}
        ${result}=    Run Keyword And Continue On Failure    Validate Equal    ${sums3}[${i}]    ${sum4}[${i}]
        Run Keyword If    "${result[0]}" == "FAIL"    Append To List    ${collector}    ${result}
    END
    Report

*** Keywords ***
Validate Equal
    [Arguments]    ${arg1}    ${arg2}
    ${result}=    Run Keyword And Ignore Error    Should Be Equal    ${arg1}    ${arg2}
    RETURN    ${result}

Report
    ${fail_count}=    Get Length    ${collector}
    IF    ${fail_count} > 0
        Log Many    @{collector}
        Fail    Validation of elements failed. Some are different
    END

相关问题