在一般的接口測試過程中,我們往往會遇到附件上傳的接口,在robotframework中,我們往往采用evaluate關(guān)鍵字來處理此類接口:
demo_file
Create Session api http://127.0.0.1
${file} Evaluate open(r"D:\\pic\\21325098165.jpg",'rb')
&{tepp} Create Dictionary file=${file}
${resp} post request api /host/web/worker/v1/upload files=&{tepp} headers=${headers}
${content} To Json ${resp.content}
${msg} Set Variable ${content['msg']}
在上述的描述的過程中,先evaluate關(guān)鍵字調(diào)用open的方法將需要上傳的文件打開,在進(jìn)行字典的創(chuàng)建,在后續(xù)的過程中將創(chuàng)建的字典傳到post request 關(guān)鍵字的 file參數(shù)中。