Key Value 比對 - daniel-qa/RobotFramework GitHub Wiki

Key Value 比對

範例: 依站台資訊,設定變數

# 站點對應 QRCode 字典
&{QRCODE_MAP}    teammodel.net=894187    rc.teammodel.cn=243826    www.teammodel.cn=478226

Set Website
    [Documentation]    根據當前網址設置站點 QRCode
    ${currentUrl}    Get Location
    Log To Console    當前網址: ${currentUrl}

    ${qrcode}    Set Variable    NONE
    FOR    ${key}    IN    @{QRCODE_MAP.keys()}
        ${contains}    Evaluate    '${currentUrl}'.find('${key}') != -1
        Run Keyword If    ${contains}
        ...    Set Suite Variable    ${qrcode}    ${QRCODE_MAP["${key}"]}
    END

    Log To Console    當前站點的 QRCode: ${qrcode}
	Log     當前站點的 QRCode: ${qrcode}