
Requests เป็น Robot Framework Library ใช้เพื่อทดสอย API ที่ช่วยให้คุณสามารถ รับ และส่งข้อมูลผ่านทาง HTTP ได้ง่ายๆ สามารถนำมาใช้ในการทดสอบAPI ประเภท REST และ SOAP
การติดตั้ง
ติดตั้งง่ายๆโดยใช้คำสั่ง pip
pip install robotframework-requests
🤖 Quick Start
ตัวอย่างการใช้งาน Requests Library แบบง่าย ในการดึงข้อมูลผ่านทาง method GET
*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Quick Get Request Test
${response}= GET https://www.google.com
คำสั่งที่สำคัญ
Keyword พื้นฐานในการส่งคำสั่งไปยัง API Server มีดังนี้
- GET ดึงข้อมูลจาก API
- POST ส่งข้อมูลไปยัง API เพื่อทำการ สร้างข้อมูล หรือใช้ login
- UPDATE / PATCH ส่งข้อมูลไปยัง API เพื่อทำการ อัพเดทข้อมูล
- DELETE ส่งข้อมูลไปยัง API เพื่อทำการ ลบข้อมูล
คำสั่งสำหรับการตรวจสอบค่า
- reason() ดึงข้อมูล status code
- json() ดึงข้อมูล response body
- Status Should Be ตรวจสอบ status ด้วย keyword ของ robot
*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Example GET keyword
${body} Create Dictionary firstname=John
${response} GET https://restful-booker.herokuapp.com/booking ${body}
Status Should Be 200
Log List ${response.json()}
Example POST keyword login
${body} Create Dictionary username=admin password=password123
${response} POST url=https://restful-booker.herokuapp.com/auth json=${body}
Log ${response.json()}
${token} Set Variable ${response.json()}[token]
Log ${token}
ดาวน์โหลดตัวอย่าง คลิก
Keyword Document
http://marketsquare.github.io/robotframework-requests/doc/RequestsLibrary.html
สนใจเรียนรู้แบบเจาะลึก
Robot Framework Selenium
Web Automated Test ด้วย
Robot Framework และ Selenium 6



[…] blog ก่อนหน้านี้ได้มีการกล่าวถึงการ ทดสอบ API ด้วย Requests Library ใน Robot Framework ไปแล้ว Blog […]