cypress - 如何将变量从 .within() 传递给 .then()?
问题描述
我想foo
从.within()
到.then()
。我希望以下代码可以工作,但事实并非如此。foo
最终成为一个 jQuery 元素。有没有办法做到这一点?
cy.get('.some-selector')
.within(() => {
const foo = 'Some value'
return foo
})
.then((foo) => {
console.log(foo)
})
解决方案
赛普拉斯文档谈论后空翻,这是由命令回调设置外部变量的地方。
警告不要这样做,但在这种情况下会起作用,因为设置和使用都在顺序步骤中。
let foo
cy.get('.some-selector')
.within(() => {
foo = 'Some value'
})
.then(() => {
expect(foo).to.eq('Some value')
})
推荐阅读
- amazon-web-services - 如何一次性为多个实例附加 IAM 角色
- php - Facebook Messenger结构化消息php不显示php
- javascript - 向 Bootstrap 响应式模态图像库添加标题
- python - 函数中的 None 是什么意思/可选字段
- arrays - 通过一个通用函数更新不同的数组
- php - 身份验证功能不起作用
- xsl-fo - fo:table-cell AntennaHouse 中的块容器
- r - 仅根据 r 中的多列选择重复项
- php - 何时使用 Doctrine 或 Symfony Cache?
- matlab - 由于索引超出矩阵维度,MATLAB 绘图失败