如何在Cypress测试中检查Openlayers地图上的功能?
我尝试将地图对象分配给全局变量,但赛普拉斯无法将其拾取:
// openlayers file
window.olMap = MapInstance;
// cypress spec
cy.window().then(window => {
console.log(window.olMap.getLayers()); // typeerror olMap is undefined, yet I can see it in cypress console
});
答案 0 :(得分:3)
由于赛普拉斯的异步特性,必须在测试继续之前加载地图,这是我解决的方法:
// Add in this get method which will wait until load
cy.get(".ol-viewport");
cy.window().then(win => {
const layers = win.olMap.getLayers().getArray();
console.log(layers); // Displays list of layers
});