英文:
Have keyword with arguments as argument
问题
I'm trying to create a keyword that runs through a passed-in process and then if that process finishes successfully, I log a list of process ids as passed. I'm having issues with the argument layout right now as I continue to get positional argument errors. Is it possible to do this all inline rather than defining everything beforehand? I'm trying to keep this as easy to read/write as possible for others that will be writing scripts with this.
The Validate Step keyword is how I'm attempting to go about this, but it's thinking that the arguments for the step keyword are the positional arguments for step_id. Then step_ids aren't taking the list of ids.
英文:
I'm trying to create a keyword that runs through a passed in process and then if that process finishes successfully, I log a list of process ids as passed. I'm having issues with the argument layout right now as I continue to get positional argument errors. Is it possible to do this all inline rather than defining everything before hand? I'm trying to keep this as easy to read/write as possible for others that will be writing scripts with this.
The Validate Step keyword is how I'm attempting to got about this but its thinking that the arguments for the step keyword is the positional argument for step_id. Then step_ids aren't taking the list of ids.
*** Test Cases ***
TF-1
[Documentation] Test Flow 1
[Tags] Test-Flow
Open Application
Click Element ${test_element1}
Validate Step
... step=Click Element ${test_element2}
... step_ids=abcd-1234 abcd-5678
*** Keywords ***
Validate Step
[Documentation] Executes keyword, if keyword ends with a status of "True"/"Pass", ids are marked as passed
[Arguments] ${keyword} @{step_ids}
${status}= Run Keyword and Return Status ${keyword}
Log ${status}
Run Keyword If ${status} Pass Ids @{step_ids}
... ELSE Fail Ids @{step_ids}
Pass Ids
[Arguments] @{ids}
Log ${ids} passed
Fail Ids
[Arguments] @{ids}
Log ${ids} failed
答案1
得分: 0
你有两个问题:Robot Framework 不太能处理带有空格的变量,并且你混合了位置和命名变量。这是我能够找到的最佳解决方法。它利用了 args 和 kwargs。Step_ids 必须是一个逗号分隔的进程列表。
*** 设置 ***
Library Collections
Library String
*** 关键字 ***
验证步骤
[参数] @{args} &{params}
记录到控制台 ${params}
${关键字}= 从列表中移除 ${args} 0
运行关键字并返回状态 ${关键字} @{args}
${step_ids_s}= 从字典中获取 ${params} step_ids
${step_ids}= 拆分字符串 ${step_ids_s} ,
记录到控制台 ${step_ids}
*** 测试用例 ***
TF-1
验证步骤 LogMany foo bar baz step_ids=abcd-1234,abcd-5678
英文:
You have two issues: Robot Framework does not handle variables with spaces very well, and you mix positional and named variables. This is the best workaround I was able to make. It takes advantage of args and kwargs. Step_ids must be a comma-separated list of processes.
*** Settings ***
Library Collections
Library String
*** Keywords ***
Validate Step
[Arguments] @{args} &{params}
Log To Console ${params}
${keyword}= Remove From List ${args} 0
Run Keyword And Return Status ${keyword} @{args}
${step_ids_s}= Get From Dictionary ${params} step_ids
${step_ids}= Split String ${step_ids_s} ,
Log To Console ${step_ids}
*** Test Cases ***
TF-1
Validate Step LogMany foo bar baz step_ids=abcd-1234,abcd-5678
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论