机器人框架的参数缺失

发布于 2024-12-11 23:58:50 字数 762 浏览 0 评论 0原文

下面的内容是抱怨“删除目录”需要 1 或 2 个参数,而我没有给出任何参数。我使用的是 2.6.3,dcsLshLocation 是一个变量(在前面添加 x 不会改变错误)。我正在使用这一切的Java 版本。

*** Settings ***
| Documentation | http://jira.basistech.net:8080/browse/JEST-226
| Resource | src/main/resources/jug-shared-keywords.txt
| Force Tags | integration | 
| Suite Precondition | Run Keywords | 
|                    |   ...        | Validate SUT Installations |
|                    |   ...        | Launch Derby Server        | 
|                    |   ...        | Copy file ${jddInstallDir}/conf/jdd-conf-basic.xml to ${jddInstallDir}/conf/jdd-conf.xml
|                    |   ...        | Remove Directory  | ${dcsLshLocation} |
| Suite Teardown | Run Keywords | Shutdown Derby 
| Test Timeout | 20 minutes

The below is rewarded with a complaint that Remove Directory requires 1 or 2 arguments and I gave it none. I'm using 2.6.3, and dcsLshLocation is a variable (and adding an x in front doesn't change the error). I'm using the Java version of all this.

*** Settings ***
| Documentation | http://jira.basistech.net:8080/browse/JEST-226
| Resource | src/main/resources/jug-shared-keywords.txt
| Force Tags | integration | 
| Suite Precondition | Run Keywords | 
|                    |   ...        | Validate SUT Installations |
|                    |   ...        | Launch Derby Server        | 
|                    |   ...        | Copy file ${jddInstallDir}/conf/jdd-conf-basic.xml to ${jddInstallDir}/conf/jdd-conf.xml
|                    |   ...        | Remove Directory  | ${dcsLshLocation} |
| Suite Teardown | Run Keywords | Shutdown Derby 
| Test Timeout | 20 minutes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2024-12-18 23:58:50

当这个问题最初被写出来时,运行关键字只能运行不带参数的关键字。但事实已不再如此。从文档中:

从 Robot Framework 2.7.6 开始,关键字也可以与参数一起运行,使用大写 AND 作为关键字之间的分隔符。执行关键字时,第一个参数是第一个关键字,后续参数直到第一个 AND 都是它的参数。第一个 AND 之后的第一个参数是第二个关键字,接下来的参数是它的参数,直到下一个 AND 为止。等等。

因此,问题中的代码可以这样表达:

| Suite Precondition | Run Keywords | 
|                    |   ...        | Validate SUT Installations
|                    |   ...        | AND | Launch Derby Server
|                    |   ...        | AND | Copy file ${jddInstallDir}/conf/jdd-conf-basic.xml to ${jddInstallDir}/conf/jdd-conf.xml
|                    |   ...        | AND | Remove Directory  | ${dcsLshLocation}

以下是问题的原始答案,其他人可能仍然觉得有用。它仍然与 2.7.6 之前的机器人框架版本相关。

当您使用运行关键字时,您无法运行带参数的关键字。诚然,文档是一个有点不清楚,但它是这样说的:

如果执行的关键字需要,则必须使用用户关键字
接受争论。

应该说的是,当您使用Run keywords时,每个参数都是要运行的关键字的名称。该关键字本身不能接受任何参数,因为机器人无法知道一个关键字的参数在哪里结束以及下一个关键字从哪里开始。

请记住,... 只是意味着前一行在下一行中继续,因此虽然它看起来像是每行都是带有参数的单独关键字,但事实并非如此。您的示例与以下内容相同:

| Suite Precondition | Run Keywords | 
|                    |   ...        | Validate SUT Installations |
|                    |   ...        | Launch Derby Server        | 
|                    |   ...        | Copy file ${jddInstallDir}/conf/jdd-conf-basic.xml to ${jddInstallDir}/conf/jdd-conf.xml
|                    |   ...        | Remove Directory  | 
|                    |   ...        | ${dcsLshLocation} |

When this question was originally written, Run Keywords could only run keywords that do not take arguments. That is no longer true. From the documentation:

Starting from Robot Framework 2.7.6, keywords can also be run with arguments using upper case AND as a separator between keywords. The keywords are executed so that the first argument is the first keyword and proceeding arguments until the first AND are arguments to it. First argument after the first AND is the second keyword and proceeding arguments until the next AND are its arguments. And so on.

The code in the question can thus be expressed like this:

| Suite Precondition | Run Keywords | 
|                    |   ...        | Validate SUT Installations
|                    |   ...        | AND | Launch Derby Server
|                    |   ...        | AND | Copy file ${jddInstallDir}/conf/jdd-conf-basic.xml to ${jddInstallDir}/conf/jdd-conf.xml
|                    |   ...        | AND | Remove Directory  | ${dcsLshLocation}

The following is the original answer to the question, which others may still find useful. It is still relevant for versions of robot framework prior to 2.7.6.

When you use Run Keywords, you cannot run keywords that take arguments. Admittedly the documentation is a bit unclear, but this is what it says:

User keywords must nevertheless be used if the executed keywords need
to take arguments.

What it should say is that, when you use Run Keywords, each argument is the name of a keyword to run. This keyword cannot take any arguments itself because robot can't know where the arguments for one keyword ends and the next keyword begins.

Remember that ... simply means that the previous row is continued on the next, so while it looks like each row is a separate keyword with arguments, it's not. You example is the same as:

| Suite Precondition | Run Keywords | 
|                    |   ...        | Validate SUT Installations |
|                    |   ...        | Launch Derby Server        | 
|                    |   ...        | Copy file ${jddInstallDir}/conf/jdd-conf-basic.xml to ${jddInstallDir}/conf/jdd-conf.xml
|                    |   ...        | Remove Directory  | 
|                    |   ...        | ${dcsLshLocation} |
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文