可以使用导入资源导入文件吗?
我需要能够运行相同的测试用例,但使用不同的变量才能以不同的语言运行相同的测试用例。我创建了不同的资源库来执行此操作。
为了告诉我的测试用例哪个变量文件,我运行关键字以仅导入该国家/地区的资源文件。
例如(在 importAU 文本中,它与 AU Resource.txt 共享相同的资源文件夹)
*** Keywords ***
AU
[Documentation] Initializes the AU keyword variables
Import Resource ../variables/AU/Resource.txt
然后这是设置txt(打开浏览器并运行正确的文件)
*** Settings ***
Library Selenium2Library
Resource ../variables/US/Resource.txt
Resource ../variables/AU/Resource.txt
Resource ../variables/DE/Resource.txt
*** Variables ***
${COUNTRY} AU //sets which country the file should run
*** Keywords ***
Homepage should be open
Run Keyword AU
Set Selenium Speed 1 second
Open Browser ${url_staging} chrome
Set log level TRACE
Maximize Browser Window
我运行了这个,这是我得到的错误。
SETUP: setup.Homepage should be open
Start / End / Elapsed: 20150707 18:56:35.038 / 20150707 18:56:35.048 / 00:00:00.010
00:00:00.009 KEYWORD: BuiltIn.Run Keyword AU
Documentation:
Executes the given keyword with the given arguments.
Start / End / Elapsed: 20150707 18:56:35.039 / 20150707 18:56:35.048 / 00:00:00.009
00:00:00.007 KEYWORD: importau.AU
Documentation:
Initializes the AU keyword variables
Start / End / Elapsed: 20150707 18:56:35.040 / 20150707 18:56:35.047 / 00:00:00.007
00:00:00.006 KEYWORD: BuiltIn.Import Resource ../variables/AU/Resource.txt
Documentation:
Imports a resource file with the given path.
Start / End / Elapsed: 20150707 18:56:35.041 / 20150707 18:56:35.047 / 00:00:00.006
18:56:35.046 FAIL Resource file '..\variables\AU\Resource.txt' does not exist.
我的关键字是否做错了或者关键字有问题?我知道这是 RobotFramework 的一个已知问题,但据说已经修复了。
这是链接:http://code.google.com/p/robotframework/issues/detail?id=944
最佳答案
首先,你可以使用${CURDIR}和他的 friend 们。
${CURDIR} 测试数据文件所在目录的绝对路径。该变量区分大小写。
${TEMPDIR} 系统临时目录的绝对路径。在类 UNIX 系统中,通常为/tmp,在 Windows 中为 c:\Documents and Settings\\Local Settings\Temp。
${EXECDIR} 开始执行测试的目录的绝对路径。
它们也可以用在导入资源的声明中。这应该可以避免一些问题。
我过去使用过不同的方法 - 定义一个全局“必需”变量(即主项目文件夹),并在所有导入中使用它。
您可以在命令行中传递这样的变量(并强制您的用户使用批处理包装器),或者如果您使用 Maven 包装器,则可以将其放在那里。
关于robotframework - 导入资源 - 文件不存在(Robot Framework),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31266279/