Fake Your GeoLocation in Web Test Automation

How to fake geolocation to assist in web test automation

Zhimin Zhan
4 min readSep 25, 2022

--

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

  1. Pass in the desired geolocation to the browser
  2. Click “Use my current location”
  3. Expect “current location” to be the desired geolocation

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.