Unable to set the geoLocation on Playwright

130 views Asked by At

I need to test a cookie banner not showing up at certain regions, and I tried to set the geolocation to the USA where it shouldn't appear.

However, I haven't been able to do so. I've tried creating different tests to just check the location of the browser (opening Google Maps) but the location always seems to be my current location or my VPN's location.

This is the test, I feel I'm stuck, don't know where else to look, checked the docs thoroughly.

  test(`Cookie 2.0 E2E test for USA (No cookie consent banner)`, async ({}) => {
    const usaLocation: LocationInfo = getLocationsToTest().find(
      (location) => location.countryCode === 'US',
    )

    const browser = await chromium.launch()
    const context = await browser.newContext()

    await context.setGeolocation({
      longitude: usaLocation.longitude,
      latitude: usaLocation.latitude,
    })

    const page = await context.newPage()
    await page.goto(`/`)

    const cookies = await context.cookies()

    const cookieScriptConsent = cookies.find(
      (cookie) => cookie.name === 'CookieScriptConsent',
    )

    // should be undefined -- need to work on this (WIP)
    expect(cookieScriptConsent).toBeUndefined()
  })

Appreciate your help, thanks a lot.

P.S., some extra info of my setup.

  • Running on Chrome.
  • My executor is based on a Docker image.
0

There are 0 answers