【问题标题】:Robotframework: Unable to Set Suite variable for the variables of Run Keyword if passes as variableRobotframework:如果作为变量传递,则无法为运行关键字的变量设置套件变量
【发布时间】:2017-03-21 14:36:42
【问题描述】:

我尝试为不同的情况生成唯一名称,并使用最少的关键字将该唯一名称设置为套件变量,但无法执行此操作, 有人可以帮我搞定吗,这是我的代码..

*** Test Cases ***

TC100_Unique Variable Checking
Generate Unique Name for Objects-loop    Product Line
Generate Unique Name for Objects-loop    Models
Generate Unique Name for Objects-loop    Portfolio

*** Keywords ***    
Generate Unique Name for Objects-loop
[Arguments]    ${function}
Set Variable    ${function}
${namePL}=    Run Keyword If    '${function}'=='Product Line'    Run      Keywords    Generate Unique Name    PL-RFT-    ${CURDIR}\\fNameEdit.txt
...    Set Suite Variable    ${namePL}
${nameMOD}=    Run Keyword If    '${function}'=='Models'    Run Keywords    Generate Unique Name    MOD-RFT-    ${CURDIR}\\modNameEdit.txt
...    Set Suite Variable    ${nameMOD}
${namePF}    Run Keyword If    '${function}'=='Portfolio'    Run Keywords    Generate Unique Name    PF-RFT-    ${CURDIR}\\pfNameEdit.txt
...    Set Suite Variable    ${namePF}

Generate Unique Name
[Arguments]    ${suffix}    ${filepath}
${name}=    Get String Plus Number    ${suffix}    ${filepath}
Set Test Variable    ${name}
Write Unique Number    ${filepath}
[Return]    ${name}

错误:

未找到变量“${namePL}”。

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    最后,我可以在单个关键字中找到解决方案。这是简单的代码。

     Run Keyword If    '${function}'=='Products'    Run Keywords    Generate  Unique Name    PL-RFT-    ${CURDIR}\\fNameEdit.txt    AND
    ...    Set Suite Variable    ${namePL}    ${name}
    

    感谢您的所有意见。

    【讨论】:

      【解决方案2】:

      Run If 语句确实允许执行多个关键字,但是,基于在同一 Run If 上下文中设置的值设置变量是这里的真正问题。我的建议是在两个不同的语句中拆分 ID 的生成和重用。

      【讨论】:

        【解决方案3】:

        考虑一下这段代码:

        ${namePL}=    Run Keyword If    '${function}'=='Product Line'    Run      Keywords    Generate Unique Name    PL-RFT-    ${CURDIR}\\fNameEdit.txt
        ...    Set Suite Variable    ${namePL}
        

        这将创建一个名为${namePL}的变量其他关键字已经运行。但是,您尝试将 Set Suite Variable 称为这些关键字之一,但它被称为 before Run keyword if 完成,因此在创建 ${namePL} 之前。

        【讨论】:

          猜你喜欢
          • 2017-04-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多