Cypress 和 cypress-metamask 插件问题(连接 ECONNREFUSED 127.0.0.1:9222)
我正在尝试将 cypress 测试集成到我的应用程序中,但为了执行 e2e 测试,我需要与 metamask 交互。我正在使用 cypress-metamask 插件 (https://www.npmjs.com/package/cypress -metamask),但无法让它工作。
运行测试会返回以下错误:
cy.task('setupMetamask') 失败并出现以下错误:
<块引用>请求http://localhost:9222/json/version失败,原因:连接ECONNREFUSED 127.0.0.1:9222
这是测试:
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')
});
});
这就是我的 cypress/plugins/index.js 的配置方式:
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');
}
})
}
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');
}
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请确保服务器已启动,
您可以在 /etc/hosts 文件中尝试这个
127.0.0.1 localhost
。Please ensure the server is started,
You can try this
127.0.0.1 localhost
in /etc/hosts file.在我们的项目中,我们使用这个库也遇到了问题。我不记得具体是什么,但总的来说我们无法解决它,然后我们将其更改为 @synthetixio/synpress。在我们的项目中,使用这个库的 e2e 测试运行得很好。
可以在此处找到使用元掩码的有用命令列表< /a>.
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.
A list of useful commands for working with metamask can be found here.