Tests running fine locally but via circleCI I get uncaught promise on newPageerror

Hello,

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?:


export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      exec: 'browserTest',
      vus: 1,
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
}

export async function browserTest () {
  const page = browser.newPage()

  try {

Notes:

  • Works locally but not via circleCI
  • Non-browser based tests are fine locally and via circleCI
  • Still fails in the same way if headless is set to true or false (or this env variable is ignored)
  • I use the browser-tools orb via circleCI to install chrome and chromedriver before building my k6 binary

Anybody got any suggestions for me?

This is what the circleCI job definition looks like:

  load_tests:
    environment:
        K6_STATSD_ENABLE_TAGS: true
        K6_BROWSER_ENABLED: true
        K6_BROWSER_HEADLESS: true
    executor:
      name: go/default
      tag: '1.19'
    steps:
      - checkout_branch
      - browser-tools/install-chrome
      - browser-tools/install-chromedriver
      - run:
          name: Install xk6
          command: |
            go install go.k6.io/xk6/cmd/xk6@latest
      - run:
          name: Build xk6 with statsd extension
          command: |
            xk6 build --with github.com/LeonAdato/xk6-output-statsd@latest
      - run:
          name: Run k6 script with statsd output
          command: |
            ./k6 run --out output-statsd << pipeline.parameters.load_test_script_path >>

Hi @nicholaspshaw,

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.

Please let us know if you have further questions.

1 Like

Hi @inancgumus ,

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

Hi @nicholaspshaw,

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.

Thanks.

1 Like

No worries @inancgumus you’re just trying to help me.

My imports are basic as you might expect. Again, these work fine locally, the only issue is running via circleCI

/* eslint import/no-unresolved: [2, { ignore: ['^k6.*'] }] */

import { browser } from 'k6/experimental/browser'

// eslint-disable-next-line no-restricted-syntax
import { LoginPage } from '../../pages/loginPage.js'

// eslint-disable-next-line no-restricted-syntax
import { DashboardPage } from '../../pages/dashboardPage.js'

Hi @nicholaspshaw,

I sent you a private message to get more details about this issue.

1 Like

Hi @nicholaspshaw,

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?

Thanks. I hope this helps.

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

Hi @nicholaspshaw,

No worries.

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?

2 Likes

@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.

Can you please pass me to someone who can help?

1 Like

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 :grimacing: