URL not passed to browser for k6-browser tests

I am trying to run the k6-browser test on windows. It opens up a new chrome window but the URL is not passed and an untitled blank tab is opened.
After 30s , the test times out with the error
Uncaught (in promise) creating new page in browser context: timed out after 30s executor=shared-iterations scenario=ui

The script as follows:

import { browser } from 'k6/browser';
import { check } from 'k6';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  //const context = await browser.newContext();
  const page = await browser.newPage();

  try {
    await page.goto("https://www.google.com/");

    await Promise.all([
        page.locator('#loginbutton').click({force:true},{buton:'left'}),
        //page.waitForNavigation(),
      ]);

    /*await page.locator('input[name="login"]').type("admin");
    await page.locator('input[name="password"]').type("123");

    await Promise.all([
      page.waitForNavigation(),
      page.locator('input[type="submit"]').click(),
    ]);

    const header = await page.locator("h2").textContent();
    check(header, {
      header: (h) => h == "Welcome, admin!",
    });*/
  } finally {
    await page.close();
  }
}

Any help is much appreciated

Hi @anandankitgrafana

I couldn’t reproduce the above issue and the code worked fine in my system. I am using k6 version 0.52.0.

import { browser } from 'k6/browser';
import { check ,sleep} from 'k6';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  
  const page = await browser.newPage();

  try {
    await page.goto("https://www.google.com/");

    await page.locator('//*[@id="APjFqb"]').type('K6'); // Type k6 in search bar
    sleep(3)
    await page.keyboard.press('Enter');  // Press Enter Key

    sleep(5);

  } finally {
    await page.close();
  }
}

Thanks

1 Like