setGeolocation(geolocation)
注意
此功能存在已知问题。详情请参阅#435。
设置浏览器上下文的地理位置。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
geolocation | 对象 | null | |
geolocation.latitude | 数字 | 0 | 纬度,介于 -90 和 90 之间。 |
geolocation.longitude | 数字 | 0 | 经度,介于 -180 和 180 之间。 |
geolocation.accuracy | 数字 | 0 | 可选的非负精度值。 |
返回值
类型 | 描述 |
---|---|
Promise<void> | 地理位置设置完成后返回的 Promise。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const context = await browser.newContext();
await context.setGeolocation({ latitude: 59.95, longitude: 30.31667 });
}