ก็ยังคงเขียนเกี่ยวกับ robot framework อีกนั่นแหละ ^_^ วันนี้เลยจะมาเขียนตัวอย่างการทดสอบ api ด้วย Robot Framework (Get Request) อย่างง่ายกันค่ะ
สิ่งที่ต้องใช้
- API ที่จะใช้ในการทดสอบ อันนี้จะใช้ API ที่ http://thetestingworldapi.com ค่ะ
- เครื่องมือที่ใช้เขียน Notepad++ ^_^
- Cmd
ขั้นแรกเราไปที่ http://thetestingworldapi.com แล้วคลิกที่ API ในที่นี้ขอเลือก API ของ StudentsDetails ดังรูปค่ะ

จากนั้นก็เปิด Notpad++ ขึ้นมาเลยค่ะ
ที่ Settings ต้องเรียก Library RequestsLibrary นะ แต่ก่อนอื่นต้องไปลง Library ตัวนี้กันก่อน โดยใช้คำสั่ง
pip install robotframework-requests
ถ้าลงแล้วก็จะตรวจสอบได้ โดยใช้คำสั่ง pip freeze ดังรูป

มาที่ Notepad++ กันต่อ ^_^ เขียนคำสั่ง ดังนี้เลย

จะเห็นได้ว่าเรามีแสดง status_code ออกมาด้วย มารู้จักความหมายของ status_code แต่ละตัวกันดีกว่า
2xx คือ OK
3xx คือ Redirection
4xx คือ Resource not found
5xx คือ Server error
มารันผลลัพธ์กันดีกว่า

อันนี้ไม่ขอรัน code ในส่วนของ content นะ ไปรันกันเอาเอง เพราะมันเยอะมากตาลาย capture รูปมาก็คงดูไม่รู้เรื่อง ^_^
การทดสอบ Get Request อย่างง่าย ก็ประมาณนี้นะคะ