问题
Trying to integrate both UI & API test cases
Created two files:
API test --> DO Login and writing token & saving it to fixture file
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