Hide default error message for a failed robot test - robotframework

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.

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.

Robot Framework: why does Log ignore my argument?

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

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"

robotframework :IOError: [Errno 2] No such file or directory: u"headers={u'Authorization': u'authToken AQIC5wM2LY4Sfcw2MbHyyr8ikI7zByHH1yFK7rVS-YYPzRQ

Hi I am getting mentioned error message while executing below robotframwork script,
Get AuthToken
${jsontemplate}= Get File ${TEMPLATE LOCATION}/ts_Authtoken.json
${jsoncontent}= Replace Variables ${jsontemplate}
${rc} ${response}= Do Post ${AUTHTOKEN} ${jsontemplate}
Log ${rc}
Log ${response}
Should Be Equal ${rc} ${200}
${Substring} = Get Substring ${response} 91 210
Log ${Substring}
${Substring1} = Get Substring ${Substring} 1 10
Log ${Substring1}
${Substring2} = Get Substring ${Substring} 13 119
Log ${Substring2}
${Substring3}= catenate ${Substring1} ${Substring2}
Log ${Substring3}
${headers}= Create Dictionary Authorization ${Substring3}
Log ${headers}
${rc1} ${result} = Do Post ${CREATEUP} ${jsontemplate1} headers=${headers}
Log ${rc1}
Log ${result}
If you are getting an error message of the form "No such file or directory: (something that doesn't look like a filename)", that usually means that the keyword you are calling is expecting a filename, and you're giving it something else.
Based on what little information has been provided, my guess is that "Do Post" requires a filename as its third parameter but you are passing a string that begins with "headers={..."

PROGRESS - Validating a user-input file output path

I've written some PROGRESS code that outputs some data to a user defined file. The data itself isn't important, the output process works fine. It's basically
DEFINE VARIABLE filePath.
UPDATE filePath /*User types in something like C:\UserAccount\New.txt */
OUTPUT TO (VALUE) filePath.
Which works fine, a txt file is created in the input directory. My question is:
Does progress have any functionality that would allow me to check if an input
file path is valid? (Specifically, if the user has input a valid directory, and if they have permission to create a file in the directory they've chosen)
Any input or feedback would be appreciated.
FILE-INFO
Using the system handle FILE-INFO gives you a lot of information. It also works on directories.
FILE-INFO:FILE-NAME = "c:\temp\test.p".
DISPLAY
FILE-INFO:FILE-NAME
FILE-INFO:FILE-CREATE-DATE
FILE-INFO:FILE-MOD-DATE
FILE-INFO:FILE-INFO
FILE-INFO:FILE-MOD-TIME
FILE-INFO:FILE-SIZE
FILE-NAME:FILE-TYPE
FILE-INFO:FULL-PATHNAME
WITH FRAME f1 1 COLUMN SIDE-LABELS.
A simple check for existing directory with write rights could be something like:
FUNCTION dirOK RETURNS LOGICAL (INPUT pcDir AS CHARACTER):
FILE-INFO:FILE-NAME = pcDir.
IF INDEX(FILE-INFO:FILE-TYPE, "D") > 0
AND INDEX(FILE-INFO:FILE-TYPE, "W") > 0 THEN
RETURN TRUE.
ELSE
RETURN FALSE.
END FUNCTION.
FILE-NAME:FILE-TYPE will start with a D for directories and a F for plain files. It also includes information about reading and writing rights. Check the help for more info. If the file doesn't exist basically all attributes except FILE-NAME will be empty or unknown (?).
Edit: it seems that FILE-TYPE returns W in some cases even if there's no actual writing rights in that directory so I you might need to handle this through error processing instead
ERROR PROCESSING
OUTPUT TO VALUE("f:\personal\test.txt").
PUT UNFORMATTED "Test" SKIP.
OUTPUT CLOSE.
CATCH eAnyError AS Progress.Lang.ERROR:
/* Here you could check for specifically error no 98 indicating a problem opening the file */
MESSAGE
"Error message and number retrieved from error object..."
eAnyError:GetMessage(1)
eAnyError:GetMessageNum(1) VIEW-AS ALERT-BOX BUTTONS OK.
END CATCH.
FINALLY:
END FINALLY.
SEARCH
When checking for a single file the SEARCH command will work. If the file exists it returns the complete path. It does however not work on directory, only files. If you SEARCH without complete path e g SEARCH("test.p") the command will search through the directories set in the PROPATH environment variable and return the first matching entry with complete path. If there's no match it will return unknown value (?).
Syntax:
IF SEARCH("c:\temp\test.p") = ? THEN
MESSAGE "No such file" VIEW-AS ALERT-BOX ERROR.
ELSE
MESSAGE "OK" VIEW-AS ALERT-BOX INFORMATION.
SYSTEM-DIALOG GET-FILE character-field has an option MUST-EXIST if you want to use a dailogue to get filename/dir from user. Example from manual
DEFINE VARIABLE procname AS CHARACTER NO-UNDO.
DEFINE VARIABLE OKpressed AS LOGICAL INITIAL TRUE.
Main:
REPEAT:
SYSTEM-DIALOG GET-FILE procname
TITLE "Choose Procedure to Run ..."
FILTERS "Source Files (*.p)" "*.p",
"R-code Files (*.r)" "*.r"
MUST-EXIST
USE-FILENAME
UPDATE OKpressed.
IF OKpressed = TRUE THEN
RUN VALUE(procname).
ELSE
LEAVE Main.
END.

Resources