如何将特定列表变量传递给 Get 和 Set 函数?
How can I pass a specific list variable to a Get and Set function?
如何将特定的全局列表变量传递给以下 Get 和 Set 函数?
假设有一个包含多个 xxxx.txt 文件的@{Files} 列表。
假设@{Files}[0] 有 dinosaur.txt
Get the File Version
[Arguments] @{Files}[??] # Not sure about this
Run Keyword If File is present
... ${time} = OperatingSystem.Get Modified Time @{Files}[]
... ${dateonly} = Split String ${time} ${SPACE}
... ${Version} = @{dateonly}[0]
ELSE
... ${Version} = MISSING
[Return] ${Version}
Set a dinosaur file version test case
${Version} = Get the File Version @{Files}[0] # Is this right ???
Set test variable ${Version}
列表变量有两种使用方式。当引用为 ${mylist}
时,我们引用下面的 Python 对象(一个类型为 List 的变量)。当我们使用 @{mylist}
时,我们正在扩展该列表中的所有元素。
以下代码是复制原始代码的完整示例(您只需要创建一个名为 dinosaur.txt
的文件):
*** Settings ***
Library OperatingSystem
Library Collections
Library String
*** Test Cases ***
Test Files Versions
@{Files}= Create List dinosaur.txt bird.txt dog.txt cat.txt
${Version}= Get the File Version ${Files[0]}
Log Version of file, ${Files[0]} is ${Version}
FOR ${file} IN @{Files}
${file_version}= Get the File Version ${file}
Log Version of file, ${file} is ${file_version}
END
Set Test Variable ${Files}
Set a dinosaur file version test case
Log Version of file, ${Files[0]} is ${Version}
*** Keywords ***
Get the File Version
[Arguments] ${File}
${file_is_present}= File is present ${File}
IF ${file_is_present}
${time}= OperatingSystem.Get Modified Time ${File}
@{dateonly}= Split String ${time} ${SPACE}
${Version}= Set Variable ${dateonly[0]}
ELSE
${Version}= Set Variable If not ${file_is_present} MISSING
END
[Return] ${Version}
Set a dinosaur file version test case
${Version}= Get the File Version ${Files[0]}
Set test variable ${Version}
File is present
[Arguments] ${File}
${result}= Run Keyword And Return Status File Should Exist ${File}
Return From Keyword ${result}
如何将特定的全局列表变量传递给以下 Get 和 Set 函数?
假设有一个包含多个 xxxx.txt 文件的@{Files} 列表。 假设@{Files}[0] 有 dinosaur.txt
Get the File Version
[Arguments] @{Files}[??] # Not sure about this
Run Keyword If File is present
... ${time} = OperatingSystem.Get Modified Time @{Files}[]
... ${dateonly} = Split String ${time} ${SPACE}
... ${Version} = @{dateonly}[0]
ELSE
... ${Version} = MISSING
[Return] ${Version}
Set a dinosaur file version test case
${Version} = Get the File Version @{Files}[0] # Is this right ???
Set test variable ${Version}
列表变量有两种使用方式。当引用为 ${mylist}
时,我们引用下面的 Python 对象(一个类型为 List 的变量)。当我们使用 @{mylist}
时,我们正在扩展该列表中的所有元素。
以下代码是复制原始代码的完整示例(您只需要创建一个名为 dinosaur.txt
的文件):
*** Settings ***
Library OperatingSystem
Library Collections
Library String
*** Test Cases ***
Test Files Versions
@{Files}= Create List dinosaur.txt bird.txt dog.txt cat.txt
${Version}= Get the File Version ${Files[0]}
Log Version of file, ${Files[0]} is ${Version}
FOR ${file} IN @{Files}
${file_version}= Get the File Version ${file}
Log Version of file, ${file} is ${file_version}
END
Set Test Variable ${Files}
Set a dinosaur file version test case
Log Version of file, ${Files[0]} is ${Version}
*** Keywords ***
Get the File Version
[Arguments] ${File}
${file_is_present}= File is present ${File}
IF ${file_is_present}
${time}= OperatingSystem.Get Modified Time ${File}
@{dateonly}= Split String ${time} ${SPACE}
${Version}= Set Variable ${dateonly[0]}
ELSE
${Version}= Set Variable If not ${file_is_present} MISSING
END
[Return] ${Version}
Set a dinosaur file version test case
${Version}= Get the File Version ${Files[0]}
Set test variable ${Version}
File is present
[Arguments] ${File}
${result}= Run Keyword And Return Status File Should Exist ${File}
Return From Keyword ${result}