Cypress 和 cypress-metamask 插件问题(连接 ECONNREFUSED 127.0.0.1:9222)

发布于 2025-01-11 18:58:57 字数 1306 浏览 0 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你搞怪i 2025-01-18 18:58:57

请确保服务器已启动,
您可以在 /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.

忆依然 2025-01-18 18:58:57

在我们的项目中,我们使用这个库也遇到了问题。我不记得具体是什么,但总的来说我们无法解决它,然后我们将其更改为 @synthetixio/synpress。在我们的项目中,使用这个库的 e2e 测试运行得很好。

npm i @synthetixio/synpress

yarn add @synthetixio/synpress

可以在此处找到使用元掩码的有用命令列表< /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.

npm i @synthetixio/synpress

yarn add @synthetixio/synpress

A list of useful commands for working with metamask can be found here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文