You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RobotFramework测试用例同时使用普通关键字与[Template]的问题咨询

错误根因

你遇到的报错是Robot Framework Test Template的固有机制导致的:只要在测试用例内部声明了[Template]属性,该用例下的所有非设置行(除了[Documentation]/[Tags]这类方括号开头的设置项)都会被默认识别为模板关键字的参数行,你写在模板声明前的普通关键字步骤,会被当成参数传递给模板关键字,自然就会出现参数数量不匹配的报错。
你补充示例里的写法也是不符合语法规则的,[Template]声明后无法插入普通关键字步骤。

解决方案

用FOR循环替代[Template],完全满足你「保留前置普通步骤、不需要把前置步骤放到[Setup]、同时实现多组参数重复调用模板关键字」的需求,修改后的用例写法如下:

TC_003_Edit_Custom_Destination
    [Documentation]     Edit Custom Destination, inside settings tab
    [Tags]              Testing Edit Custom Destination Functionality
    # 前置普通步骤正常写,只会执行一次
    TC_001_Streaming_test_setup  other
    Cancel create Destination
    Click on edit title for new destination created  ${destination_title_name}
    
    # 用FOR循环实现多组参数调用,效果和Test Template完全一致
    FOR    ${name}    ${address}    ${stream_key}    ${expected_tip}
        Create Destination Invalid Scenarios    ${name}    ${address}    ${stream_key}    ${expected_tip}
    END
        ${empty}                           ${empty}                            ${empty}          Please enter an RTMP address
        ${empty}                           ${rtmps_address}                    ${empty}          Please enter an stream key
        ${empty}                           rtm://google.com                    123ABC            Invalid Destination
        ${empty}                           ${rtmps_address}                    123ABC            Please give this destination a name
        ${destination_title_name}          ${rtmps_address}                    123ABC            ${empty}

内容的提问来源于stack exchange,提问作者Hardik Gami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 04:36:01