2

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer! Seems like I need to get a bit more of the basics - i was not sure about the difference betwqeen *** Keywords *** and *** Variables *** but now I know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.