cy.request doesn't allowing me to go to next UI test cases

余生长醉 提交于 2020-07-10 07:49:09

问题


Trying to integrate both UI & API test cases

Created two files:

  1. API test --> DO Login and writing token & saving it to fixture file

  2. Spec test -->Do REAL Login by using username and password and once test case pass then in next test first get the response by using cy.request using token which saved by step1. Based on response keys search the data in search bar

API Test File:

it("Login Request API",function(){

        cy.request({
            method:"POST",
            url: POST URL,
            headers:{
             "content-type" : "application/json"
            },
            body : {
             "email": USER NAME,
             "password": PASSWORD
            },
            log: true
        }).then((response) => {
             // Parse JSON the body.
             expect(response.status).to.equal(200)
             let resbody = JSON.parse(JSON.stringify(response.body));
            cy.writeFile("File Path to store response",resbody)
         })
    });

Cypress version: 3.8.3

Once above test is executed then it redirect to first test . Not going to further tests


回答1:


For Cypress Version 3.8.3: You may need to check the path of the new file you are trying to create. it is by default within the 'fixture' folder.

cy.request({
    method:"POST",
    url: POST URL,
    headers: {
      "content-type" : "application/json"
    },
    body : {
      "email": USER NAME,
      "password": PASSWORD
    },
    log: true
}).then((response) => {
    // Parse JSON the body.
    expect(response.status).to.equal(200);
    cy.writeFile("<path>/api.json", response.body); // <path> is with respect to cypress/fixture folder
});

From my test:



来源:https://stackoverflow.com/questions/62214550/cy-request-doesnt-allowing-me-to-go-to-next-ui-test-cases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!