|
@@ -1,36 +1,39 @@
|
|
-import { browser } from 'k6/browser';
|
|
|
|
|
|
+import { browser } from "k6/browser";
|
|
|
|
|
|
export const options = {
|
|
export const options = {
|
|
scenarios: {
|
|
scenarios: {
|
|
ui: {
|
|
ui: {
|
|
- executor: 'shared-iterations',
|
|
|
|
- vus: 1, // 使用5个虚拟用户
|
|
|
|
|
|
+ executor: "shared-iterations",
|
|
|
|
+ vus: 1, // 使用5个虚拟用户
|
|
iterations: 1,
|
|
iterations: 1,
|
|
options: {
|
|
options: {
|
|
browser: {
|
|
browser: {
|
|
- type: 'chromium',
|
|
|
|
|
|
+ type: "chromium",
|
|
launchOptions: {
|
|
launchOptions: {
|
|
- args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
|
|
|
+ },
|
|
|
|
+ },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
thresholds: {
|
|
thresholds: {
|
|
- checks: ['rate==1.0'],
|
|
|
|
- }
|
|
|
|
|
|
+ checks: ["rate==1.0"],
|
|
|
|
+ },
|
|
};
|
|
};
|
|
|
|
|
|
export default async function () {
|
|
export default async function () {
|
|
- const targetUrl = __ENV.targetUrl || 'http://www.baidu.com';
|
|
|
|
- const timeStamp = __ENV.timeStamp || '1751936544346';
|
|
|
|
|
|
+ const targetUrl = __ENV.targetUrl || "http://www.baidu.com";
|
|
|
|
+ const timeStamp = __ENV.timeStamp || "1751936544346";
|
|
const page = await browser.newPage();
|
|
const page = await browser.newPage();
|
|
// const targetUrlWithoutProtocol = targetUrl.replace('http://', '');
|
|
// const targetUrlWithoutProtocol = targetUrl.replace('http://', '');
|
|
// targetUrlWithoutProtocol = targetUrlWithoutProtocol.replace('https://', '');
|
|
// targetUrlWithoutProtocol = targetUrlWithoutProtocol.replace('https://', '');
|
|
try {
|
|
try {
|
|
- await page.goto(targetUrl);
|
|
|
|
|
|
+ await page.goto(targetUrl, {
|
|
|
|
+ timeout: 60000,
|
|
|
|
+ waitUntil: "networkidle", // 等待网络稳定再继续(适合截图)
|
|
|
|
+ });
|
|
await page.screenshot({ path: `screenshots/screenshot_${timeStamp}.png` });
|
|
await page.screenshot({ path: `screenshots/screenshot_${timeStamp}.png` });
|
|
} finally {
|
|
} finally {
|
|
await page.close();
|
|
await page.close();
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|