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

RobotFramework从CSV取变量报错:${description}参数异常

RobotFramework迁移至VSCode后${description}参数报错问题

原本使用PyCharm开发的RobotFramework测试用例,迁移到VSCode后,调用Create And Approve A New Request关键字时,${description}变量触发Unexpected argument错误。尝试清空测试用例、修改CSV文件路径后,问题仍未解决。

测试用例代码

*** Settings ***
Documentation    Package 2.1
Library          SeleniumLibrary
Library          DataDriver    file=../../Automated Tests/Provisioning Process/resources/package2.1_data.csv    dialect=excel     encoding=utf-8
Resource         ../../custom_code/customized_keywords.robot
Resource         ../../Provisioning Process/resources/login.robot
Resource         ../../Provisioning Process/resources/sharepoint.robot
Resource         ../../Provisioning Process/resources/teams.robot
Test Setup       Open SPO Site    ${tenant_url}    Chrome
Test Template    Create And Approve A New Request
Test Teardown    Close Browser


*** Test Cases ***
Test Case 473511: Provision a new Teams Group: ${teams_group_name}
    [Documentation]    *Objective:* Request and approve a new Teams Group in multiple iterations
    ...                *Prerequisites:* Define iteration to be executed in append package2.1_data.csv file
    Create And Approve A New Request    ${teams_group_name}    ${sensitivity_label}     ${space_type}    ${justification}    ${description}

关键字代码

*** Keywords ***
Create And Approve A New Request
    [Tags]    IN PROGRESS
    [Arguments]    ${teams_group_name}    ${sensitivity_label}    ${space_type}    ${justification}    ${description}
    Wait Until Element Is Visible    ${teams_request_element}
    # Access teams request page
    Wait Until Element Is Visible And Click    ${teams_request_element}
    Wait Until Element Is Visible    ${title_teams_request_page}
    # open request form
    Wait Until Button Is Visible And Click    ${new_request_btn}
    Wait Until Iframe Is Visible And Select Frame    ${request_form_iframe1}
    Wait Until Iframe Is Visible And Select Frame    ${request_form_iframe2}
    # Fill request from
    Wait Until Element Is Visible And Input Text    ${teams_groups_name_input}    ${teams_group_name}
    Wait Until Element Is Visible And Input Text    ${description_input}    ${description}
    Wait Until Element Is Visible And Click    ${type_of_space_input}
    Wait Until Element Is Visible And Click    //span[@class='itemTemplateLabel_dqr75c' and contains(text(), '${space_type}')]
    Wait Until Element Is Visible And Input Text    ${justification_input}    ${justification}
    Wait Until Element Is Visible And Click    ${owners_element}
    Wait Until Element Is Visible    ${owners_input}
    Input Text    ${owners_input}    jsilva
    Wait Until Element Is Visible And Click    ${jsilva_list_element}
    Wait Until Element Is Visible And Click    ${members_element}
    Wait Until Element Is Visible    ${members_input}
    Input Text    ${members_input}    spierre
    Wait Until Element Is Visible And Click    ${seb_list_element}
    Double Click Element    ${remove_src_value}
    Input Text    ${members_input}    ibozo
    Wait Until Element Is Visible And Click    ${ivan_list_element}
    Wait Until Element Is Visible And Click    ${sensitivity_input}
    Wait Until Element Is Visible And Click    //span[@class='itemTemplateLabel_dqr75c' and contains(text(), '${sensitivity_label}')]
    Capture Page Screenshot
    Unselect Frame
    # Submit
    Wait Until Button Is Visible And Click    ${form_save_btn}
    Wait Until Element Is Not Visible    ${form_save_btn}
    Log    Request Form: EXECUTED
    Unselect Frame

CSV文件内容

***Test Cases***;${teams_group_name};${sensitivity_label};${space_type};${justification};${description}
Case1;Public with Default template;Public;Default template;Automated testing;All Approve
Case 2;Public without L2 IM validation;Public;Validator and L2 Apps Admin;Automated testing;Skips L2 IM validation

排查与解决方向

  • 检查VSCode插件兼容性:确保安装的是Robot Framework Language Server插件,且版本与当前RobotFramework、DataDriver库版本匹配。旧版本插件可能存在参数解析逻辑bug。
  • 核对参数一致性:确认关键字定义的5个参数顺序、数量,与测试用例调用、CSV表头列的顺序完全一致,无多传、漏传情况。
  • 验证CSV格式:确认CSV每行的列数与表头一致(共6列),分隔符为分号;,${description}列无换行、特殊引号等可能导致解析失败的字符,可临时替换为纯文本测试。
  • 清理VSCode缓存:关闭VSCode后删除项目下.vscode/目录的缓存文件,重新打开项目,避免旧缓存干扰参数解析。
  • 检查变量作用域:确认${description}变量在DataDriver加载后可正常被测试用例读取,可通过添加Log ${description}语句验证变量是否正确赋值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 09:52:06