script-browser.js 959 B

123456789101112131415161718192021222324252627282930313233343536
  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. await page.screenshot({ path: `screenshots/screenshot_${timeStamp}.png` });
  31. } finally {
  32. await page.close();
  33. }
  34. }