suggestions for writing to console

1,087 views
Skip to first unread message

g28

unread,
Nov 4, 2011, 11:09:49 AM11/4/11
to robotframework-users
I am trying to create a keyword to write messages to the console.

I want this because:

1. debug (send variables). It is faster for me to just see info on
the console than to open and drill into the log files.
2. feedback. I have a single script that takes 6+ hours because we
are adding records with a loop. We wanted to know after x records
where it is in the adding process.
3. we use Jenkins to drive all of our scripts so seeing feedback
there is helpful to us.

Issue I have is when you start a script the test case name is sent to
console along with a bunch of spaces. This is so the " | PASS | "
message lines up at the end.

The following is what shows up on the console depending on if I added
"\n"

* without newline. All of the console message are 1 per line except
the 1st is messed up and " | PASS | " is not aligned.
http://dl.dropbox.com/u/8495437/Without%20newline.png
def console_write(self, arg1):
"""Print the value given to the console."""
#sys.__stdout__.write('\n')
logger.debug('Got argument %s' % arg1)
logger.console(arg1)

#sys.__stdout__.write('\n
')

* with newline. There is an extra line each time I use the keyword.
1st line is good. " | PASS | " is aligned.
http://dl.dropbox.com/u/8495437/with%20new%20line.png
def console_write(self, arg1):
"""Print the value given to the console."""
sys.__stdout__.write('\n')
logger.debug('Got argument %s' % arg1)
logger.console(arg1)

sys.__stdout__.write('\n
')

If anyone has suggestions on how to better approach this it would be
appreciated.

Thanks.

Greg

Chris Prinos

unread,
Nov 10, 2011, 7:01:38 AM11/10/11
to robotframework-users
Instead of trying to write to the console, I'd consider one of these
other options:
1) look at the listener interface
http://robotframework.googlecode.com/svn/tags/robotframework-2.1/doc/userguide/RobotFrameworkUserGuide.html#using-listener-interface.
This will allow you to get information on tests as they are being run
and you can run arbitrary code to integrate with jenkins or some other
tool

2) Make a keyword that uses a custom python logging channel (or just
do that directly in your test code) and configure that channel to
output to a file, message queue, etc



On Nov 4, 10:09 am, g28 <kohr...@gmail.com> wrote:
> I am trying to create a keyword to write messages to the console.
>
> I want this because:
>
> 1. debug (send variables).  It is faster for me to just see info on
> the console than to open and drill into the log files.
> 2. feedback.  I have a single script that takes 6+ hours because we
> are adding records with a loop.  We wanted to know after x records
> where it is in the adding process.
> 3.  we use Jenkins to drive all of our scripts so seeing feedback
> there is helpful to us.
>
> Issue I have is when you start a script the test case name is sent to
> console along with a bunch of spaces.  This is so the " | PASS | "
> message lines up at the end.
>
> The following is what shows up on the console depending on if I added
> "\n"
>
> * without newline.  All of the console message are 1 per line except
> the 1st is messed up and " | PASS | " is not aligned.http://dl.dropbox.com/u/8495437/Without%20newline.png
>     def console_write(self, arg1):
>         """Print the value given to the console."""
>         #sys.__stdout__.write('\n')
>         logger.debug('Got argument %s' % arg1)
>         logger.console(arg1)
>
> #sys.__stdout__.write('\n
> ')
>
> * with newline.  There is an extra line each time I use the keyword.
> 1st line is good.  " | PASS | " is aligned.http://dl.dropbox.com/u/8495437/with%20new%20line.png

greg

unread,
Nov 10, 2011, 9:57:45 AM11/10/11
to robotframework-users
Thanks for the ideas Chris. I will keep them in mind if I need to
expand.

My main goal here is to have a quick way to see variable values and to
report back to Jenkins. We wanted it all together to see how the
scripts are running and to give feedback. If I added record x with
name y this gives us a way to report this to the run window (we can
report whatever we want to the console now). This way we do not have
to dig into the logs.

On a side note I modified it to use color and also added another
keyword that just dumps all of the variables to console (modified
version of GetVariables).

Since there is not a debugger and I prefer coding in Notepad++ with
syntax highlighted keywords, comments, etc. this solution is much
easier for our needs.

Greg

On Nov 10, 6:01 am, Chris Prinos <chrispri...@gmail.com> wrote:
> Instead of trying to write to the console, I'd consider one of these
> other options:
>  1) look at the listener interfacehttp://robotframework.googlecode.com/svn/tags/robotframework-2.1/doc/....

Ben Williams

unread,
Nov 10, 2011, 11:53:35 AM11/10/11
to koh...@gmail.com, robotframework-users
The easiest way to write something to the console is using Echo command.

We have a function:

def displayResults(strResults):
    os.system('Echo.')
    os.system('Echo ' + strResults)

That it shows up in the console, even the Jenkins console.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.


greg

unread,
Nov 10, 2011, 12:22:18 PM11/10/11
to robotframework-users
Ben

That is a solution but it does not get around my initial question as
to how to make the console look cleaner.

I tried this function and ran with the following in RF.

displayResults Send this to console!
displayResults Line 2
displayResults Line 3

View the results.
http://dl.dropbox.com/u/8495437/Using%20displayResults.png

Notice now the "| PASS |" is not aligned and there is an extra line
after the echos.

I wanted to prevent the extra lines AND have "| PASS |" line up when I
send console command.

So far I had to either go with

1. "| PASS |" lines up but each command send to console has extra
line.
2. "| PASS |" does not line up but each command does not have the
extra line.

Currently I am doing option 1.

Bulkan

unread,
Nov 10, 2011, 6:33:05 PM11/10/11
to koh...@gmail.com, robotframework-users
Hi all,

From the user guide this how you log to the console and file log [1]

from robot.api import logger

def log_to_console(arg):
    logger.console('Got arg %s' %arg)

def log_to_console_and_log_file(arg):
    logger.info('Got arg %s' %arg, also_consoleTrue)



Hope that helps.

-





greg

unread,
Nov 11, 2011, 8:49:21 AM11/11/11
to robotframework-users
Bulkan,

That is what I am using already. It does not solve my issues listed
above.

Greg

On Nov 10, 5:33 pm, Bulkan <bul...@gmail.com> wrote:
> Hi all,
>
> From the user guide this how you log to the console and file log [1]
>
> from robot.api import logger
>
> def log_to_console(arg):
>     logger.console('Got arg %s' %arg)
>
> def log_to_console_and_log_file(arg):
>     logger.info('Got arg %s' %arg, also_consoleTrue)
>
> Hope that helps.
>
> http://bulkan-evcimen.com
> -
>
> [1] -http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkU...
> (search
> for *Logging to console*)

Pekka Klärck

unread,
Nov 12, 2011, 4:46:15 AM11/12/11
to koh...@gmail.com, robotframework-users
2011/11/4 g28 <koh...@gmail.com>:

> I am trying to create a keyword to write messages to the console.
>
[snip]

>
> Issue I have is when you start a script the test case name is sent to
> console along with a bunch of spaces.  This is so the " | PASS | "
> message lines up at the end.

Did I get it right that everything else works fine but the text you
write to the console is not aligned nicely with the text Robot itself
writes there? I don't think there's any easy solution for that
problems because your library should know what Robot has written and
what it is going to write. Similar problem occurs when there are
errors or warnings during the execution. These messages are written to
stderr when they occur and aren't generally aligned very well with the
"normal" execution messages in the console.

One thing you could try is writing the text to sys.__stderr__. It
doesn't help with alignment in the console but you can then easily
forward your messages (and possible errors and warnings) into a file
or somewhere else. Depending on your use case, using listener as
already suggested by Chris might also work.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Reply all
Reply to author
Forward
0 new messages