- Cypress Tutorial
- Cypress - Home
- Cypress - Introduction
- Cypress - Architecture and Environment Setup
- Cypress - Test Runner
- Cypress - Build First Test
- Cypress - Supported Browsers
- Cypress - Basic Commands
- Cypress - Variables
- Cypress - Aliases
- Cypress - Locators
- Cypress - Assertions
- Cypress - Text Verification
- Cypress - Asynchronous Behavior
- Cypress - Working with XHR
- Cypress - jQuery
- Cypress - Checkbox
- Cypress - Tabs
- Cypress - Dropdown
- Cypress - Alerts
- Cypress - Child Windows
- Cypress - Hidden Elements
- Cypress - Frames
- Cypress - Web Tables
- Cypress - Mouse Actions
- Cypress - Cookies
- Cypress - Get and Post
- Cypress - File Upload
- Cypress - Data Driven Testing
- Cypress - Prompt Pop-up Window
- Cypress - Dashboards
- Cypress - Screenshots and Videos
- Cypress - Debugging
- Cypress - Custom Commands
- Cypress - Fixtures
- Cypress - Environment Variables
- Cypress - Hooks
- Cypress - Configuration of JSON File
- Cypress - Reports
- Cypress - Plugins
- Cypress - GitHub
- Cypress Useful Resources
- Cypress - Quick Guide
- Cypress - Useful Resources
- Cypress - Discussion
Cypress - Get and Post
The Get and Post methods are a part of the Application Programming Interface (API) testing, which can be performed by Cypress.
Get Method
To perform a Get operation, we shall make a HTTP request with the cy.request() and pass the method Get and URL as parameters to that method.
The status code reflects, if the request has been accepted and handled correctly. The code 200(means ok) and 201(means created).
Implementation of Get
The implementation of Get method in Cypress is explained below −
describe("Get Method", function(){ it("Scenario 2", function(){ cy.request("GET", "https://jsonplaceholder.cypress.io/comments", { }).then((r) => { expect(r.status).to.eq(200) expect(r).to.have.property('headers') expect(r).to.have.property('duration') }); }) })
Execution Results
The output is as follows −
Post Method
While using the Post method, we are actually sending information. If we have a group of entities, we can append new ones at the end, with the help of Post.
To perform a Post operation, we shall make a HTTP request with the cy.request() and pass the method Post and URL as parameters to that method.
Implementation of Post
Given below is an implementation of Post method in Cypress −
describe("Post Method", function(){ it("Scenario 3", function(){ cy.request('https://jsonplaceholder.cypress.io/users?_limit=1') .its('body.0') // yields the first element of the returned list // make a new post on behalf of the user cy.request('POST', 'https://jsonplaceholder.cypress.io/posts', { title: 'Cypress', body: 'Automation Tool', }) }) });
Execution Results
The output is given below −