Search code examples
javascripttestinggeolocationopenlayers

Simulating moving geolocation when developing web map solution using OpenLayers


Long title but simple problem that I really haven't found a good solution to.

Prerequisites

  • ASP.NET Framework Web Forms Application (not really important)
  • Map solution using OpenLayers 2.14 (yeah I know it's old but it works)

I'm currently implementing a feature that will display the current position of the device in map and it's based on the Geolocate-control of OpenLayers. It works great for the initial load but I would like to simulate a person moving around geographically with their device for testing purposes.

What I've tried

  • I've tried using the Sensors-feature of DevTools. Again, this works for the initial load, changing the location requires a refresh of the page.
  • I've tried using Selenium ChromeDriver to send the coordinates with the command: Emulation.setGeolocationOverride, but this does not trigger watchPosition being updated for navigator.geolocation.
  • Can't find any suitable Chrome Extension for the problem.

Does anyone know of any best practice for this problem? At the moment I have to revert to some refactoring and simulate some updates using setInterval. This however won't fully test the behavior of the navigator.geolocation-feature without me running around with my developer-device in the wild.


Solution

  • For anyone working with OpenLayers 2.x I would like to add that you can save yourself a lot of headache by specifying the watch-property to true using the Geolocate-control. This is by default false which caused a lot of testing to fail. Simple testing using the Sensors-feature of DevTools works as intended if the watch-property is set.