Hi, Guys
I was trying to run k6 in linux ubuntu virtual machine and I encounter an error while executing the browser instance script in a headless mode.
aut@LMAUT1:~$ ./k6 K6_BROWSER_ENABLED=true run script.js
ERRO[0000] unknown command "K6_BROWSER_ENABLED=true" for "k6"
aut@LMAUT1:~$ K6_BROWSER_ENABLED=true ./k6 run script.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: script.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 1m0s max duration (incl. graceful stop):
* browser: 1 looping VUs for 30s (exec: browser, gracefulStop: 30s)
ERRO[0004] Failed to load resource: the server responded with a status of 403 () browser_source=network line_number=0 source=browser stacktrace="<nil>" url="https://alb.reddit.com/rp.gif?ts=1690188543714&id=t2_aa7ovq9w&event=PageVisit&m.itemCount=undefined&m.value=&m.valueDecimal=undefined&m.currency=undefined&m.transactionId=&m.customEventName=&m.products=&m.conversionId=&uuid=054f7779-5ea1-4814-a63f-4bc1bf230665&aaid=&em=&external_id=&idfa=&integration=gtm&opt_out=0&sh=1280&sw=720&v=rdt_f5bd31b2"
ERRO[0032] Uncaught (in promise) navigating frame to "https://qa9.legalmatch.com/": navigating to "https://qa9.legalmatch.com/": timed out after 30s executor=constant-vus scenario=browser
browser_dom_content_loaded.......: avg=103.65ms min=79µs med=605µs max=690.93ms p(90)=428.25ms p(95)=529.13ms
browser_first_contentful_paint...: avg=742.54ms min=742.54ms med=742.54ms max=742.54ms p(90)=742.54ms p(95)=742.54ms
browser_first_meaningful_paint...: avg=742.54ms min=742.54ms med=742.54ms max=742.54ms p(90)=742.54ms p(95)=742.54ms
browser_first_paint..............: avg=742.54ms min=742.54ms med=742.54ms max=742.54ms p(90)=742.54ms p(95)=742.54ms
browser_loaded...................: avg=125.32ms min=259µs med=14.09ms max=514.95ms p(90)=421.14ms p(95)=468.04ms
data_received....................: 5.7 MB 180 kB/s
data_sent........................: 83 kB 2.6 kB/s
http_req_connecting..............: avg=29.49ms min=0s med=0s max=197ms p(90)=128.8ms p(95)=132.39ms
http_req_duration................: avg=376.69ms min=22.31ms med=255.3ms max=1.3s p(90)=968.99ms p(95)=1.06s
http_req_receiving...............: avg=215.22ms min=1ms med=79ms max=1.03s p(90)=674.6ms p(95)=848ms
http_req_sending.................: avg=182.79µs min=0s med=0s max=7ms p(90)=1ms p(95)=1ms
http_req_tls_handshaking.........: avg=18.75ms min=0s med=0s max=129ms p(90)=70.39ms p(95)=80.99ms
http_reqs........................: 93 2.935365/s
iteration_duration...............: avg=31.55s min=31.55s med=31.55s max=31.55s p(90)=31.55s p(95)=31.55s
iterations.......................: 1 0.031563/s
vus..............................: 1 min=1 max=1
vus_max..........................: 1 min=1 max=1
running (0m31.7s), 0/1 VUs, 1 complete and 0 interrupted iterations
browser ✓ [======================================] 1 VUs 30s
aut@LMAUT1:~$
Script
import { chromium } from 'k6/experimental/browser';
import { check } from 'k6';
export const options = {
scenarios: {
browser: {
executor: 'constant-vus',
exec: 'browser',
vus: 1,
duration: '30s'
}
}
};
export async function browser() {
const browser = chromium.launch({ headless: true, timeout: '60s' });
const page = browser.newPage();
try {
await page.goto('https://qa9.legalmatch.com/');
check(page, {
'Find the Right Lawyer for Your Legal Issue!': (page) =>
page.locator("(//a[@class='case-intake-form__header--link'])[1]").isVisible() ===
true
});
check(page, {
'Hero Banner': (page) => page.locator("(//div[@class='hero '])[1]").isVisible() === true
});
check(page, {
'Top Rated': (page) =>
page
.locator("(//div[@class='w-top-rated w-top-rated--no-location '])[1]")
.isVisible() === true
});
} finally {
page.close();
browser.close();
}
}
Thanks for your help.