在变量定义中使用变量

Using Variables in Variable definition

我正在尝试将变量转化为变量,但它不起作用。我搜索了 google 并尝试了很多东西,但没有成功。
我希望这个问题不是 "dumb":
我做错了什么?

*** 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

用space分隔的格式有点难读,但是每个变量名必须由两个或多个space分隔,但"year month day"应该只有一。