How to make Run Keyword If work with 'OR'? - robotframework

I am trying to use Run Keyword If with or but for some reason it does not work and I could not understand why. It shows me an error No keyword with name 'or' found. I assume there is some syntax error. I also tried with OR but it did not work.
Keyword 1
Check Walkthrough Guide Opened
Go to ${WALKTHROUGH_URL}
Open Walkthrough Guide If It's Closed
Wait Until Element Is Visible ${WELCOME_POPUP} ${WFE_TIMEOUT}
Page Should Contain Element ${POPUP_TITLE}
Keyword 2
${ELEMS}= Execute JavaScript return localStorage.getItem('peopleAnalyticsTourDismiss')
Run Keyword If ('${ELEMS}' == 'true') or (${ELEMS}' == 'None') Run Keywords
... Execute Javascript localStorage.setItem('peopleAnalyticsTourDismiss', 'false')
... AND Reload Page

You need to convert the two spaces on either side of "or" to a single space. Robot sees the two or more spaces and thinks "or" is the keyword to run.
Run Keyword If ('${ELEMS}' == 'true') or (${ELEMS}' == 'None') Run Keywords
# ^^ ^^

Robot Framework is understanding your OR as the second argument of the keyword Run Keyword If. Switch the double spaces for a single one, like the example below:
Run Keyword If ('${ELEMS}' == 'true') or (${ELEMS}' == 'None') Run Keywords
This way, robot will understand ('${ELEMS}' == 'true') or (${ELEMS}' == 'None') as just one argument of Run Keyword If, with is the condition one.
If you still have doubts, I've found this issue with a similar problem, and a good solution as an example.
Other thing that can be giving you some trouble, is that you missed a ' in the beggining of the second comparison: or (${ELEMS}' == 'None'). Try changing it for one of the options below:
or ('${ELEMS}' == 'None')
or ("${ELEMS}" == "None")
or ("""${ELEMS}""" == """None""")
Please refer to the Builtin library for doubts about triple quotes.

Related

How to fix "Escaping empty cells with '\' before line continuation marker '...' is deprecated" error in Robot Framework?

I keep on getting this error when running my Robot Framework script:
"Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2."
Here is a sample code:
*** Test Cases ***
Debug
${Str} = Set Variable Rose
: FOR ${Ctr} IN RANGE 1 5
\ Run Keyword If '${Str}' == 'Test' Log Test
\ ... ELSE Log Not Test
I searched for a solution and I only got this link: https://gerrit.openbmc-project.xyz/#/c/openbmc/openbmc-test-automation/+/22245/
I can see that they used FOR/END instead of :FOR (which was working fine before).
FOR ${userid} IN RANGE 2 16
${user_info}= Get User Info ${userid}
Run Keyword If "${user_info['user_name']}" != ""
... Run IPMI Standard Command user set name ${userid} ""
END
However, when I try to change my code to use FOR/END, RIDE automatically changes it back to :FOR.
I use RIDE heavily and would like to continue to do so I need it to work around this error. My RIDE is the latest one so upgrade won't work. Any help would be appreciated.
The syntax for the FOR-loop is changed. From the documentation:
Not closing loops with END, escaping keywords inside loops with \, and
using :FOR instead of FOR are all going to be deprecated in Robot
Framework 3.2. Users are advised to switch to the new syntax as soon
as possible.
With your code I can still run the test, but the deprecation warning is shown. To remove the warning this worked for me in Eclipse:
Debug
${Str} = Set Variable Rose
:FOR ${Ctr} IN RANGE 1 5
\ Run Keyword If '${Str}' == 'Test' Log Test
... ELSE Log Not Test
When you remove the escape character in the ELSE line the warning is no longer shown. This is a workaround though, untill a new version of RIDE comes along I guess.

How to fix "No keyword with name '0=' found" in Robot Framework

I am a newbie in Robot framework. I want to run multiline IF Statement but I am getting below error:
Error :
"0= Evaluate, ${G_NO_OF_RECIPIENTS}+${NUMBER_OF_CALLEE} FAIL No
keyword with name '0=' found. "
This error is occurring for variable ${REM_COUNT}
Code :
Log ${G_NO_OF_RECIPIENTS}
Log ${NUMBER_OF_CALLEE}
${REM_COUNT} Set Variable ${0}
Run Keyword If "${NUMBER_OF_CALLEE}" != "${G_NO_OF_RECIPIENTS}" Run Keywords
... ${REM_COUNT}= Evaluate ${G_NO_OF_RECIPIENTS}+${NUMBER_OF_CALLEE}
... AND Log "ITS WORKING"
Similar piece of code works somewhere else, only thing was I did not use multiline if statement in it. I appreciate if I get help on this.
Thanks
The Run Keywords does not allow variable assignment inside its block, e.g. this line:
Run Keywords
... ${REM_COUNT}= Evaluate ${G_NO_OF_RECIPIENTS}+${NUMBER_OF_CALLEE}
... AND Log "ITS WORKING"
is illegal syntax. It tried to substitute ${REM_COUNT} with its value (0), and to run it - thus the failure.
Run Keyword If does pass any return values, so you can do it this way:
${REM_COUNT}= Run Keyword If "${NUMBER_OF_CALLEE}" != "${G_NO_OF_RECIPIENTS}"
... Evaluate ${G_NO_OF_RECIPIENTS}+${NUMBER_OF_CALLEE}
... ELSE Set Variable ${REM_COUNT} # if the condition is False, leave the variable to its previous value
Run Keyword If "${NUMBER_OF_CALLEE}" != "${G_NO_OF_RECIPIENTS}" Log "ITS WORKING"

Else condition in robot framework not running

I am trying run:
Run keyword if ${browser}='chrome' somekeyword
Else if ${browser}='ff' somekeyword
it's giving me a format error I am running as per doc. can anyone suggest the error?
Run Keyword If ${browser}=='chrome' keyword
... ELSE IF ${browser}=='ff' keyword
... ELSE keyword
Keep proper space either tab or 2+ spaces as this may also be the reason as suggested by #Bryan Oakley
Hope this helps if not do post the exact keywords you have used with the error...

Deprecation of isblank("string") in Julia 0.4

I'm doing text parsing in Julia and need to test if certain strings are blank (in order to parse into floats). I have been using isblank() booleans in <0.4 Julia, but after upgrading to 0.4, I get the following warning:
julia> isblank(q)
WARNING: isblank(s::AbstractString) is deprecated, use all((c->begin
c == ' ' || c == '\t'
end),s) instead.
in depwarn at deprecated.jl:73
in isblank at deprecated.jl:50
while loading no file, in expression starting on line 0
true
What replaced isblank()? Is the above really the replacement? My googling didn't turn up anything useful.
Yes, that is the replacement.
Basically in #5939 and related issues, it was revealed that answering isblank is a lot harder than it might first appear given Unicode complexities.
The deprecation occurred in #8233.
Everything looks natural, it must be a replacement in new version, you can add the line bellow in your code and replace (using Ctrl+H) all isblank( with isblk(. I wish it works for you.
isblk(s)=all((c->begin c == ' ' || c == '\t' end),s)
now isblk([]) # => true

Customize zsh's prompt when displaying previous command exit code

Zsh includes the ability to display the return code/exit code of the previous command in the prompt by using the %? escape sequence.
However I would like to have the following prompt:
user#host ~ [%?] %
when the exit code is different from 0 and:
user#host ~ %
when exit code is 0.
If I use %? alone it is always displayed, even if %? is 0.
In addition I want the square brackets but only when the exit code not 0.
What is the simplest way to do this?
Add this in the position in PS1 where you want the exit code to appear:
%(?..[%?] )
It's a conditional expression. The part between the two dots (nothing in this case) is output if the expression before the first dot is true. The part after the second dot is output if it's false.
For example:
PS1='%n%m %~ %(?..[%?] )%# '
Alternatively, you can:
setopt PRINT_EXIT_VALUE
to always print a newline showing previous return value.
I don't prefer this for ordinary use, but it is often good for debugging shell scripts.

Resources