简体   繁体   English

Robot Framework:在变量中使用当前日期无效

[英]Robot Framework: Using current date in the variable is not working

My Variables header inside my Robot file looks like: 我的机器人文件中的我的Variables标头看起来像:

*** Variables ***
${date} =  Get Current Date    result_format=%Y%m%d%H%M%S
${workspaceName} =  Workspace${date}

When I use ${workspaceName} later in the file, it's content is "Get Current Date result_format=%Y%m%d%H%M%S" as a string. 当我稍后在文件中使用${workspaceName} ,其内容为“获取当前日期result_format =%Y%m%d%H%M%S”作为字符串。 But when ${workspaceName} is defined inside a test case, it works correctly. 但是,在测试用例中定义${workspaceName}时,它可以正常工作。

Is it true that the Variables section can't contain functions? 变量部分不能包含函数是真的吗? For example Get Current Date ? 例如Get Current Date

You are correct. 你是对的。 You cannot call functions within the ***Variables*** section. 您不能在“ ***Variables***部分中调用函数。 If you would like to use the Get Current Date Function and assign it to a Variable you will need to do it within the ***Test Cases*** section or the ***Keywords*** section! 如果您想使用“ Get Current Date功能并将其分配给变量,则需要在“ ***Test Cases***部分或“ ***Keywords***部分中进行操作!

For example: 例如:

***Settings***
Library    DateTime

***Variables***
[...]

***Test Cases***
[...]
${CurrentDate} =    Get Current Date    result_format=%Y%m%d%H%M%S
Log    ${CurrentDate}

***Keywords***
[...]
# Can do it here too!

Will log today's date in the format you have specified. 将以您指定的格式记录今天的日期。 Hope this helps! 希望这可以帮助! Any other questions please ask away! 还有其他问题请问!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM