English 中文(简体)
Cypress - Get and Post
  • 时间:2024-03-24 10:01:20

Cypress - Get and Post

Previous Page Next Page  

“Get”和“邮政”方法是“应用规划接口”测试的一部分,可由“Cypress”进行。

Get Method

为了开展“公平行动”,我们将以cy.request()提出“吉大港”申请,并将“Get”和“URL”作为这种方法的参数。

如果请求得到接受和正确处理,地位法就反映了这一点。 法典第200(means ok)和201(means 创建)。

Implementation of Get

The implementation of Get methods in Cypress is 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 )
      });
   })
})

产出如下:

Get Method

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

下面是“旋风”中采用邮政方法。


describe("Post Method", function(){
   it("Scenario 3", function(){
      cy.request( https://jsonplaceholder.cypress.io/users?_pmit=1 )
      .its( body.0 ) // yields the first element of the returned pst
      // make a new post on behalf of the user
      cy.request( POST ,  https://jsonplaceholder.cypress.io/posts , {
         title:  Cypress ,
         body:  Automation Tool ,
      })
   })
});

产出如下:

Post Method Advertisements