add network interception to cypress test

This commit is contained in:
mahula 2023-05-26 12:53:18 +02:00
parent 0e046e222c
commit 7528d32dfc
2 changed files with 4 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"projectId": "qa7fe2",
"defaultCommandTimeout": 180000,
"defaultCommandTimeout": 5000,
"pageLoadTimeout": 180000,
"ignoreTestFiles": "*.js",
"chromeWebSecurity": false,

View File

@ -2,10 +2,12 @@ import { Given } from "cypress-cucumber-preprocessor/steps";
import 'cypress-network-idle';
Given('somebody reported the following posts:', table => {
const reportIdRegex = /^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/
cy.intercept({
method: 'POST',
url: '/',
hostname: 'localhost',
port: 4000,
}).as('postToLocalhoast')
table.hashes().forEach(({ submitterEmail, resourceId, reasonCategory, reasonDescription }) => {
@ -36,6 +38,7 @@ Given('somebody reported the following posts:', table => {
cy.wrap(interception.response.statusCode).should('eq', 200)
cy.wrap(interception.response.body)
.should('have.nested.property', 'data.fileReport.reportId')
.and('match', reportIdRegex)
})
console.log('Cypress waited for fileReport request')
cy.waitForNetworkIdle(2000)