Else condition in robot framework not running - robotframework

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

Related

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

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.

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"

expected at least 1 argument, got 0

I installed robot framework yesterday and trying to run a test file.Below is my test file, while i try to run the file using robot -d tests/Amazon.robot , i am getting a error as
[Error] Expected at least 1 argument,got 0.
can someone please help me.
You didn't specify where to look for tests and you are using -d incorrectly.
Most likely you need command robot tests/Amazon.robot
The problem looks like in the usage of the Sleep keyword - you want to pass the argument "3" to it, but did not put two or more spaces b/n them.
With problems like this, check the generated log.html file - the failure will be in the record for the specific keyword, helping you pinpoint which line is the error one.

OSB : Xquery Comparision Failing Intermittently

I have following condition in my OSB proxy.
$body/*[1]/xyzflag eq 'true' and (:some other true conditions:)
The node xyzflag is not even present under node pointed by variable $body.
The condition works as expected (gives false) most of the times. but sometime it gives true.
Anyone has faced this situation? Seems a bug to me. Can some help?
The XQuery expression you are trying is wrong.
e.g. If your XML is looks like below:
<school>
<teacher>
<isClassteacher>Y</isClassteacher>
</teacher>
<teacher>
<isClassteacher>N</isClassteacher>
</teacher>
</school>
Then your expression will be like below:
data($body/teacher[1]/isClassteacher)='Y'
Note: Please make the changes as per your requirement.
Hope this will be helpful.
regards
Asutosh
Try to make it like this:
fn:data($body/[1]/xyzflag)
If you are checking for existence of that node <xyzflag>, I will suggest you to use fn:exists function.
This expression
$body/*[1]/xyzflag = 'true'
will return true if the node <xyzflag> is present. It is not going to bother whether the contents of the node is present or not

Resources