gpt4 book ai didi

mocha.js - 如何跨各种文件共享 Cypress.io 中的 describe() block ,类似于 Mocha 的 'Shared Behaviour' 设施

转载 作者:行者123 更新时间:2023-12-02 02:44:37 27 4
gpt4 key购买 nike

我正在开发一个 Web 测试自动化框架,并希望在 describe() 中提供一些功能。一棵柏树 ..spec.js 文件,通过另一个柏树中的另一个方法存在 ..spec.js 文件?

欢迎阅读 共享行为 Mocha 提供的设施:
https://github.com/mochajs/mocha/wiki/Shared-Behaviours
enter image description here
enter image description here

我试过了,但它不起作用。
1. 是否有可能实现类似于 Mocha 共享步骤(如上所述)的东西?
2. 或者有没有类似Cucumber-ruby/Pico-container的世界目的?

好心提醒。

enter image description here

最佳答案

您可以使用自定义命令在多个文件上重复使用步骤。这可以通过以下步骤完成。

  • cypress/support/commands.js 中创建自定义命令使用您要在多个文件中使用的步骤。您可以使用以下语法:

  • Cypress.Commands.add('customCommand', function() {
    cy.get('object')
    .clear()
    .type('something')
    // do other steps
    })
  • 创建自定义命令后,您可以通过以下语法在测试脚本中使用它:

  • describe('Description of the test', function () {
    it('first scenario of the test', function () {
    cy.customCommand()
    })
    })

    结论:要在多个测试文件中共享步骤,您需要将共享步骤放在 commands.js 中,而不是放在测试文件中。

    关于mocha.js - 如何跨各种文件共享 Cypress.io 中的 describe() block ,类似于 Mocha 的 'Shared Behaviour' 设施,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56259458/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com