You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While saving responses in a request handler, such as cy.intercept(..., REQUEST_HANDLER) I get a new error that says I can't execute 'writeFile' from outside a support file. The function defined is in a support file. This used to work.
This use to work, and I don't recall when I started seeing this.
Test code to reproduce
The code example is in the stack overflow answer pasted above. Here it is again.
Note: even when moving the cy.now call to the spec file, it throws the exact same error, complaining that the cy.writeFile call doesn't exist in a spec or support file.
describe('fixture creation', () => {
it('should save fixtures of every endpoint that matches a url', () => {
cy.login()
cy.visit('/ubmc/system/pci-topology')
cy.intercept('https://covfefe/redfish/v1/Chassis/Asrock/PCIeDevices/**',
req => {
req.continue((res) => {
cy.now('writeFile',
`cypress/fixtures/${ req.url.replace('https://covfefe/', '') }.json`,
res.body)
})
})
})
it('should produce results from the fixtures directory', () => {
cy.intercept('**redfish/v1/Chassis/Asrock/PCIeDevices/**', req => {
req.reply({
fixture: `${ req.url.replace('https://covfefe/', '') }.json`
})
})
// @ts-ignore
cy.login()
cy.visit('/ubmc/system/pci-topology')
})
})
Cypress Version
v13.6.3
Node version
v18.12.0
Operating System
linux
Debug Logs
npm -v 8.19.2; node -v v18.12.0
uname -a; lsb_release -a
Linux beastmode 6.8.0-45-generic #45~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 11 15:25:05 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
(uncaught exception)CypressError: cy.writeFile() must only be invoked from the spec file or support file.
(xhr)GET https://i-tyan/redfish/v1/Managers/SDS-7471481/LogServices/Log/Entries
managersPath
(xhr)GET https://i-tyan/redfish/v1/Systems/Asrock
systemsPath
CypressError
The following error originated from your application code, not from Cypress. It was caused by an unhandled promise rejection.
>cy.writeFile() must only be invoked from the spec file or support file.
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the uncaught:exception event.Learn more
cypress/e2e/wait.cy.ts:2:6
1 |export const wait = (ms: number = 30000) => {
> 2 | cy.wait('@sessionService', {timeout: ms})
| ^
Other
If there were some way to write a fixture file for every response in a normal fashion, please let me know. I feel like this hacky solution is being guarded against and I would like to understand what changed.
Thank you!
The text was updated successfully, but these errors were encountered:
Current behavior
While saving responses in a request handler, such as
cy.intercept(..., REQUEST_HANDLER)
I get a new error that says I can't execute 'writeFile' from outside a support file. The function defined is in a support file. This used to work.Desired behavior
https://stackoverflow.com/questions/72664114/automatically-save-cypress-fixture-from-api-response
This use to work, and I don't recall when I started seeing this.
Test code to reproduce
The code example is in the stack overflow answer pasted above. Here it is again.
Note: even when moving the
cy.now
call to the spec file, it throws the exact same error, complaining that the cy.writeFile call doesn't exist in a spec or support file.Cypress Version
v13.6.3
Node version
v18.12.0
Operating System
linux
Debug Logs
Other
If there were some way to write a fixture file for every response in a normal fashion, please let me know. I feel like this hacky solution is being guarded against and I would like to understand what changed.
Thank you!
The text was updated successfully, but these errors were encountered: