Rayrun
← Back to Discord Forum

Block geolocation

Hi, Maybe someone can help,in my app in most cases there is geolocataion used and this is fine as I can set it easily. But I need also to check if without geolocaiton it's still working. And here is the problem because I can't dismiss geolocation dialog and my app is waiting until you either confirm or deny location. So basically I'm ending up in state like on screenshot and I can't do any action.

image.png

This thread is trying to answer question "How can I dismiss the geolocation dialog in my app or check if it works without geolocation?"

2 replies
vikramsanap_10396

Hey Yabol, Did you find any solution on this issue? I am also facing the same. Thanks

vikramsanap_10396

Hey Bro, Just got the solution on this issue. You just need to give permission for the geolocation in your 'Playwright.config.ts' file.

How to do that ?

go to your 'playwright.config.ts' file in 'projects' array section create a project you want to launch your tests in with following properties :

{ name: 'Google Chrome', use: { ...devices['Desktop Chrome'], channel: 'chrome', geolocation: { longitude: 170.088155, latitude: 75.145800 }, permissions: ['geolocation'] }, }

ideally you should use your latitude and longitude values and it shouldn't allow any random values but surprisingly in my case, It allowed me to login using any random lattitude and longitude values and that was a blessing in disguise for me as I wanted to run my test caes on azure devops and we don't know the location where their servers are located.

So you can try out this solution. Hope it will help you.

Geolocation.png

Answer

Dismissing Geolocation Dialog with Playwright

To automate the dismissal of the geolocation dialog in your app with Playwright, you'll need to adjust the permissions in your browser context.

Setting Up Permissions

In your playwright.config.ts file, define the permissions for your tests. To dismiss the geolocation dialog, set geolocation permissions to an empty array:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    permissions: ['geolocation'],
  },
});

By doing this, you're granting geolocation permission to your browser context.

Clearing Permissions

Next, in your test file (tests/example.spec.ts), clear all permissions before running any tests using context.clearPermissions():

import { test } from '@playwright/test';

test.beforeEach(async ({ context }) => {
  await context.clearPermissions();
});

// Your tests go here...

This revokes all previously granted permissions.

Now, when you run your tests, the geolocation dialog should be dismissed automatically as no specific location is provided. This lets you check if your app works without geolocation data.

Remember, this solution is based on the information provided. If your app or framework has additional details or requirements, please provide more context for further assistance.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.