user
09/03/2022, 12:16 PMuser
09/03/2022, 12:17 PMuser
09/03/2022, 12:17 PMstale-optician-85950
09/03/2022, 5:15 PMcypress.config.ts
file) and integration (now called e2e) folders.average-caravan-18738
09/04/2022, 9:46 AMaverage-caravan-18738
09/04/2022, 9:48 AMaverage-caravan-18738
09/04/2022, 9:49 AMaverage-caravan-18738
09/04/2022, 10:21 AMaverage-caravan-18738
09/04/2022, 10:33 AMred-dawn-5427
09/04/2022, 12:19 PMstraight-student-54807
09/05/2022, 2:04 AM.all
to an intercept alias returns an array of all calls to that alias. Source: GitHub issue comment: https://github.com/cypress-io/cypress/issues/477#:~:text=There%20actually%20is%20an%20undocumented%20way%20to%20check%20the%20number%20of%20times%20an%20XHR%20was%20responsed%20to%20using%20.all%20on%20the%20alias..
In cypress/support/commands.ts
ts
// Intercepts all requests made to your API
Cypress.Commands.add("trackMyApiRequests", () => {
cy.intercept(`${Cypress.env("API_URL")}/**`).as("myApi");
});
// test fails if any intercepted API call has an error code > 399
Cypress.Commands.add("stopTestSuiteIfApiError", () => {
cy.get("@myApi.all").each((req) => {
const cutoff = 399;
const status = req?.response?.statusCode;
if (status && status > cutoff) {
expect(req)
.to.have.nested.property("response.statusCode")
.below(
cutoff,
`URL:${req.request.url}\nMETHOD:${req.request.method}\nAPI ERROR CODE`
);
}
});
});
In your test spec file, add trackMyApiRequests
to the beforeEach()
hook, and stopTestSuiteIfApiError
to the afterEach()
hook.
ts
describe("Test spec", () => {
beforeEach(() => {
cy.trackMyApiRequests(); // add here
});
afterEach(() => {
cy.stopTestSuiteIfApiError(); // add here
});
it("some test", () => {
//Cypress test code
});
});
I think you could try calling cy.stopTestSuiteIfApiError()
at the end of each individual test if you want only that specific test. to fail and not skip the remaining tests in the spec.
Hope this helps!kind-pizza-45261
09/05/2022, 7:40 AMfresh-insurance-69051
09/05/2022, 11:44 AMbusy-dusk-58025
09/05/2022, 12:44 PMechoing-stone-88523
09/05/2022, 4:29 PMcypress run --e2e --config baseUrl=http://localhost:3037
The errors I get are:
[2455:0905/161349.759231:ERROR:address_tracker_linux.cc(215)] Could not bind NETLINK socket: Permission denied
[2617:0905/161349.818642:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
[2770:0905/161351.803800:ERROR:file_path_watcher_inotify.cc(86)] Failed to read /proc/sys/fs/inotify/max_user_watches
[2770:0905/161351.804524:ERROR:address_tracker_linux.cc(215)] Could not bind NETLINK socket: Permission denied (13)
Error [ERR_LOADER_CHAIN_INCOMPLETE]: "file:///opt/buildhome/.cache/Cypress/10.7.0/Cypress/resources/app/node_modules/ts-node/esm/transpile-only.mjs 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include `shortCircuit: true` in the hook's return.
at new NodeError (node:internal/errors:387:5)
at ESMLoader.resolve (node:internal/modules/esm/loader:852:13)
at async ESMLoader.getModuleJob (node:internal/modules/esm/loader:431:7)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12) {
code: 'ERR_LOADER_CHAIN_INCOMPLETE'
}
echoing-stone-88523
09/05/2022, 4:33 PMbusy-dusk-58025
09/06/2022, 7:06 AMnpm install cypress
damp-memory-26821
09/06/2022, 7:06 AMcolossal-farmer-50435
09/06/2022, 7:54 AMdamp-memory-26821
09/06/2022, 9:26 AMbored-actor-82502
09/06/2022, 9:49 AMsticky-potato-84128
09/06/2022, 11:54 AMfuture-fireman-94379
09/06/2022, 12:50 PMProperty 'request' does not exist on type 'CypressNpmApi'
. for me its showing only 4 options (cli, defineConfig, open and run)damp-memory-26821
09/06/2022, 1:19 PMprehistoric-restaurant-72560
09/06/2022, 1:22 PMprehistoric-restaurant-72560
09/06/2022, 1:24 PMclever-father-23857
09/06/2022, 3:49 PMorange-sandwich-10738
09/06/2022, 7:01 PMglamorous-lighter-30340
09/06/2022, 7:20 PM