script-browser.js 857 B

123456789101112131415161718192021222324252627282930313233
  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. }
  12. },
  13. },
  14. },
  15. thresholds: {
  16. checks: ['rate==1.0'],
  17. }
  18. };
  19. export default async function () {
  20. const targetUrl = __ENV.targetUrl || 'http://www.baidu.com';
  21. const timeStamp = __ENV.timeStamp || '1751936544346';
  22. const page = await browser.newPage();
  23. // const targetUrlWithoutProtocol = targetUrl.replace('http://', '');
  24. // targetUrlWithoutProtocol = targetUrlWithoutProtocol.replace('https://', '');
  25. try {
  26. await page.goto(targetUrl);
  27. await page.screenshot({ path: `screenshots/screenshot_${timeStamp}.png` });
  28. } finally {
  29. await page.close();
  30. }
  31. }