Reputation: 2780
How can I check for features on an Openlayers map within a Cypress test?
I have tried assigning the map object to a global variable but Cypress can't pick it up:
// 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
});
Is there a better way to detect features within Cypress?
Upvotes: 1
Views: 1285
Reputation: 2780
Due to the asyncronous nature of Cypress the map must be loaded before the test continues, this is how I solved it:
// 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
});
Upvotes: 4