playwright自动化测试时,会遇到位置信息的提示,如图所示
可以在new_context
时设置geolocation
,在谷歌地图上可以查看地点的经纬度
方法一:new_context时,设置geolocation
context = browser.new_context(
geolocation={"longitude": 41.890221, "latitude": 12.492348},
permissions=["geolocation"]
)
或者
context.set_geolocation({"longitude": 48.858455, "latitude": 2.294474})
方法二:browser_context_args fixture中设置
@pytest.fixture(scope="session")
def browser_context_args(browser_context_args, pytestconfig):
return {
**browser_context_args,
"geolocation":{"longitude": 101.08572766649516, "latitude": 20.51233528633878},
"permissions": ["geolocation"]
}