-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After upgrading to latest Cypress version 13.6.4, we are getting "cy.readFile() must only be invoked from the spec file or support file." #28915
Comments
Could you include the code and explanation around which file has the addCommand code and how it's included in the support file? |
@jennifer-shehane Thanks for the response and here is the detailed explanation: we are referring to a json in before all hook class to set report custom data (like platform, URL, browser) Custom Command written in cypress/support/command.ts Cypress.Commands.add('exportReportMetaData', () => {
cy.readFile('cypress/reporter/reportMetaData.json', { log: false }).then((obj) => {
if (obj['baseUrl'] == "") {
const triggeredURL = String(Cypress.config('baseUrl'));
let triggeredEnvironment, browserName, platformName;
(triggeredURL.includes('dvl')) ? triggeredEnvironment = 'DVL' :
(triggeredURL.includes('www')) ? triggeredEnvironment = 'PROD' :
triggeredEnvironment = 'UNDEFINED ENVIRONMENT';
(Cypress.browser.family == 'chromium') ? browserName = 'Chrome' : browserName = Cypress.browser.family;
(Cypress.platform == 'win32') ? platformName = 'Windows' :
(Cypress.platform == 'linux') ? platformName = 'Linux' :
(Cypress.platform == 'darwin') ? platformName = 'OSX' :
platformName = Cypress.platform;
const jsonObj = {
'baseUrl': triggeredURL,
'environment': triggeredEnvironment,
'browserName': browserName,
'browserVersion': Cypress.browser.version,
'platform': platformName,
'arch': Cypress.arch,
'device': obj['device'],
'isMobile': obj['isMobile']
};
cy.writeFile('cypress/reporter/reportMetaData.json', jsonObj, { log: false });
};
});
}); Before class written in cypress/support/hook.ts and custom command is imported here import './commands';
before(function() {
cy.exportReportMetaData();
}); Hook path is described in the cypress.config.ts export default defineConfig({
e2e: {
.............
supportFile: "cypress/support/hooks.ts",
.........
},
}); |
@jennifer-shehane Any updates on this? Its severely impacting our execution. Note: Its happening in the latest Cypress version(13.6.6) as well |
Does the error go away if you move this customCommand directly into the support file or the test file? Unfortunately we don't have time to prioritize this work right now, so trying to find a workaround for you. |
We ran into the same problem @sadhishsk So maybe you should check your e2e.ts if there's something which escapes the spec context. We're currently running on Cypress 13.7.3, node version 20.12.2 |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Current behavior
We are getting this error "Timed out retrying after 60000ms: cy.readFile() must only be invoked from the spec file or support file. Because this error occurred during a before all hook we are skipping all of the remaining tests." while reading a config document in the before all hook class. This issue is happening only on Chromium browsers and working fine in Electron.
This was working fine for all these days and suddenly started to happen now.
Note: this function(cy.readfile) written in custom commands and we are importing and using in the before all hook class
Desired behavior
We should able to read the file written in custom commands and can be used in before all hook class
Test code to reproduce
Custom Command:
Before hook class:
Cypress Version
13.6.4
Node version
v20.11.0
Operating System
Windows 10 Enterprise
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: