菜单
开源

setDefaultTimeout(timeout)

设置所有接受 timeout 选项的方法的默认最大超时时间,单位为毫秒。

参数类型默认值描述
timeoutnumber取决于具体操作。超时时间,单位为毫秒。

示例

JavaScript
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();
  context.setDefaultTimeout(1000); // 1s
  const page = await context.newPage();
  await page.click('h2'); // times out
}