add network interception to cypress test

This commit is contained in:
mahula 2023-05-26 12:53:18 +02:00
parent 18288efa1b
commit 0e046e222c

View File

@ -2,6 +2,12 @@ import { Given } from "cypress-cucumber-preprocessor/steps";
import 'cypress-network-idle';
Given('somebody reported the following posts:', table => {
cy.intercept({
method: 'POST',
url: '/',
hostname: 'localhost',
}).as('postToLocalhoast')
table.hashes().forEach(({ submitterEmail, resourceId, reasonCategory, reasonDescription }) => {
const submitter = {
email: submitterEmail,
@ -19,6 +25,19 @@ Given('somebody reported the following posts:', table => {
reasonCategory,
reasonDescription
})
cy.wait(['@postToLocalhoast']).then((interception) => {
cy.wrap(interception.response.statusCode).should('eq', 200)
})
cy.wait(['@postToLocalhoast']).then((interception) => {
cy.wrap(interception.response.statusCode).should('eq', 200)
})
cy.wait(['@postToLocalhoast']).then((interception) => {
console.log('Cypress interception:', interception)
cy.wrap(interception.response.statusCode).should('eq', 200)
cy.wrap(interception.response.body)
.should('have.nested.property', 'data.fileReport.reportId')
})
console.log('Cypress waited for fileReport request')
cy.waitForNetworkIdle(2000)
})
})