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

Robot Framework导入资源文件报错‘Import file not found’求助

Robot Framework导入资源文件提示“Import file not found”的解决办法

问题背景

学习Robot Framework时创建了示例项目,尝试导入资源文件测试功能,始终收到Import file not found错误。已尝试以下操作但未解决:

  • 修改资源文件扩展名为.resource和.robot
  • 将资源文件移至测试文件同一目录
  • 确认资源文件中无测试用例
  • 多次调整引用路径并参考相关方案

相关代码及目录结构

测试文件

*** Settings ***
Documentation    These tests are written to validate SFDC Object Creation
Library          SeleniumLibrary
Resource         resource_file.resource


*** Test Cases ***
Validate Account creation in SFDC
    User clicks on Account tab from Home Page
    User clicks on New Account
    User enters the required Account information
    User verifies account creation in SFDC

*** Keywords ***
User clicks on Account tab from Home Page
User clicks on New Account
User enters the required Account information
User verifies account creation in SFDC

资源文件

*** Settings ***
Documentation    This Robot File contains all the utility methods
Library    SeleniumLibrary

*** Variables ***
${sfdc_url}                 https://test.salesforce.com
${browser_name}             chrome
${username}                 //input[@type='email']
${password}                 //input[@type='password']
${login_btn}                //input[@id='Login']
${home_button}              //nav[@role='navigation']/descendant::*[text()='Home']


*** Keywords ***
User logs in successfully to SFDC Environment
    Open Browser                     ${sfdc_url}                ${browser_name}
    Maximize Browser Window
    Wait Until Element Is Enabled    ${username}                30
    Input Text                       ${username}                myusername
    Input Password                   ${password}                mypassword
    Click Button                     ${login_btn}
    Wait Until Element Is Enabled    ${home_button}             60

项目目录结构

venv
├── tests
└── resourceFiles

解决方案

1. 使用正确的相对路径导入

测试文件位于tests目录,资源文件位于resourceFiles目录,需通过相对路径指定资源文件位置,修改测试文件的Resource语句:

Resource         ../resourceFiles/resource_file.resource
  • 若资源文件和测试文件在同一目录,直接写文件名即可(需确保文件名完全匹配,包括大小写和扩展名)

2. 全局指定资源文件搜索路径

运行测试时,通过--resource参数告诉Robot Framework资源文件的目录:

robot --resource ./resourceFiles tests/你的测试文件名.robot

如果使用IDE(如PyCharm、RIDE),可在运行配置中添加该参数,避免每次命令行输入。

3. 检查文件名与路径拼写

  • 确认资源文件名和导入语句中的名称完全一致(Linux/macOS区分大小写,Windows不区分)
  • 检查目录名称拼写,比如resourceFiles不要误写为resources或其他名称

4. 排查IDE或运行环境的文件识别问题

若将资源文件移至测试文件同目录仍报错,需检查:

  • 资源文件是否被IDE的文件排除列表忽略
  • 运行测试时的工作目录是否正确(比如是否在项目根目录下执行测试命令)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 17:45:26