Using Variables in Variable definition

谁都会走 提交于 2019-12-08 08:41:16

问题


I am trying to get variables into variables but it wont work. I searched google and tried a lot of stuff but it did not wor out.
I hope this question ist not "dumb":
What am I doing wrong ?

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

回答1:


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.



来源:https://stackoverflow.com/questions/29772879/using-variables-in-variable-definition

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