robot小技巧

2018-08-31  本文已影响3人  heliping_peter

定位json中的文件

${resp}=    Post Request    cmb    ${url}     data=${abc}   headers=${header} 
    Should Be Equal As Strings    ${resp.status_code}    200
    ${content}=         Set Variable    ${resp.json()}
    ${id}    Set Variable   ${content['data'][0]['id']}

list类型的json修改值

 ${aaa}      Set Variable    [{'aaa':"1",'bbb':"2"}]
    ${aaaList}    Evaluate    ${aaa}
    Log    ${aaaList[0]}

循环执行

devops_pipeline执行结果_流水线执行完毕
    [Arguments]     ${repo_type}=github      ${workspace}=${workspaceName_github}      ${pipeline}=${pipelineName_github}
      :FOR    ${i}    IN RANGE    100
    \    sleep    60
    \    ${return}    devops_pipeline执行结果    ${repo_type}      ${workspace}     ${pipeline}
    \    Run Keyword If    '${return}'=='Success'    Exit For Loop 
    \    Run Keyword If    '${return}'=='Failed'    Exit For Loop
    [Return]    ${return}

用例失败后仍然执行

Run Keyword And Continue On Failure    Should Be Equal As Strings    '${return}'    'Success' 

base64解码,并且将解码的字节转换为字符

    ${kk}    Evaluate    base64.b64decode('${github_token}')    modules=base64
    ${kkstr}     Decode Bytes To String    ${kk}    UTF-8   

替换json中的某个值

 ${github_decode_token}    Evaluate    ${workspaceJSON_github}
    Set To Dictionary    ${github_decode_token['scm']}      token=${kkstr}
    log     ${github_decode_token['scm']['token']}
    [Return]    ${github_decode_token}

条件执行

${workspaceJson}     Run Keyword If    '${repo_type}'=='gitlab'   Set Variable    ${workspaceJson_gitlab}
   ...       ELSE IF     '${repo_type}'=='github'   Set Variable      ${githubjson_token}
   log    ${workspaceJson} 
上一篇下一篇

猜你喜欢

热点阅读