Apu*_*uig 13
是的。
您可以geolocation.getCurrentPosition()从窗口对象中存根该函数。
cy.visit('/test', {
onBeforeLoad (win) {
// e.g., force Barcelona geolocation
const latitude = 41.38879;
const longitude = 2.15899;
cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsFake((cb) => {
return cb({ coords: { latitude, longitude } });
});
},
});
Run Code Online (Sandbox Code Playgroud)
事实上,GitHub 上有一个帖子讨论了 Cypress 的这个(所需的)功能。
我已经使用 Cypress v4.10.0 发布了适合我的解决方案,请随意改进代码。
| 归档时间: |
|
| 查看次数: |
4367 次 |
| 最近记录: |