gpt4 book ai didi

Cypress :父包运行其 Cypress /集成测试及其依赖项 Cypress /集成测试

转载 作者:行者123 更新时间:2023-12-05 04:35:28 25 4
gpt4 key购买 nike

问题:Cypress npm 父项目能否导入/添加/运行其依赖项 Cypress npm 项目的 Cypress 测试?

问题的答案是这个链接有效,将一个整体的 Cypress 测试包分解成多个 Cypress 测试包并使用 Module API .但是,我不得不重新考虑我的问题。我没有解决的是 npm cypress 包之间存在依赖关系(自定义命令)。

Cypress: Import tests into "./cypress/integration" from multiple npm dependencies?

示例:

  • npm package cy_test_A 依赖于 npm package cy_test_B 自定义命令,
  • npm package cy_test_B 依赖于 npm package cy_test_C 自定义命令。

这些包中的每一个都有用于规范的 cypress 集成和用于自定义命令的 src:

cy_test_***

├── cypress
│ ├── integration
│ │ └── tests
│ └── support
│ └── specs
├── src
│ └── commands

Cypress 集成测试可以从其依赖项中导入吗?当我执行测试运行时,我希望看到一个组合测试,包括 dependencies' cypress tests + parent's cypress test

npm package cy_test_A 依赖于 npm package cy_test_B 中的自定义命令,这些命令用于 cy_test_A Cypress 集成测试。在构建 npm 包 cy_test_B 时,它在提交到 npm 存储库之前有自己的 cypress 集成测试。 我希望 cy_test_A 运行自己的 cypress 集成测试,但 cypress 集成测试其依赖项 cy_test_B 作为好吧。

├── cypress
│ ├── integration
│ │ └── tests_A <<< Dependent on src/commands **cy_test_B**
│ │ └── tests_B <<< Imported cypress/integration/tests from **cy_test_B**
│ └── support
│ └── specs
├── src
│ └── commands
├── node_module
│ └── **cy_test_B**
│ └── ***
│ └── ***

想法?谢谢

最佳答案

不确定是否所有的 t's 都被交叉了,但是索引文件可以用来整理所有自定义命令而无需物理移动它们。

/cypress/support/commands-index.js

require('../../cy_test_A/src/commands')
require('../../cy_test_B/src/commands')

然后将 supportFile 指定为该索引文件。

const cypress = require('cypress')

cypress.open({
reporter: 'junit',
browser: 'chrome',
project: '..',
config: {
supportFile: './cypress-run-other-project/support/commands-index.js',
video: true,
},
env: {
login_url: '/login',
products_url: '/products',
},
})

但是现在,/cy_test_A/cypress/support/index.js 中发生的任何其他事情都将被忽略(例如附加库),所以可能 commands-index. js 需要

require('../../cy_test_A/cypress/support')
require('../../cy_test_B/cypress/support')

你可以检查加载了哪些命令(在规范中)

it('checks that both custom commands have bee loaded', () => {
const commands = Cypress.Commands._commands
expect(commands).to.have.property('checkA') // command from cy_test_A
expect(commands).to.have.property('checkB') // command from cy_test_B
})

关于 Cypress :父包运行其 Cypress /集成测试及其依赖项 Cypress /集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71030863/

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