我的机器人框架测试套件遇到了问题。我有一个像这样的简单测试结构:
robotframework
|_foo
|_tests folder
|_pages folder
|_firefoxTestProfile folder
|_...
我已经设置了一个基本的 Firefox 配置文件路径来运行我的测试,并像这样设置了变量:
*** Variables ***
${FF_PROFILE} foo\firefoxTestProfile
*** Keywords ***
Open browser window
Open Browser ${test_url} ${browser}
... ff_profile_dir=${FF_PROFILE}
当我从顶层目录运行我的测试时,它运行良好:
C:/robotframework$ pybot foo/tests/test.txt
但是,如果我尝试从 foo 目录运行它,如下所示:
C:/robotframework/foo$ pybot tests/test.txt
测试抛出失败,说明
"The system cannot find the path specified: foo/firefoxTestProfile/*.*"
我尝试了各种方法,比如把路径设置为
../foo/firefoxTestProfile
/foo/firefoxTestProfile
firefoxTestProfile
以及将 firefoxTestProfile 文件夹移动到文件结构中的不同路径并更新到该新路径,但这些都不起作用并显示与以前相同的错误消息。
这也很重要,因为我想要一个默认的 firefox 配置文件来运行测试,并且这些测试在不同的人之间传递,以便在他们的机器上本地运行它们。任何帮助将不胜感激。
最佳答案
有几个内置变量可以帮助您正确定义路径。
这里最有趣的是 ${CURDIR}
来自文档:
${CURDIR} An absolute path to the directory where the test data file is located. This variable is case-sensitive.
我通常会定义一个主套件设置文件(在您的情况下,在根测试文件夹中),并在其中定义以下 3 个全局级别变量
在根测试文件夹中创建文件 __init.robot。
在其中创建一个套件设置部分(它将在任何测试之前运行 - 但只运行一次!)
Set Global Variable ${testsRootFolder} ${CURDIR}
Set Global Variable ${pagesRootFolder} %{CURDIR}${/}..${/}_pages
Set Global Variable ${firefoxProfileFolder} %{CURDIR}${/}..${/}firefoxTestProfile
关于testing - Robot Framework - 使用相对路径从不同的目录变体运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33137570/