Robot Framework - 使用来自不同目录变体的 运行 测试的相对路径
Robot Framework - using relative paths to run tests from different directory variations
我 运行 我的 Robot Framework 测试套件遇到了问题。我有一个像这样的简单测试结构:
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 文件夹移动到文件结构中的不同路径并更新到该新路径,但是 none 这有效并显示与以前相同的错误消息。
这也很重要,因为我希望将默认的 firefox 配置文件 运行 与测试一起使用,并且这些测试在不同的人之间传递,以便 运行 在他们的机器上将它们本地化。任何帮助将不胜感激。
你可以像这样使用相对路径:
..${/}..${/}foo${/}firefoxTestProfile
您应该从运行测试的文件中提及 'firefoxTestProfile' 的相对路径。
有几个内置变量可以帮助您正确定义路径。
这里最有趣的是 ${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
不幸的是,Selenium 在非规范路径方面存在问题 - 至少在 Windows 上是这样。 ${/}..${/}
原来是有问题的,Selenium 因使用此类字符串的文件引用而失败。
解决此问题的方法是将字符串库与 ${CURDIR}
:
一起使用
${UpperDir} ${Leaf} Split String From Right ${CURDIR} ${/} 1
我 运行 我的 Robot Framework 测试套件遇到了问题。我有一个像这样的简单测试结构:
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 文件夹移动到文件结构中的不同路径并更新到该新路径,但是 none 这有效并显示与以前相同的错误消息。
这也很重要,因为我希望将默认的 firefox 配置文件 运行 与测试一起使用,并且这些测试在不同的人之间传递,以便 运行 在他们的机器上将它们本地化。任何帮助将不胜感激。
你可以像这样使用相对路径:
..${/}..${/}foo${/}firefoxTestProfile
您应该从运行测试的文件中提及 'firefoxTestProfile' 的相对路径。
有几个内置变量可以帮助您正确定义路径。
这里最有趣的是 ${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
不幸的是,Selenium 在非规范路径方面存在问题 - 至少在 Windows 上是这样。 ${/}..${/}
原来是有问题的,Selenium 因使用此类字符串的文件引用而失败。
解决此问题的方法是将字符串库与 ${CURDIR}
:
${UpperDir} ${Leaf} Split String From Right ${CURDIR} ${/} 1