View in #general on Slack
@Kate: Hi all,
I am getting an error by using a function I.setGeoLocation(121.21, 11.56, 10)
with Webdriver helper.
this.browser.setGeoLocation is not a function
Could someone please check if it is really a bug? If yes, I will create an issue.
“codeceptjs”: “3.0.6",
“webdriverio”: “7.0.7"
Thanks in advance!
I guess I should install and enable @wdio/devtools-service, but following did not work:
plugins:{
wdio: {
enabled: true,
services: ['devtools'],
}
},
@davert: It is from deprecated JSONWire protocol
And your browser session probably using new WebDriver protocol
So the command is not available there
I don’t know what is workaround there… If it is not part of protocol probably there is no API for that. I would recommend using Playwright or Puppeteer instead
@thanh: https://github.com/webdriverio/webdriverio/issues/5510
[webdriverio/webdriverio] #5510 “browser.setGeoLocation is not a function” after update to webdriverio v6
@Kate: Thanks for the answers @davert @thanh
I actually found this Github answer before I posted here, and after reading the article https://dev.to/coffeestain/emulate-geolocation-for-automated-testing-with-webdriverio-5e2e I did following:
npm install @wdio/devtools-service --save-dev
- in codeceptjs config, I added
plugins:{
wdio: {
enabled: true,
services: ['devtools'],
}
},
- in test,
I.useWebDriverTo('setTimezone', async ({ browser }) => {
browser.setGeoLocation({ latitude: 121.21, longitude: 11.56});
browser.cdp('Emulation', 'setTimezoneOverride', {
timezoneId: 'Europe/London'
})
});
And this did not work.
I will try Puppeteer now, as recommended
DEV Community: Emulate GeoLocation for Automated Testing with webdriverIO
In case anyone will need, here’s a solution to change timezone or geolocation with Puppeteer helper
I.usePuppeteerTo('emulate timezone and geolocation', async ({ page }) => {
await page.emulateTimezone('America/New_York');
await page.setGeolocation({latitude: 59.95, longitude: 30.31667});
});
@davert: Thanks! This is really good solution