简体   繁体   English

是否可以在名称中声明带有 arguments 的关键字?

[英]Is it possible to declare a keyword with arguments inside the name?

I want to declare a keyword in the following format:我想以下列格式声明一个关键字:

Environment variable    SOME_DIR   is   C:\\Something

I've tried doing it via this decorator:我试过通过这个装饰器来做:

@keyword(name = "Environment variable ${name} is ${value}")
def setEnvVar(self, name, value):
    # ...

But it is not recognized when I try to call it:但是当我尝试调用它时无法识别:

No keyword with name 'Environment variable' found.

Is this syntax possible in Robot Framework?这种语法在 Robot Framework 中是否可行? If so, how?如果是这样,怎么做?

The way you're defining the keyword is correct.您定义关键字的方式是正确的。 The way you are calling it in your test is not.您在测试中调用它的方式不是。

When you use two or more spaces between items in a statement, robot uses that to determine the keyword name and arguments.当您在语句中的项目之间使用两个或多个空格时,机器人使用它来确定关键字名称和 arguments。 Thus, when you do Environment variable SOME_DIR is C:\\Something , it see it as the keyword Environment variable followed by the arguments SOME_DIR , is , and C:\\Something .因此,当您执行Environment variable SOME_DIR is C:\\Something时,它会将其视为关键字Environment variable后跟 arguments SOME_DIRisC:\\Something

Since you are using embedded arguments, you can't use multiple spaces.由于您使用的是嵌入式 arguments,因此您不能使用多个空格。 You need to call the keyword like this:您需要像这样调用关键字:

environment variable SOME_DIR is c:\\Something

For more information see Embedding arguments into keyword names in the robot framework user guide.有关更多信息,请参阅机器人框架用户指南中的将arguments 嵌入到关键字名称中。

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

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