Open jimevans opened 1 year ago
Thank you @jimevans for filing!
I want to add that clients should be able to set this location override per tab.
The Browser Testing and Tools Working Group just discussed Geolocation emulation
.
Should we propose it as part of the https://w3c.github.io/geolocation-api/ spec?
Chrome currently supports latitude, longitude, accuracy overrides which works for the top-level context and iframes. It does not affect the permission and it does not allow to use geolocation on insecure contexts.
WebdriverIO currently already supports this by overwriting the navigator.geolocation
interface in the browser via the preload script:
const patchedFn = options instanceof Error
? `cbError(new Error(${JSON.stringify(options.message)}))`
: `cbSuccess({
coords: ${JSON.stringify(options)},
timestamp: Date.now()
})`
await this.scriptAddPreloadScript({
functionDeclaration: /*js*/`() => {
Object.defineProperty(navigator.geolocation, 'getCurrentPosition', {
value: (cbSuccess, cbError) => ${patchedFn}
})
}`
})
@christian-bromann Thanks for sharing! Do you support changing it after the page is loaded/during the test? Also, what about Geolocation.watchPosition()
?
I think the override on the browser side would be more robust but preload scripts offer the ability to implement something already.
I agree. The current emulation features we have can't be changed after the page has loaded. It would be helpful, especially for component tests to modify these capabilities without having to do a page load.
One request often heard from users is that they want to simulate a browser at a specific geolocation for their sites. WebDriver should provide a mechanism to facilitate this testing.