2015-10-14 1050 views
4

我遇到了一个与我的Robot Framework测试套件有关的问题。我有一个简单的测试结构是这样的: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文件夹到不同路径的文件中结构和更新到新路径,但没有一个工作并显示与以前相同的错误消息。

这也很重要,因为我想要一个默认的Firefox配置文件与测试一起运行,并且这些测试在不同的人之间传递,以便在他们的机器上本地运行它们。任何帮助将不胜感激。

回答

11

有几个内置变量可以帮助您正确定义路径。

的一个最有趣这里是$ {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 
+0

$ {} CURDIR似乎是实现这一目标的最佳选择。谢谢! – chmcc

1

你可以使用相对路径是这样的: .. $ {/} .. $ {/}富$ {/} firefoxTestProfile

你应该从一个运行该文件提到 'firefoxTestProfile' 的相对路径测试。

相关问题