Robot Framework测试模板传递命名参数报错排查
问题分析及修正方案
核心问题点
- 测试用例参数传递格式错误:使用
Test Template时,测试用例不需要用变量名=的方式传参,模板关键字会按参数顺序接收值,原写法被Robot Framework误认为是变量引用,导致解析失败。 - 关键字参数默认值定义错误:关键字
Create New Guest of Specified Type的参数默认值写成了字符串guest_details,这不是合法的变量引用,且当前场景不需要默认值,直接定义必填参数即可。
修正后的代码
*** Settings *** Library SeleniumLibrary Test Template Create New Guest of Specified Type *** Test Cases *** Verify creation of new guest of type Today &{TodayGuestDetails} Today Visitor *** Keywords *** Create New Guest of Specified Type [Arguments] ${guest_details} ${schedule_type} ${guest_type} Fill Guest Details ${guest_details} *** Variables *** &{TodayGuestDetails} firstname=Test lastname=Guest email=guest@mail.com
补充说明
- 测试用例中直接按关键字参数的顺序传入
&{TodayGuestDetails}、Today、Visitor,模板会自动将这些值对应到关键字的三个参数上。 - 关键字的参数去掉了错误的默认值,明确为必填参数,符合测试逻辑。
内容的提问来源于stack exchange,提问作者user828647
相关产品推荐
相关产品推荐

