Invalid Memory Address

I am getting this Error when running K6 Browser locally any help?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=

These is my options:

export const options = {
  scenarios: {
    browser: {
      executor: 'constant-vus',
      vus: 10,
      duration: '5m',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    }
}
};

Hi @chingher90, welcome to the community forum!

Can you share the sanitized version of the test script also with us?

1 Like

@bandorko

Here is the sanitized version

import { browser } from 'k6/experimental/browser';
import { sleep, check } from 'k6';
import { SharedArray } from "k6/data";
import papaparse from "https://jslib.k6.io/papaparse/5.1.1/index.js";

export const options = {
  scenarios: {
    browser: {
      executor: 'constant-vus',
      vus: 10,
      duration: '5m',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    }
}
};

  // not using SharedArray here will mean that the code in the function call (that is what loads and
  // parses the csv) will be executed per each VU which also means that there will be a complete copy
  // per each VU
const csvData = new SharedArray("UserData", function () {
  // Load CSV file and parse it using Papa Parse
  return papaparse.parse(open("./data/randomData.csv"), { header: true }).data;
});

  // Pick a random userID test data pair
  const getCSVRandomData = csvData[Math.floor(Math.random() * csvData.length)];
  console.log("Selected UserName Data: ", JSON.stringify(getCSVRandomData));

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

  try {
    await page.goto('https://FAKE_URL.com/index.html');
    page.locator('input[name="username"]').type(getCSVRandomData.users);
    page.locator('input[name="password"]').type(getCSVRandomData.password);
    const submitButton = page.locator("LOGINBUTTON_XPATH");
    await Promise.all([page.waitForNavigation(), submitButton.click()]);
    sleep(1.0)
    //Navigate to another page after login
    page.goto ('https://FAKE_URL.com');
    sleep(1.0)
    const text = page.locator('XPATH');
    if (text.isVisible()) {
      console.log("element is visible");
    }
    
  } finally {
    const signoutButton = page.locator('SIGNOUT_XPATH');
    if (signoutButton.isVisible()) {
      await Promise.all([page.waitForNavigation(), signoutButton.click()]);
      console.log(" Test Successfully Sign out");
    }else{
      console.log("SignOut failed to locate");
    };
    page.close();
  }
}


I confirm the script will work if I just config for only one VU for one iteration but if I bump up the VUs like the above settings …it will crash.

@chingher90: Are there any stacktrace in the error message?