script-browser.js 981 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { browser } from "k6/browser";
  2. export const options = {
  3. scenarios: {
  4. ui: {
  5. executor: "shared-iterations",
  6. vus: 1, // 使用5个虚拟用户
  7. iterations: 1,
  8. options: {
  9. browser: {
  10. type: "chromium",
  11. launchOptions: {
  12. args: ["--no-sandbox", "--disable-setuid-sandbox"],
  13. },
  14. },
  15. },
  16. },
  17. },
  18. thresholds: {
  19. checks: ["rate==1.0"],
  20. },
  21. };
  22. export default async function () {
  23. const targetUrl = __ENV.targetUrl || "http://www.baidu.com";
  24. const timeStamp = __ENV.timeStamp || "1751936544346";
  25. const page = await browser.newPage();
  26. // const targetUrlWithoutProtocol = targetUrl.replace('http://', '');
  27. // targetUrlWithoutProtocol = targetUrlWithoutProtocol.replace('https://', '');
  28. try {
  29. await page.goto(targetUrl, {
  30. timeout: 60000
  31. });
  32. await page.screenshot({ path: `screenshots/screenshot_${timeStamp}.png` });
  33. } finally {
  34. await page.close();
  35. }
  36. }