如何从事件处理程序访问当前运行的测试文件的名称?

发布于 2025-02-06 19:18:49 字数 329 浏览 0 评论 0 原文

我需要在每个测试之前运行的事件处理程序中使用当前运行的测试访问文件的名称,以记录有关该测试的一些内容。这样:

Cypress.on('uncaught:exception', (err, runnable) => {
    cy.currentTest; // Doesn't have the test file name, only the names of a context and a spec
    logSomeStuff();
    return false
});

有可能吗?

I need to access the name of the file with the currently running test within an event handler that runs before every test to log some stuff about that test. Like this:

Cypress.on('uncaught:exception', (err, runnable) => {
    cy.currentTest; // Doesn't have the test file name, only the names of a context and a spec
    logSomeStuff();
    return false
});

Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

贱贱哒 2025-02-13 19:18:49

您可以为此使用 cypress.spec 。您可以从

it('log spec info', () => {
  console.log(Cypress.spec)
  // {
  //   name: 'filter.cy.js',
  //   relative: 'cypress/e2e/filter.cy.js',
  //   absolute: '/Users/janelane/Dev/web-app/cypress/e2e/filter.cy.js',
  // }
})

You can use the Cypress.spec for this. You can read about it from here

it('log spec info', () => {
  console.log(Cypress.spec)
  // {
  //   name: 'filter.cy.js',
  //   relative: 'cypress/e2e/filter.cy.js',
  //   absolute: '/Users/janelane/Dev/web-app/cypress/e2e/filter.cy.js',
  // }
})
﹂绝世的画 2025-02-13 19:18:49

运行参数为您提供以下信息

title: 'my-test-title',
duration: 75,
state: 'failed',
invocationDetails: {
  relativeFile: 'path-to-test'
},
parent: {
  title: 'my-describe-title',
  tests: [other tests in suite]
}

The runnable parameter gives you the following information

title: 'my-test-title',
duration: 75,
state: 'failed',
invocationDetails: {
  relativeFile: 'path-to-test'
},
parent: {
  title: 'my-describe-title',
  tests: [other tests in suite]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文