Hi. Thanks for your reply.
function runTest() {
const cypress = require('cypress');
// Note: This seems to need v37.4 of nw.js.
// Maybe a few earlier but v35 crashed.
// Throws: Error [ERR_UNKNOWN_STDIN_TYPE]: Unknown stdin file type
// in v35.
// It seems this is an error cause by NW.js stdin being disabled.
// https://github.com/nwjs/nw.js/issues/586
// But, seems to work in v37.4
cypress.run({
// The issue is here:
// We need to be able to run the nw.js chromium browser in nw.js
// inorder to test your app that is written for that environment.
// The default browser used by Cyress is the built-in Electron browser.
// You can also specify 'chrome' which launches a window/tab in the normal Chrome browser app.
// Both these options would probably work if you did not use node.js in your app. But if that
// is the case then there is no point running Cypress within nw.js. You could just run it as
// the normal standalone way it was intended.
// I guess it *could* be possible to customise Cypress to add the option to run the nw.js 'browser'
// but I have no idea how to go about that, even if it is possible.
browser: 'electron',
env : {
// Pass the nw browser window so the tests
// can access the global scope and hence your app
nwWin: nw.Window.get()
},
// The spec to run. Yes, it does run but even with the env set it to the nw window
// it is *executing the test* in an Electron browser, not a nw.js browser. Of course.
spec: './cypress/integration/nwjs_spec_1.js'
})
.then((results) => {
// We get here so output the result
console.log("My Results=" + results.runs[0].tests[0].state)
console.table(results.runs[0].tests[0])
})
.catch((err) => {
console.error("My Error",err)
})
}