Reputation: 15488
I'm writing some automated tests using node.js and Cypress, and since I have a lot of them I want to group them split them off onto their own files. I have started doing this, eg:
//myscripts/prodPageTests.js
const { exec } = require('child_process');
let command = "npx cypress run --headless --browser chrome --spec './cypress/e2e/LoremProdPage.feature'";
// Other tests to come.
// Probably in some kind of loop with args.
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${error}`);
return;
}
console.log(`Output:\n${stdout}`);
if (stderr) {
console.error(`Error Output:\n${stderr}`);
}
});
This works, but after it runs I also get the warning:
Error Output:
DevTools listening on ws://127.ip.address/devtools/browser/<some hash>
2025-02-19 10:18:07.287 Cypress[18578:4259699] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSup
Which I understand to be something to do with the Mac Sonoma OS.
I'm just curious: is there a work around for this with node.js?
Upvotes: 1
Views: 57
Reputation: 4043
You can filter out the lines in the stderr
output that contain the warning message
const { exec } = require('child_process');
const command = 'npx cypress run --headless --browser chrome --spec "./cypress/e2e/LoremProdPage.feature"';
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${error}`);
return;
}
// Split stderr into lines and filter out any that contain the warning message.
const filteredStderr = stderr
.split('\n')
.filter(line => !line.includes('WARNING: Secure coding is not enabled for restorable state'))
.join('\n');
console.log(`Output:\n${stdout}`);
if (filteredStderr) {
console.error(`Filtered Error Output:\n${filteredStderr}`);
}
});
Upvotes: 1
Reputation: 10018
I would do it using the Module API
You can require Cypress as a node module from your application under test and run Cypress via Node.js.
This means you don't need the execa()
layer to execute Cypress.
All of your CLI options are available as options in this mode, for example
//myscripts/prodPageTests.js
const cypress = require('cypress')
cypress.run({
browser: 'chrome',
headless: true,
spec: './cypress/e2e/LoremProdPage.feature'
})
.then((results) => {
console.log(`Results:\n${results}`);
})
.catch((err) => {
console.error(`Error executing command: ${error}`);
})
Upvotes: 1