Using Variables in Variable definition

╄→尐↘猪︶ㄣ 提交于 2019-12-07 15:16:28

From the 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.

In order to do what you want, you'll need to define the variables in a keyword. For example:

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

Note: you can fetch all three parts of the data in a single call to the keyword, like so:

${year}  ${month}  ${day}=  Get Time    year month day

It's a bit hard to read with the space-separated format, but the variable names must each be separated by two or more spaces, but "year month day" should have only one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!