7
votes

In a robot framework test case I set a variable and then do a process.

Because the setting of the variable is not a very interesting bit of information, I don't want to include that in my report.

| Verifying STUFF  |
| | ${endpoint}=    | set variable | STUFF
| | Verify

My report contains this:

KEYWORD: ${endpoint} = BuiltIn.Set Variable STUFF

But I would rather not have it there. How can I tell Robot Framework to just not log that line?

------edit------

It looks like this should do it:

pybot --removekeywords NAME:SetVariable testcase.txt

But the Set Variable keywords are still there.

(And yes, I upgraded my robot framework to 2.8.3 to take advantage of this function.)

5
What exactly do you mean by "the Set Variable keywords are still there"? Do you mean they're still logged, or do you mean that they still exist in your test? Also, are you using the Java- or Python-based version of Robot Framework? - Brandon Olson

5 Answers

3
votes

The best you can do is to use

Set Log Level    NONE

but it will still log all the keyword calls, just not anything inside those.

Or if you call a python function which calls another function, then the call to the second function is not logged.

Like this:

*** Settings ***
Library           lib.py

*** Test Cases ***
demo
    Set Log Level    NONE
    ${a}    foo
    xyzzy

*** Keywords ***
xyzzy
    qwerty

qwerty
    No Operation
    Log    123

and lib.py being like this:

def foo():
    abc = bar()
    return abc

def bar():
    c = 1
    print c
    return c
3
votes

The problem is that when you assign a variable like ${var} = Keyword, the name of the keyword in Robot Framework outputs is ${var} = Keyword, not Keyword as you would expect. If your keyword is from a library or a resource file, its name will also be included like ${var} = MyLibrary.Keyword. The latter is a feature but the former is a bug that is hopefully fixed in RF 2.9.

An easy workaround for the keyword name, for now, including the variable name is using wildcards. Something like this ought to work for you:

--RemoveKeywords 'name:* = BuiltIn.Set Variable'
2
votes

You can use --removekeywords or --flattenkeywords option on pybot to remove the content of keyword So if you have e.g. keyword "foo" that contains lot's of logging keywords, you can set "--flattenkeywords name:foo" option to pybot, and In the log you'll only see the primary keyword, but no keywords inside it.

http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.3#removing-and-flattening-keywords

0
votes

If you use a python library, the following monkey-patching works for me:

from robot.libraries.BuiltIn import BuiltIn
from robot.output.logger import LOGGER
import types

def _nothing(*args, **kwargs):
    pass

def disable_keyword_logging(self):
    self._logging_methods = (LOGGER.start_keyword, LOGGER.end_keyword)
    LOGGER.start_keyword = types.MethodType(_nothing,LOGGER)
    LOGGER.end_keyword = types.MethodType(_nothing,LOGGER)

def enable_keyword_logging(self):
    LOGGER.start_keyword, LOGGER.end_keyword = self._logging_methods

Then when this script is run:

Disable keyword logging
Log    Hello world
Enable keyword logging

the "Log" keyword is not logged to the output but the output is. If you really want nothing (also no debug/info/warn information logged by the called keywords), you will still have to set the log level to "NONE".

0
votes

Robot Framework doesn't log "global" variables as part of a variable table. Global is in quotation marks because Set Global Variable actually is logged, but if you initialize your variable like so...

*** Variables ***
${endpoint}     stuff

*** Keywords ***

...then it will not be in the Log. Additionally, if you don't want anyone to see the variable at all if they're just looking at the front end of your testing suite, you can bury it in a Resource file and the call the Resource file.

Robot Framework logs your Set Variable keywords and results because Set Variable implies that you're setting a variable dynamically and might be setting it based on the result of a keyword, in which case you'd probably want to know what the result of the keyword is. If you're just creating a static variable, then no extra work beyond the table is required. Is a dynamic variable a required part of your code?