return cy.request('https://webiste.com/config.json').then( (appConfig) => {
// save to Cypress.config
});
The above code threw this error:
The function exported by the plugins file threw an error.
We invoked the function exported by 'C:\projects\nfe-credit-flow\cypress\plugins\index.js', but it threw an error.
The following error was thrown:
ReferenceError: cy is not defined at Promise.then (C:\projects\nfe-credit-flow\cypress\plugins\index.js:74:4) at tryCatcher (C:\projects\nfe-credit-flow\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (C:\projects\nfe-credit-flow\node_modules\bluebird\js\release\promise.js:512:31) at Promise._settlePromise (C:\projects\nfe-credit-flow\node_modules\bluebird\js\release\promise.js:569:18) at Promise._settlePromise0 (C:\projects\nfe-credit-flow\node_modules\bluebird\js\release\promise.js:614:10) at Promise._settlePromises (C:\projects\nfe-credit-flow\node_modules\bluebird\js\release\promise.js:693:18)
Plugins run a node.js task while cypress runs in the browser. You should use an npm package such as request
to do this. The config
variable is accessible from the plugin e.g. module.exports = (on, config) => { ...
Since cypress uses request, it's a good idea to have the same dependency rather than a new one like axios. So just npm i request
than:
const request = require('request');
request('https://webiste.com/config.json').then( (appConfig) => {
config.whatever = appConfig.whatever
});
Or you could use a merge
function (e.g. from loadsh) to override config
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With