我是机器人框架的新手,当运行下面的变量$ {month}重新回归时,没有'
。我要做的是将月份作为数字转换为文本中的相关月份,例如1月至1月,4月至4月等。
我相信这将是一个简单的修复,但我不知道它是什么......任何帮助将非常感激。
${month int} Get Current Date result_format=%m
Log To Console month int=${month int}
${month} = Set Variable If '${month int}' >= 13 Fail
${month} = Set Variable If '${month int}' == '01' January
${month} = Set Variable If '${month int}' == '02' Febuary
${month} = Set Variable If '${month int}' == '03' March
${month} = Set Variable If '${month int}' == '04' April
${month} = Set Variable If '${month int}' == '05' May
${month} = Set Variable If '${month int}' == '06' June
${month} = Set Variable If '${month int}' == '07' July
${month} = Set Variable If '${month int}' == '08' August
${month} = Set Variable If '${month int}' == '09' September
${month} = Set Variable If '${month int}' == '10' October
${month} = Set Variable If '${month int}' == '11' November
${month} = Set Variable If '${month int}' == '12' December
Log To Console month string=${month}
答案 0 :(得分:0)
我不确定比较失败的原因(也许您将整数与字符串进行比较?)但您可以通过使用dateTime对象来解决问题:
${month int} Get Current Date result_format=datetime
Log To Console month int=${datetime.month}
${month} = Set Variable If ${datetime.month} >= 13 Fail
${month} = Set Variable If ${datetime.month} == 1 January
${month} = Set Variable If ${datetime.month} == 2 Febuary
${month} = Set Variable If ${datetime.month} == 3 March
....
答案 1 :(得分:0)
您的代码完全按照您要求他的方式执行。看看它:在最后一行你说
${month} = Set Variable If '${month int}' == '12' December
因此${month}
设置为None
,因为${month int}
不是12而None
是给定条件不为真的情况的默认值。您需要使用else if
逻辑,这在Robotframework中以这种方式完成:
${month} = Set Variable If '${month int}' >= 13 Fail
... '${month int}' == '01' January
... '${month int}' == '02' Febuary
... '${month int}' == '03' March
... '${month int}' == '04' April
... '${month int}' == '05' May
... '${month int}' == '06' June
... '${month int}' == '07' July
... '${month int}' == '08' August
... '${month int}' == '09' September
... '${month int}' == '10' October
... '${month int}' == '11' November
... '${month int}' == '12' December
答案 2 :(得分:0)