text()
返回响应体作为字符串。
返回值
类型 | 描述 |
---|---|
Promise<string> | 一个 Promise,解析为响应体字符串。 |
示例
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 text = await res.text();
console.log(`text: ${text}`); // text: <!DOCTYPE html>...
} finally {
await page.close();
}
}