我有一个与RobotFramework相关的问题,更准确地说是读取文件,为不同的命令grep它,将它们添加到字典中,然后将命令发送到服务器。
让我告诉你我现在有什么。
我有第二个函数叫做从文件发送命令
Send commands from file to server
[Arguments] ${COMMANDS_FILE}
${FILE_CONTENT}= Get File ${COMMANDS_FILE}
@{LINES}= Split to Lines ${FILE_CONTENT}
: FOR ${line} IN @{LINES}
\ Send command ${line}
发送命令是一个工作正常的关键字,只需向服务器发送命令即可。
命令文件看起来像这样(commands.txt):
VAL1;VAL2;VAL3;
VAL1;VAL4;VAL5;
VAL6;VAL7;VAL8
VAL6;VAL7;VAL8
因此,您可以看到两行上的VAL1相同。
如何获取VAL1并将其保存在某处(字典或列表),然后从包含VAL1的文件中运行所有命令?
答案 0 :(得分:1)
你必须在;
上进一步分割每一行,并检查你要查找的第一个命令。以下是基于您的代码的方式:
Send commands from file to server
[Arguments] ${COMMANDS_FILE}
${FILE_CONTENT}= Get File ${COMMANDS_FILE}
@{LINES}= Split to Lines ${FILE_CONTENT}
${commands to run}= Create List # will store only the commands you want to run
:FOR ${line} IN @{LINES}
\ ${members}= Split String ${line} separator=; # each command in the line is a list member now
\ Run Keyword If $members[0] == 'VAL1' Append To List ${commands to run} ${line}
:FOR ${command_line} IN @{commands to run}
\ Send Command ${command_line}