首页 > 解决方案 > how set geolocation to block in chrome using puppeteer

问题描述

I am looking for a way to respond block when being asked about sharing my location

I got to the point that I do

const context = browser.defaultBrowserContext();
context.clearPermissionOverrides();

I when I do this and login to my app I get the share location pop-up. After that I am able to set my location by doing

context.overridePermissions(global.URL, ['geolocation']);
 await page.setGeolocation({
   latitude: 39.103957,
   longitude: -76.834938
  });

What I actually looking to do is respond 'block' to the share location pop-up. Below is how my test would eventually look

it("shows error page", async () => {
    await page.setUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) 
           AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1")
    const context = browser.defaultBrowserContext();
    context.clearPermissionOverrides();
    //somehow respond blocked
    await common.login(page, global.USER4,global.PASSWORD4)
    expect(await landingPage.getText()).toMatch("error text")
})

标签: javascriptpuppeteerjest-puppeteer

解决方案


推荐阅读