Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework string padding

Looking for a way to have some more nice aligned output on Robot Framework (set test message or log). Here's the example on how I done it on python:

print "%-12s" % "received:", "%-5s" % 1323
print "%-12s" % "sent:", "%-5s" % 123

Output:

received:    1323 
sent:        123 

Is it possible to do the same on Robot Framework?

Currently my code is:

Set Test Message      received: ${rx}\nsent: ${tx}

and my output is like this (2 examples with different values):

received: 847383
sent: 9511

received: 4814
sent: 9511111

My expected output should be

received: 847383
sent:     9511

received: 4814
sent:     9511111

or

received:  847383
sent:        9511

received:    4814
sent:     9511111
like image 205
user2988257 Avatar asked Nov 07 '25 20:11

user2988257


1 Answers

You can use the Evaluate keyword to run a short snippet of python code to format the string. Here's a keyword that does that for you:

*** Keywords ***
Record sent and received
    [Arguments]    ${sent}    ${received}
    ${message}=    Evaluate    
    ...    "%-12s %s\\n%-12s %s\\n" % ('received:', '${received}', 'sent:', '${sent}')
    set test message    ${message}
like image 74
Bryan Oakley Avatar answered Nov 09 '25 14:11

Bryan Oakley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!