簡體   English   中英

Robot Framework-將列表變量作為關鍵字參數傳遞

[英]Robot Framework - Passing List variables as keyword argument

我正在嘗試將此字符串列表用作單個關鍵字參數,但在運行時出現錯誤。

[錯誤]文件Variables.robot中的錯誤變量名稱'$ {LIST_TEST_ATTRIBUTES}無效

我可以按住Ctrl鍵單擊$ {LIST_TEST_ATTRIBUTES},它的確在Variables.robot文件中找到了變量

Variables.robot

*** Variables ***
${LIST_TEST_ATTRIBUTES} = ["${access_engine_ip}","${analytics_engine_ip}","${AUT_Version}","${browser_type}","${ESX_server_ipaddress}","${device_type_x450_g2}"]

Test.robot
*** Settings ***
Resource Variables.robot
*** Test Cases ***
Initialize Test
    initialize test variables  ${LIST_TEST_ATTRIBUTES}

您真正想要的是在Python文件中定義列表。 使用Python文件可簡化變量的初始化。

或像Bryan Oakley指出的那樣更正語法。 請參閱用戶指南

例:

Variables.py
LIST_TEST_ATTRIBUTES = ["${access_engine_ip}", "${analytics_engine_ip}", "${AUT_Version}", "${browser_type}", "${ESX_server_ipaddress}", "${device_type_x450_g2}"]

Test.robot
*** Settings ***
Variables         Variables.py

*** Test Cases ***
Initialize Test
    initialize test variables    ${LIST_TEST_ATTRIBUTES}

*** Keywords ***
initialize test variables
    [Arguments]    ${arg1}
    Log    ${arg1}

這不是在“變量”部分中創建列表的語法; 這是正確的方法-您在名稱前加上@ ,而不是$ ,並將所有成員之間至少隔開兩個空格:

*** Variables ***
@{LIST_TEST_ATTRIBUTES}    ${access_engine_ip}    ${analytics_engine_ip}   ${AUT_Version}   ${browser_type}    ${ESX_server_ipaddress}    ${device_type_x450_g2}

現在,在您的示例中,所有成員都是對其他變量的引用。 創建套件時即會實例化LIST_TEST_ATTRIBUTES這意味着此時所有這些成員都必須已經具有值-例如在導入的資源文件中定義,或在此文件中的list變量之前定義。

如果不是這種情況-仍然沒有設置它們的值,但是稍后會發生,您可以做一些不同的事情-使用創建列表變量的關鍵字,並使用套件范圍進行設置; 然后在需要時調用關鍵字:

*** Variables ***
# the value of this variable is set through the "Set The Value Of The List Var" keyword
${LIST_TEST_ATTRIBUTES}    ${None}    # this "declaration" is not needed, but it's a good practice - thus you show to the other users there is this suite-level var

*** Keywords ***
Set The Value Of The List Var
    ${LIST_TEST_ATTRIBUTES}=     Create List    ${access_engine_ip}    ${analytics_engine_ip}   ${AUT_Version}   ${browser_type}    ${ESX_server_ipaddress}    ${device_type_x450_g2}
    Set Suite Variable    ${LIST_TEST_ATTRIBUTES}

如果已設置其成員的值,則將調用關鍵字“ Set The Value Of The List Var的值”,並且該列表變量將在該調用之后的所有情況下可用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM