保存值并以后在命令链中使用
我正在测试一个拖动方案,想要获得元素位置并在Mousemove中使用该值。我虽然cypress.env()是保存值的一种方法,但它在Mousemove参数中显示为空。如何保存初始数据?
cy.get('.draggable')
.then($el => { Cypress.env('start', $el[0].getBoundingClientRect()) })
.trigger('mousemove', , { pageX: Cypress.env('start').x +20 })
I'm testing a drag scenario, want to get an elements position and use the value in a mousemove. I though that Cypress.env() was a way to save values, but it appears empty in the mousemove parameters. How do I save the initial data?
cy.get('.draggable')
.then($el => { Cypress.env('start', $el[0].getBoundingClientRect()) })
.trigger('mousemove', , { pageX: Cypress.env('start').x +20 })
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
测试命令在运行测试时采用其值,但是命令稍后运行(异步),因此
cypress.env('start')
在排队时尚未定义。您可以添加一个
。然后()
延迟排队命令,它将读取最新值。The test commands take their values as the test is run, but the commands run later (asynchronously), so
Cypress.env('start')
is not yet defined when the mousemove command is queued.You can add a
.then()
to delay queueing that command, and it will read the latest value.