I’m a newbee, I have a requirement to generate command line string with different input argument and will run this command in my test device, but I don’t how to generate it .
test code requirement and example:
default suffix is ‘’ or ${EMPTY}
append different group/string to this suffix,
but I found ${cmd_suffix} old value can’t write to ${cmd_suffix} new value
any good solution for me to generate this command line string ?
input argument is mandatory and not ${None}
parse system/tenant/cmd suffix
${cmd_suffix} = Set Variable ' ' # default is no suffix
${cmd_suffix} = Run Keyword If '${system}' is not '${None}' Catenate '${cmd_suffix} system ${system}'
${cmd_suffix} = Run Keyword If '${tenant}' is not '${None}' Catenate '${cmd_suffix} tenant ${tenant}'
${cmd_suffix} = Run Keyword If '${domain}' is not '${None}' Catenate '${cmd_suffix} domain ${domain}'
${cmd_suffix} = Run Keyword If '${cmd_user}' is not '${None}' Catenate '${cmd_suffix} user ${cmd_user}'
${cmd_suffix} = Run Keyword If '${cmd_group}' is not '${None}' Catenate '${cmd_suffix} group ${cmd_group}'
${cmd_suffix} = Run Keyword If '${source}' is not '${None}' Catenate '${cmd_suffix} source ${source}'
${cmd_suffix} = Run Keyword If '${cmd}' is not '${None}' Catenate '${cmd_suffix} ${cmd}'
Log ${cmd_suffix} # log result for debug
Thanks for the reply
I will run this keyword in my robot testcase, just input the arguments after this keyword like this format:
My Keyword system=sys1 domain=mydomain.com cmd_user=my_user1
My Keyword system=sys2 domain=mydomain.com cmd_user=my_user2 cmd_group=my_group2
My Keyword tenant=t1 source=my_source cmd_user=my_user3 cmd_group=my_group3 cmd=extensive
sorry, I just list the command line input argument in the code example, and not list the keyword name and [Arguments]
in fact, my expected result is some variable ${cmd_suffix} can save previous value in this keyword, and not be overwrite. the scope is only in this keyword. (local keyword scope variable), seems current result is overwrite previous value and can’t save previous value.
with this base command line, there is more filter option like: user_name/group_name/domain_name/system_name/tenant_name/extensive/brief/…
in addition, default command suffix is None, we can add any filter with input arguments to generate it based on different testcase, the command filter may have 1-4 at the same time, for example, we can add both [user_name and domain_name] or [user_name + system_name + extensive] or [group_name + domain_name + tenant_name + brief] …
after generate the command line and filter suffix, we will run this command on device
my expected is {cmd_suffix}** can **[Catenate]** previous **{cmd_suffix} value with new suffix when input argument is not None, but previous {cmd_suffix}** value is **{None} …
thanks all for your reply, I have a code example to do it as below, is there any good/better solution to do it ?
my current code as below
Verify Use Table
[Documentation] Check User Table
[Arguments] ${devices}=device # input argument, device name
... ${cmd}=${None} # input argument, cmd suffix after show: [ extensive | all-systems-tenants | root-system | tenant t1 ]
... ${system}=${None} # input argument, cmd suffix after show: [ system sys1 ]
... ${tenant}=${None} # input argument, cmd suffix after show: [ tenant t1 ]
... ${cmd_source}=all # input argument, show cmd : source [ all | source1| source2 | source3 ]
... ${cmd_user}=${None} # input argument, show cmd filter auth table result with [user xxx]
... ${cmd_group}=${None} # input argument, show cmd filter auth table result with [group xxx]
... ${source_name}=${None} # input argument, show cmd filter auth table result with [source all source-name xxx]
... ${source}=${None} # check argument in result
... ${domain}=${None} # check argument in result
... ${ip}=${None} # check argument in result
... ${total_count}=${None} # check argument in result
... ${user}=${None} # check argument in result
... ${groups}=${None} # check argument in result
... ${state}=Valid # check argument in result, default is Valid
... ${file}=template.yaml # template file
${cmd_list} = Create List
Run Keyword If '${system}' is not '${None}' Append To List ${cmd_list} system ${system}
Run Keyword If '${tenant}' is not '${None}' Append To List ${cmd_list} tenant ${tenant}
Run Keyword If '${domain}' is not '${None}' Append To List ${cmd_list} domain ${domain}
Run Keyword If '${cmd_user}' is not '${None}' Append To List ${cmd_list} user ${cmd_user}
Run Keyword If '${cmd_group}' is not '${None}' Append To List ${cmd_list} group ${cmd_group}
Run Keyword If '${source_name}' is not '${None}' Append To List ${cmd_list} source-name ${source_name}
Run Keyword If '${cmd}' is not '${None}' Append To List ${cmd_list} ${cmd}
Log ${cmd_list}
${cmd_suffix} = Set Variable ${EMPTY} # default is no suffix
:FOR ${cmd} IN @{cmd_list}
\ ${cmd_suffix} = Catenate ${cmd_suffix} ${cmd}
\ Log ${cmd_suffix}
Log ${cmd_suffix}
# ....
# code for device connection and run cmd steps
# ....