automation - Cypress - supportFile 中的 before() 钩子在每个规范之前运行
问题描述
根据文档,这个钩子应该只在每个套件运行时执行一次(每次cypress run
调用一次),但这似乎在每个规范之前执行。这是一个错误吗?还是我做错了什么?
Cypress.Cookies.defaults({
preserve: ['cookie']
})
before(() => {
cy.log("Should only run once")
})
});
解决方案
该before()
钩子每个规范文件运行一次,而不是每个cypress run
.
看起来您需要Before Run API
on('before:run', (details) => {
/* ... */
})
推荐阅读
- javascript - 我正在尝试使用删除按钮构建一个购物车,该按钮在每次单击时删除该项目
- ansible - 在 Ansible 剧本中自动包含环境变量
- html - target="_blank" 在 Firefox 的新标签中打开,但不是 chrome (Svelte)
- pine-script - Pine Script 根据新的最高交易量在低/高价上绘制水平线
- selenium - 无法在 Katalon Studio 上滑动和滚动到文本
- kql - Kusto:如何汇总计算数据
- c# - 我很难找出如何在 WPF 中创建样式资源
- python - 对加速度计和陀螺仪的时间序列数据进行下采样
- xts - period.apply 函数错误,同时在自定义函数中将一个 XTS 与另一个 XTS 子集
- javascript - 如果我选择代码选项,如何打印代码名称