导入资源 - 文件不存在(机器人框架)
Import Resource - File does not exist (Robot Framework)
可以使用导入资源导入文件吗?
我需要能够 运行 相同的测试用例,但使用不同的变量才能 运行 不同语言的相同测试用例。为此,我创建了不同的资源库。
为了告诉我的测试用例哪个变量文件,我 运行 关键字只导入那个国家的资源文件。
例如(importAU文本中的这个,与AU共享同一个资源文件夹Resource.txt)
*** Keywords ***
AU
[Documentation] Initializes the AU keyword variables
Import Resource ../variables/AU/Resource.txt
然后这是设置 txt(打开浏览器并 运行s 正确的文件)
*** 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 的一个已知问题,但据说已修复。
这里是link:http://code.google.com/p/robotframework/issues/detail?id=944
首先,你可以使用${CURDIR}和他的朋友们。
${CURDIR} 测试数据文件所在目录的绝对路径。此变量区分大小写。
${TEMPDIR} 系统临时目录的绝对路径。在类 UNIX 系统中,这通常是 /tmp,在 Windows c:\Documents and Settings\\Local Settings\Temp.
中
${EXECDIR} 测试执行开始目录的绝对路径。
它们也可以用在导入资源的声明中。这应该可以为您省去一些麻烦。
我过去使用了一种不同的方法 - 通过定义一个作为主项目文件夹的全局 "required" 变量,并在所有导入中使用它。
您可以在命令行中传递这样一个变量(并强制您的用户使用批处理包装器)或者如果您使用 maven 包装器,您可以将它放在那里。
可以使用导入资源导入文件吗?
我需要能够 运行 相同的测试用例,但使用不同的变量才能 运行 不同语言的相同测试用例。为此,我创建了不同的资源库。
为了告诉我的测试用例哪个变量文件,我 运行 关键字只导入那个国家的资源文件。
例如(importAU文本中的这个,与AU共享同一个资源文件夹Resource.txt)
*** Keywords ***
AU
[Documentation] Initializes the AU keyword variables
Import Resource ../variables/AU/Resource.txt
然后这是设置 txt(打开浏览器并 运行s 正确的文件)
*** 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 的一个已知问题,但据说已修复。
这里是link:http://code.google.com/p/robotframework/issues/detail?id=944
首先,你可以使用${CURDIR}和他的朋友们。
${CURDIR} 测试数据文件所在目录的绝对路径。此变量区分大小写。
${TEMPDIR} 系统临时目录的绝对路径。在类 UNIX 系统中,这通常是 /tmp,在 Windows c:\Documents and Settings\\Local Settings\Temp.
中
${EXECDIR} 测试执行开始目录的绝对路径。
它们也可以用在导入资源的声明中。这应该可以为您省去一些麻烦。
我过去使用了一种不同的方法 - 通过定义一个作为主项目文件夹的全局 "required" 变量,并在所有导入中使用它。
您可以在命令行中传递这样一个变量(并强制您的用户使用批处理包装器)或者如果您使用 maven 包装器,您可以将它放在那里。