1234567891011121314151617181920212223242526272829303132333435363738 |
- import { browser } from "k6/browser";
- export const options = {
- scenarios: {
- ui: {
- executor: "shared-iterations",
- vus: 1, // 使用5个虚拟用户
- iterations: 1,
- options: {
- browser: {
- type: "chromium",
- launchOptions: {
- args: ["--no-sandbox", "--disable-setuid-sandbox"],
- },
- },
- },
- },
- },
- thresholds: {
- checks: ["rate==1.0"],
- },
- };
- export default async function () {
- const targetUrl = __ENV.targetUrl || "http://www.baidu.com";
- const timeStamp = __ENV.timeStamp || "1751936544346";
- const page = await browser.newPage();
- // const targetUrlWithoutProtocol = targetUrl.replace('http://', '');
- // targetUrlWithoutProtocol = targetUrlWithoutProtocol.replace('https://', '');
- try {
- await page.goto(targetUrl, {
- timeout: 60000
- });
- await page.screenshot({ path: `screenshots/screenshot_${timeStamp}.png` });
- } finally {
- await page.close();
- }
- }
|