Robot Framework字符串填充

时间:2015-12-08 10:05:13

标签: python robotframework

寻找在Robot Framework上设置更好的对齐输出的方法(设置测试消息或日志)。以下是关于如何在python上完成它的示例:

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

输出:

received:    1323 
sent:        123 

是否有可能在Robot Framework上做同样的事情?

目前我的代码是:

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

我的输出是这样的(2个不同值的例子):

received: 847383
sent: 9511

received: 4814
sent: 9511111

我的预期输出应为

received: 847383
sent:     9511

received: 4814
sent:     9511111

received:  847383
sent:        9511

received:    4814
sent:     9511111

1 个答案:

答案 0 :(得分:3)

您可以使用Evaluate关键字运行一小段python代码来格式化字符串。这是一个为您执行此操作的关键字:

*** Keywords ***
Record sent and received
    [Arguments]    ${sent}    ${received}
    ${message}=    Evaluate    
    ...    "%-12s %s\\n%-12s %s\\n" % ('received:', '${received}', 'sent:', '${sent}')
    set test message    ${message}