无法使用相对路径访问资源文件

Unable to access resource file using relative path

我在资源文件下创建了几个变量,如果我尝试使用完整的绝对路径访问,我可以访问资源文件下的变量,但如果我使用相对路径,它就不起作用。

下面是资源文件的截图(尝试将格式更改为.txt、.robot、.resources)

下面是我尝试访问资源文件的测试用例文件

您的“相对”路径是相对于 Collections.robot 文件,您需要向上几层,例如:

../../resources/Txt/Resource.robot

其中:

  • 首先 .. 将您移动到测试文件夹
  • .. 将您移动到 ​​venv 文件夹
  • venv 文件夹下你有这个 resources

我也不认为使用 Robot 框架是 运行 JMeter 测试的最佳方式,查看 release history of the JMeter library it was updated 4 years ago and since then several versions of JMeter released, for instance JMeter 4.0 which had a lot of breaking changes so I would rather recommend switching to Process library and run JMeter in command-line non-GUI mode

使用相对导入时,它们基于您要导入的文件的位置。

因为Collections.robot在other_dirs/venv/Test/Collection/目录下,资源一在other_dirs/venv/resources/Txt /,正确的相对导入路径是:

Resource       ../../resources/Txt/Resource.robot

旁注 - 为什么要将源代码存储在 venv 目录中?这看起来像您正在使用的 python 虚拟环境,因此由它管理;它通常也在 git 忽略等中。这看起来像是一种不正确的做法。