Search code examples
leafletautomated-testsmapse2e-testingtestcafe

How to test leaflet based maps using testcafe?


We are building a series of tests using TestCafe. How do we test if a point or path in a leaflet control is rendered correctly? To be more specific we are trying to test the lat-lon data of a circle marker in the map. But, we do not have any leaflet map/marker object available in the scope of testcafe scripts.

References:

Unit testing leaflet maps


Solution

  • I created a simple example of an assertion for a path element in a leaflet control on the getting started demo page https://leafletjs.com/examples/quick-start/

    import { Selector } from 'testcafe';
    
    fixture `fixture`
        .page `https://leafletjs.com/examples/quick-start/`;
    
    test('test', async t => {
        await t
            .switchToIframe('iframe')
            .expect(Selector('path').withAttribute('stroke', 'red').getAttribute('d')).eql('M141.20355555554852,171.94704600190744a42,42 0 1,0 84,0 a42,42 0 1,0 -84,0 ');
    });
    

    Please provide us with an example of your testing page so we will be able to offer you something more specific for your scenario.