我试图将变量放入变量中,但它不起作用。我搜索了谷歌并尝试了很多东西,但没有成功。
我希望这个问题不是“愚蠢的”:
我做错了什么?
*** Settings ***
Library SeleniumLibrary
Library OperatingSystem
*** Variable ***
${year} Get Time return year
${month} Get Time return month
${day} Get Time return day
${output} ${CURDIR}\Testing\Tests\SRV\csdb_@{year}-@{month}-@{day}.log
*** Testcases ***
Textfile should have a line saying the service is started
${errors} = Grep File ${output} Test
最佳答案
来自robot framework user's guide :
The most common source for variables are Variable tables in test case files and resource files. Variable tables are convenient, because they allow creating variables in the same place as the rest of the test data, and the needed syntax is very simple. Their main disadvantages are that values are always strings and they cannot be created dynamically.
为了执行您想要的操作,您需要在关键字中定义变量。例如:
*** Keywords ***
Get Output
${year}= Get Time year
${month}= Get Time month
${day}= Get Time day
${output}= Set variable ${CURDIR}/Testing/Tests/SRV/csdb_${year}-${month}-${day}.log
[Return] ${output}
*** Testcases ***
Textfile should have a line saying the service is started
${output}= Get Output
${errors} = Grep File ${output} Test
注意:您可以在对关键字的一次调用中获取数据的所有三个部分,如下所示:
${year} ${month} ${day}= Get Time year month day
用空格分隔的格式阅读起来有点困难,但变量名必须用两个或多个空格分隔,但“年月日”只能有一个。
关于robotframework - 在变量定义中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29772879/