I’m fairly certain this all worked fine before but I had to switch projects for a month and now I’m experiencing some issues I wanted to seek help for.
So I have some browser based tests I’ve created, running them locally, it all works as expected. However, when I try to run them via our circleCI pipeline, I get the following error:
time="2024-04-30T10:58:02Z" level=error msg="Uncaught (in promise) TypeError: Cannot read property 'newPage' of undefined or null\n\tat browserTest (file:///home/circleci/project/load_tests/tests/frontend/testLoad.js:27:15(3))\n" executor=shared-iterations scenario=ui
The k6 script I’ve written looks like this, am I missing anything I should be initialising?:
We no longer recommend directly using xk6-browser. Instead, we release the browser module (xk6-browser) along with standard k6 distributions. For instance, you can find the latest k6 release on this web page.
Please visit this link for a step by step tutorial on how to use the k6 browser.
I am using the browser included within the core k6 project, am I not? The web page you’ve listed doesn’t contain direct information related to my issue and is just the general release notes page so I’m not sure what you’re trying to point me toward?
For the step by step tutorial, the only difference I see is the use of Context? I’ve since added this and it just produces a slightly different error for the same thing:
time="2024-04-30T16:45:43Z" level=error msg="Uncaught (in promise) TypeError: Cannot read property 'newContext' of undefined or null\n\tat browserTest (file:///home/circleci/project/load_tests/tests/frontend/partnerDashboardJobSearch.js:27:18(3))\n" executor=shared-iterations scenario=ui
Apologies. I guess I’ve misunderstood your issue. Could you share the import paths you use on your script? The browser module exports newContext through k6/experimental/browser and it should work. It might mean that the module doesn’t exist if newContext cannot be reached through the browser module.
After discussing this with the team, we have some ideas.
The statsd extension uses an older version of k6, v0.45.1 specifically. This is because xk6 builds k6 with the highest version requested by extensions. So, the browser module’s API in k6 v0.45.1 doesn’t support the newContext API that you’re using.
Are you sure that you’re using the statsd extension locally while running your script?
It seems like you don’t need to use the statsd extension. Could you try removing it from your CircleCI config and retry?
It wasn’t working for const page = browser.newPage() either though, I switched that based on more recent examples?
You’re correct I was not using statsD locally while running the script as I used k6 via homebrew rather than a custom binary, apologies, I did not make that remotely clear.
We do need the statsD extension, though as per DM I did try removing this and hit other errors:
time="2024-05-07T12:33:41Z" level=error msg="error building browser on IterStart: launching browser: Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory at browserTest (file:///home/circleci/project/load_tests/tests/frontend/partnerDashboardJobSearch.js:26:7(0))"
I’ll try doing some hacking around to see if I can get an acceptable balance of the version of golang, k6 and a browser
It wasn’t working for const page = browser.newPage() either though, I switched that based on more recent examples?
For everyone out there, if you want to use a specific browser version API (in your case, the k6 version is v0.45.1), you need to use the specific browser API. For example, for k6 v0.45.1, you should use this API.
Unfortunately, we don’t know why the dbus issue occurs (for example). Have you tried running the script with K6_BROWSER_HEADLESS=1 environment variable?
@inancgumus just to highlight here, you were correct to point out issues with the syntax I was using and what is mentioned in the v0.45.1 documentation.
However, I did make changes in line with the documentation, this ran fine locally, but not via circleCI as before. This includes when using k6 directly, rather than creating a binary. So statsD isn’t the issue, the binary isn’t the issue. A specific k6 version is not the issue. This seems some inherent issue with k6 browser or it’s directly related to it anyway.
Sorry just another update, this is actually working with 0.45.1 version. It is possible and works headlessly, if trying non-headless, it fails but this is progress