I am trying to integrate cypress tests into my app, but in order to perform e2e tests I need to interact with metamask. I am using the cypress-metamask plugin (https://www.npmjs.com/package/cypress-metamask), but cannot get it to work.
Running the tests returns the following error:
cy.task('setupMetamask') failed with the following error:
request to http://localhost:9222/json/version failed, reason: connect ECONNREFUSED 127.0.0.1:9222
This is the test:
describe('NFTicket', () => {
beforeEach(() => {
cy.setupMetamask();
cy.changeMetamaskNetwork('localhost')
cy.visit('/')
});
it('is expected to display a sussess message', () => {
cy.get('[data-cy=title]').should('contain.text', 'MetaMask Detected')
});
});
This is how my cypress/plugins/index.js is configured:
module.exports = (on, config) => {
require('cypress-metamask/plugins')(on);
on('before:browser:launch', (browser = { isHeaded: true }, arguments_) => {
if (browser.name === 'chrome') {
arguments_.args.push('--remote-debugging-port=9222')
arguments_.args.push('--disable-background-timer-throttling');
arguments_.args.push('--disable-backgrounding-occluded-windows');
arguments_.args.push('--disable-renderer-backgrounding');
}
})
}
CodePudding user response:
Please ensure the server is started,
You can try this 127.0.0.1 localhost
in /etc/hosts file.
CodePudding user response:
In our project, we also encountered a problem using this library. I don't remember exactly what it was, but in general we couldn't solve it and then we changed it to @synthetixio/synpress. In our project with this library e2e tests run perfectly.
npm i @synthetixio/synpress
yarn add @synthetixio/synpress
A list of useful commands for working with metamask can be found here.