response()
返回匹配的 Response 对象,如果因错误未接收到响应,则返回 null
。
返回值
类型 | 描述 |
---|---|
Promise<Response | null> | Response 对象,如果因错误未接收到响应,则返回 null 。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
const res = await page.goto('https://test.k6.io/');
const req = res.request();
const response = await req.response();
// ...
} finally {
await page.close();
}
}