Robot Framework: why does Log ignore my argument? - runtime-error

When I run the code below I get an error message
Keyword 'BuiltIn.Log' expected 1 to 5 arguments, got 0.
for the second log to console (within the if-clause). Why? Why doesn't it "see" the variable I try to send as an argument?
Googling doesn't return anything useful. I have tried several combinations of spaces and apostrophes but nothing has worked.
Function key above F12
[Arguments] ${fkey}
${ValidFKeys}= Create List F13 F14 F15 F16 F17
log to console ${fkey}
Run Keyword If $fkey in $ValidFKeys run keywords
... log to console ${fkey}

Check the Run Keywords documentation:
By default all arguments are expected to be keywords to be executed.
What happened is Run Keywords treated Log To Console as the first keyword to be ran, then the value of ${fkey} as the second - it did not pass it as argument to the log. To overcome this, add an "AND" - so now it knows ${fkey} is an argument; if yo udon't have any other keyword to be ran, either drop Run Keywords, or use No Operation:
Run Keyword If $fkey in $ValidFKeys run keywords
... log to console ${fkey} AND No Operation

Related

Trimmomatic-0.39 error message "Unknown option -baseout ..."

I have used Trimmomatic-0.39 few times already for trimming some sequencing data. This time I tried the option -baseout as stated in the manual but it does not recognise it as a valid option and the command does not run. If I run the command, as I usually I do with all the output files listed, it works though.
I type in the command line:
java -jar trimmomatic-0.39.jar PE -phred33 -trimlog trimmed_file18_log.log -baseout file18.fastq.gz file18-R1.fastq.gz file18-R2.fastq.gz ILLUMINACLIP:NexteraPE-PE.fa:2:30:10 MAXINFO:25:0.2 MINLEN:20
What I get back is:
Unknown option -baseout file18.fastq.gz
Usage:
PE [-version] [-threads <threads>] [-phred33|-phred64] [-trimlog <trimLogFile>] [-summary <statsSummaryFile>] [-quiet] [-validatePairs] [-basein <inputBase> | <inputFile1> <inputFile2>] [-baseout <outputBase> | <outputFile1P> <outputFile1U> <outputFile2P> <outputFile2U>] <trimmer1>...
or: .....
I get back the same error message even if I move the '-baseout file18.fastq.gz' option after '...jar PE' and before the list of all the other options.

Robot-framework: How do I run keyword and its variables stored in a list?

I am currently trying to pass a keyword and its arguments as a List to an another keyword, which then runs it, like this.
Keyword That Runs:
[Arguments] #{keyword_to_run_with_parameters}
Run Keyword #{keyword_to_run_with_parameters}
For demo I created a parameter in the following way to test it:
#{to_analyze}= Create List Should Be Equal ${True} ${True}
Which gave me the following:
No keyword with name 'keyword_to_run_with_parameters = ['Should Be Equal', True, True]' found.
I have tried creating the list in different ways, but this was the only one that worked. I also tried running it with ${keyword_to_run_with_parameters}, but did not run.
I tried to search StackOverflow for any suggestion, but did not find appropriate ones.
Edit:
I am working with GUI and I want to create a new Keyword which takes screenshots when a non-selinium keyword fails. This is currently not working, because I cannot handle the list as a container for keywords and their arguments. A solution could be to only call this function if the keyword already failed, but I'm curious about other approaches.
Capture Screenshot On Failure
[Documentation] Captures screenshot on failure of a keyword, then fails the test with custom message if any is given.
... Needed because RobotFramework/Selinium only takes screenshot if a RobotFramework/Selinium command fails.
... param: keywords: #{keywords}= Create List Keyword Arguments
[Arguments] ${failmessage}=Basic feedback for failiure. Picture is above. #{keywords}
${good} = Run Keyword And Return Status #{keywords}
Run Keyword If not ${good} Run Keywords
... Capture Page Screenshot
... AND Fail ${failmessage}

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"

Hide default error message for a failed robot test

I am writing a robot test to see if a list of servers appears in a unix configuration file.
The test is something along the lines of:
Test Case
#{server_list}= server1 server2 server3
${lines}= Get File /etc/config_file
:FOR ${server} in #{server_list}
\ Run Keyword and Continue on Failure Should Contain ${lines} ${server} msg="${server} not in /etc/config_file"
When the test fails it prints out my custom error message to console and then prints out the default message, i.e. 'contents of file' does not contain 'server name', to console. The messages also appear in the output.xml file as well.
Is there a way to disable this default message, so that only my custom message is shown?
Thanks
The msg and values attributes for the Should Contain keyword work like this:
If msg is not given, the error message is <first> != <second>.
If msg is given and values gets a true value (default), the error message is <msg>: <first> != <second>.
If msg is given and values gets a false value, the error message is simply <msg>. See Boolean arguments for more details about using false values.
(see http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Should%20Be%20Equal)
So it seems that if you only want your message to be shown you need to set the values=False attribute.

Resources