Skip to content

Script fails when variable is set in command line. Workaround is to Evaluate the variable. #4323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
UliSei opened this issue Apr 26, 2022 · 6 comments

Comments

@UliSei
Copy link
Contributor

UliSei commented Apr 26, 2022

I don't understand why I need to use the workaround in line 12:

*** Settings ***
Library    DateTime


*** Variables ***
${EPOCHDATE}    ${60}


*** Test Cases ***
Convert Given Epoch
    Log To Console    \n\${EPOCHDATE}=${EPOCHDATE}
    ${EPOCHDATE}    Evaluate    ${EPOCHDATE}*1     # workaround
    ${epochTS}    Convert Date    ${EPOCHDATE}
    Log To Console    \n${EPOCHDATE} was converted to ${epochTS}

Given line 12 is active
When I call robot --variable EPOCHDATE:60 callWithArgument.robot
Then the result is PASS.

Given line 12 is commented
When I call robot --variable EPOCHDATE:60 callWithArgument.robot
Then the result is FAIL.

Given line 12 is commented
When I call robot callWithArgument.robot
Then the result is PASS.

@Pratapreddy1188
Copy link

workout is just making that string to convert to proper variable.

Difference
Convert Date 60

Convert Date ${60}

https://robotframework.org/robotframework/latest/libraries/DateTime.html#Epoch%20time

@UliSei
Copy link
Contributor Author

UliSei commented Apr 27, 2022

In other words
Using --variable EPOCHDATE:60 leads to the same kind of variable as
using ${EPOCHDATE} 60 instead of ${60} in callWithArgument.robot?

@Pratapreddy1188
Copy link

Yes.
When not specified with in the braces ${} it is considered int as string.
you could check the same passing --variable EPOCHDATE:${60}

@UliSei
Copy link
Contributor Author

UliSei commented Apr 27, 2022

Ah ok. So I replaced the workaround by
${EPOCHDATE} Convert To Integer ${EPOCHDATE}

I also checked what happens with or without asserting the integer type when I run
robot --variable EPOCHDATE:${60} callWithArgument.robot
However the script fails with
'' cannot be converted to an integer: ValueError: invalid literal for int() with base 10: ''
Obviously the EPOCHDATE:${60} is resolved to EPOCHDATE:''
-> so I'll have to keep the type conversion line.

@UliSei
Copy link
Contributor Author

UliSei commented Apr 27, 2022

I'd suggest to add one further line as example:
grafik

How do you think about it?

@pekkaklarck
Copy link
Member

Values you give from the command line are strings. Thus if you want a value you pass like --variable EPOCHDATE:60 to be considered an integer, it needs to be converted. Some keywords do conversion automatically, but Convert Date explicitly handles strings an numbers differently so you need to do conversion yourself.

Being able to pass non-string values from the command line would be sometimes handy. We already have #2946 about that so this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants