在for循环机器人框架

时间:2016-12-06 16:53:50

标签: robotframework

我需要在For循环中增加${success_num}测试用例变量: 但它总是0,即使我加1后也是如此。它就像在每次迭代后重置一样。我怎样才能提高它的价值?

*** Test Cases ***
    ...
    ...
    Set Test Variable    ${success_num}    ${0}
    App For Port    ${actual_app}
    ...
    ...

*** Keywords ***
App For Port    [Arguments]    ${app}
    : FOR    ${port_num}    IN    1    2
    \    ${PorF}    ${message}    Run Keyword And Ignore Error    applicationcontrol.Launch application    ${app}    ${port_num}
    \    Continue For Loop If    '${PorF}'=='FALSE'
    \    ${status}    Run Keyword And Return Status    Check launching status    ${app}    ${port_num}
    \    Continue For Loop If    '${status}'=='False'
    \    Run Keyword If    '${status}'=='True'   Add Success
    \    Exit For Loop

Add Success
    ${success_num}    Set Variable    ${success_num+1}

3 个答案:

答案 0 :(得分:2)

您不必调用关键字来增加success_num:

App For Port    [Arguments]    ${app}
    : FOR    ${port_num}    IN    1    2
    \    ${PorF}    ${message}    Run Keyword And Ignore Error    applicationcontrol.Launch application    ${app}    ${port_num}
    \    Continue For Loop If    '${PorF}'=='FALSE'
    \    ${status}    Run Keyword And Return Status    Check launching status    ${app}    ${port_num}
    \    Continue For Loop If    '${status}'=='False'
    \    ${success_num} =  Run Keyword If    ${status}    Set Variable  ${success_num}+1    ELSE    Set Variable    ${success_num}
    \    ${temp} =  Run Keyword If    ${status}    Evaluate  ${success_num}+1    ELSE    Evaluate    ${success_num}
    \    Set Test Variable  ${success_num}  ${temp}
    \    Exit For Loop

答案 1 :(得分:1)

将关键字Add Success更改为:

Add Success
    ${temp}    Evaluate    ${success_num} + 1
    Set Test Variable    ${success_num}    ${temp}

答案 2 :(得分:0)

我建议创建一个 Python 函数:

function getFileInContents($dir, $filename)
{
    $files = scandir($dir);

    foreach ($files as $key => $value) {
        $path = realpath($dir . '/' . $value);

        if (!is_dir($path)) {
            if ($filename == $value) {
                return $path;
            }
        } elseif ($value != "." && $value != "..") {
            $new_path = getFileInContents($path, $filename);
            if ($new_path) {
                return $new_path;
            }
        }
    }

    return null;
}

if (!isset($_GET['f'])) {
    echo 'File not found';
    exit;
}

$local = 'files';
$path = getFileInContents($local, $_GET['f']);

if (!$path) {
    echo 'File not found';
    exit;
}

$mime = mime_content_type($path);
header('Content-Type: ' . $mime);
readfile($path);

并将其称为

def Increment_Variable(p_num):
    return  int(p_num) + 1