
Set up a rest api testing environment with python and robot framework, installing python, PyCharm, and libraries like robot framework, requests, and json; configure a project and verify installations.
*** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${base_url} http://restapi.demoqa.com
${city} Delhi
*** Test Cases ***
Get_weatherInfo
create session mysession ${base_url}
${response}= get request mysession /utilities/weather/city/${city}
log to console ${response.status_code}
log to console ${response.content}
log to console ${response.headers}
${contentTypeValue}= get from dictionary ${response.headers} Content-Type
log to console ${contentTypeValue}
# Validations
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 200
${body}= convert to string ${response.content}
should contain ${body} Delhi
${contentTypeValue}= get from dictionary ${response.headers} Content-Type
should be equal ${contentTypeValue} application/json
*** Settings ***
Documentation Suite description
Library RequestsLibrary
Library Collections
*** Variables ***
${base_url}= http://restapi.demoqa.com/customer
*** Test Cases ***
Put_CustomerRegistration
create session mysession ${base_url}
${body}= create dictionary FirstName=kiran1234 LastName=kiran1234 UserName=kiran1234xyx Password=kiran1234 Email=kiran1234@gmail.com
${header}= create dictionary Content-Type=application/json
${response}= post request mysession /register data=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
#VALIDATIONS
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 201
${res_body}= convert to string ${response.content}
should contain ${res_body} OPERATION_SUCCESS
should contain ${res_body} Operation completed successfully
VideoGameDB API
-------------------------------
Pre-Requisite: Install Gradle on Windows
Graddle Download link: https://gradle.org/releases/
VideoGameDB API Download Link:
https://github.com/james-willett/VideoGameDB
How to run application using gradle...
E:\VideoGameDB-master\gradlew bootRun
url: http://localhost:8080/swagger-ui/index.html
Video Game Database application with API endpoints that support JSON and XML
Script
-------------------------------------
*** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${base_url} http://localhost:8080
*** Test Cases ***
TC1:Returns all the videos games(GET)
create session mysession ${base_url}
${response}= get request mysession /app/videogames
log to console ${response.status_code}
log to console ${response.content}
#Validation
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 200
TC2:Add a new video game (POST)
create session mysession ${base_url}
${body}= create dictionary id=100 name=Spider-Man releaseDate=2019-09-20T08:55:58.510Z reviewScore=5 category=Adventure rating=Universal
${header}= create dictionary Content-Type=application/json
${response}= post request mysession /app/videogames data=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
#Validations
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 200
${res_body}= convert to string ${response.content}
should contain ${res_body} Record Added Successfully
TC3: Returns the details of a single game by ID(GET)
create session mysession ${base_url}
${response}= get request mysession /app/videogames/100
log to console ${response.status_code}
log to console ${response.content}
#Validation
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 200
${res_body}= convert to string ${response.content}
should contain ${res_body} Spider-Man #Name of game
TC4:Update an existing video game by specifying a new body (PUT)
create session mysession ${base_url}
${body}= create dictionary id=100 name=Pacman releaseDate=2019-09-20T08:55:58.510Z reviewScore=5 category=Adventure rating=Universal
${header}= create dictionary Content-Type=application/json
${response}= put request mysession /app/videogames/100 data=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
#Validations
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 200
${res_body}= convert to string ${response.content}
should contain ${res_body} Pacman
TC5: Deletes a video game by ID (DELETE)
create session mysession ${base_url}
${response}= delete request mysession /app/videogames/100
#Validations
${status_code}= convert to string ${response.status_code}
should be equal ${status_code} 200
${res_body}= convert to string ${response.content}
should contain ${res_body} Record Deleted Successfully
*** Settings ***
Library JSONLibrary
Library os
Library Collections
*** Test Cases ***
Testcase1:
${json_obj}= load json from file C:/SeleniumPractice/jsondata/jsondata.json
${name_value}= get value from json ${json_obj} $.firstName
should be equal ${name_value[0]} John
${street_value}= get value from json ${json_obj} $.address.streetAddress
should be equal ${street_value[0]} 21 2nd Street
${faxnumb_value}= get value from json ${json_obj} $.phoneNumber[1].number
log to console ${faxnumb_value[0]}
should be equal ${faxnumb_value[0]} 646 555-4567
Learn to validate xml and excel data using Robot Framework by verifying single element values, counting elements, checking attributes, and extracting changed element values.
Validate xml content from an api using robot framework by sending a get request, converting responses to string, parsing elements, and verifying single and multiple values.
*** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${base_url} http://jsonplaceholder.typicode.com
*** Test Cases ***
TestHeaders
create session mysession ${base_url}
${response}= get request mysession /photos
log to console ${response.headers}
${contentTypeValue}= get from dictionary ${response.headers} Content-Type
should be equal ${contentTypeValue} application/json; charset=utf-8
${contentEncodingValue}= get from dictionary ${response.headers} Content-Encoding
should be equal ${contentEncodingValue} gzip
TestCookies
create session mysession ${base_url}
${response}= get request mysession /photos
log to console ${response.cookies} # Displays all the cookies
${cookieValue}= get from dictionary ${response.cookies} __cfduid
log to console ${cookieValue} # Displayed specific Cookie value
*** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${base_url} http://restapi.demoqa.com
*** Test Cases ***
BasicAuthTest
${auth}= create list ToolsQA TestPassword
create Session mysession ${base_url} auth=${auth}
${response}= get Request mysession /authentication/CheckForAuthentication/
log to console ${response.content}
should Be Equal As Strings ${response.status_code} 200
*** Settings ***
Library RequestsLibrary
Library Collections
Library XML
Library OperatingSystem
*** Variables ***
${base_url} https://certtransaction.elementexpress.com
${bearerToken} "Bearer E4F284BFADA11D01A52508ED7B92FFD7EE0905659F5DED06A4B73FC7739B48A287648801"
*** Test Cases ***
BearerAuthTest
create session mysession ${base_url}
${headers} create Dictionary Authorization=${bearerToken} Content-Type=text/xml
${req_body}= get file C:/SeleniumPractice/xmldata/PostData.txt
log to console ${req_body}
${response}= post Request mysession / data=${req_body} headers=${headers}
log to console ${response.status_code}
log to console ${response.content}
*** Settings ***
Library RequestsLibrary
Library Collections
Library XML
Library OperatingSystem
*** Variables ***
${base_url} https://certtransaction.elementexpress.com
${bearerToken} "Bearer E4F284BFADA11D01A52508ED7B92FFD7EE0905659F5DED06A4B73FC7739B48A287648801"
*** Test Cases ***
BearerAuthTest
create session mysession ${base_url}
${headers} create Dictionary Authorization=${bearerToken} Content-Type=text/xml
${req_body}= get file C:/SeleniumPractice/xmldata/PostData.txt
log to console ${req_body}
${response}= post Request mysession / data=${req_body} headers=${headers}
log to console ${response.status_code}
log to console ${response.content}
Course Introduction: Mastering Robot Framework for Test Automation
Welcome to our comprehensive course on Robot Framework, a versatile test automation framework designed for acceptance testing and acceptance test-driven development (ATDD). Robot Framework is renowned for its user-friendly tabular test data syntax and embraces a keyword-driven testing approach, making it accessible for both beginners and experienced testers.
Course Contents:
1) Robot Framework Environment Setup
Step-by-step guide to setting up the Robot Framework environment for efficient test automation
2) HTTP Requests
Exploring the basics of HTTP requests and their various methods:
GET
POST
PUT
DELETE
3) Video Game API - End to End API Testing
Practical application of Robot Framework in testing a Video Game API end-to-end
4) Validating JSON Files
Understanding and implementing validation techniques for JSON files
5) Validating XML Files
Exploring methods to validate XML files using Robot Framework
6) Validating Complex XML & JSON Files
Advanced techniques for validating intricate XML and JSON files
7) Types of Authentications
In-depth coverage of authentication methods within Robot Framework
8) Google Maps API - End to End API Testing
Real-world example of end-to-end API testing using the Google Maps API
Robot Framework's extensibility is a key feature, and this course will guide you in harnessing its full potential:
Learn to extend testing capabilities through test libraries implemented in either Python or Java.
Discover how to create new higher-level keywords from existing ones, using the same syntax as for creating test cases.