Fake Your GeoLocation in Web Test Automation
How to fake geolocation to assist in web test automation
A repost of my daughter’s article with permission. I added a few notes. This is also included in my “How to in Selenium WebDriver” series.
Many web apps use location-based information (e.g. find the nearest restaurant). To test this feature, you need to simulate the browser’s geolocation. Tests can be run anywhere, and using specific locations can help test location-based behaviour, e.g. distance calculation.
This tutorial will go over how to fake your location in an automated test.
Table of Contents:
· Test Design
· Test Steps
∘ JavaScript method
∘ Selenium 4/Chrome Devtools Protocol Method
· Complete Script
· Zhimin’s Notes
Sample Website
I will use WhenWise’s Location search bar for this tutorial.
Test Design
- Pass in the desired geolocation to the browser
- Click “Use my current location”
- Expect “current location” to be the desired geolocation