Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementHandle: nil pointer dereference #1056

Open
Tracked by #1138
lthurr opened this issue Oct 3, 2023 · 4 comments
Open
Tracked by #1138

ElementHandle: nil pointer dereference #1056

lthurr opened this issue Oct 3, 2023 · 4 comments
Labels
bug Something isn't working user request Requested by the community

Comments

@lthurr
Copy link

lthurr commented Oct 3, 2023

Brief summary

Hi, I have been trying to set a pipeline to automatically run our k6 browser tests in order to collect periodically some web vital metrics.

The problem is that I can't manage to make it work because I'm getting panic: runtime error: invalid memory address or nil pointer dereference. I have been trying to look out for solutions or even if this was reported before and I haven't found anything. So I'm kindly requesting your support here.

The k6 version run within the jenkins job returns

k6 v0.46.0 (2023-08-14T13:23:26+0000/v0.46.0-0-gcbd9e9ad, go1.20.7, linux/amd64)

let me proceed to explain what I see

k6 version

k6 v0.46.0 (2023-08-14T13:23:26+0000/v0.46.0-0-gcbd9e9ad, go1.20.7, linux/amd64)

OS

linux

Docker version and image (if applicable)

No response

Steps to reproduce the problem

I have two examples,
one of them triggers the panic: runtime error. However, when I execute the example script described in k6.io, this one works perfectly fine.

The following script triggers the panic

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


export let options = {
  scenarios: {
    addProductToCart: {
      executor: 'shared-iterations',
      iterations: 10,
      vus: 1,
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  }
};

export default async function () {
    const context = browser.newContext();
    try {
      context.addCookies([{name: COOKIE_NAME, value: COOKIE_VALUE, domain: COOKIE_DOMAIN, path: "/"}]);
      const page = context.newPage();

      await page.goto(url, { waitUntil: 'networkidle' });

      await page.locator(loc1).click();
      await page.locator(loc2).click();
      await page.locator(loc3).click();
      page.locator(loc4).waitFor({ state: 'visible' });


      check(page, {
          'Item is added to cart': page.locator(loc5).textContent() == 'validation text'
        }
      );
    } finally {
      page.close();
    }
}

The following script doesn't trigger the panic

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


export let options = {
  scenarios: {
    example: {
      executor: 'shared-iterations',
      iterations: 10,
      vus: 1,
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  }
};

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

  try {
    await page.goto('https://test.k6.io/');
  } finally {
    page.close();
  }
}

Expected behaviour

Script is executed succesfully

Actual behaviour

When I execute the file provided above, I face the following output

panic: runtime error: invalid memory address or nil pointer dereference

[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1195471]

goroutine 1000 [running]:
github.com/grafana/xk6-browser/common.(*ElementHandle).clickablePoint(0xc00068d9f0)
	github.com/grafana/xk6-browser@v1.0.2/common/element_handle.go:181 +0x2d1
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func1({0x1a09cb0, 0xc000ae8ae0}, 0x0?)
	github.com/grafana/xk6-browser@v1.0.2/common/element_handle.go:1441 +0x3ba
github.com/grafana/xk6-browser/common.retryPointerAction({0x1a09cb0, 0xc000ae8ae0}, 0xc001f78b80, 0xc0023d6240)
	github.com/grafana/xk6-browser@v1.0.2/common/element_handle.go:1488 +0x42
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func2({0x1a09cb0?, 0xc000ae8ae0?}, 0xc0023d6240?, 0x0?)
	github.com/grafana/xk6-browser@v1.0.2/common/element_handle.go:1476 +0x3b
github.com/grafana/xk6-browser/common.(*Frame).newPointerAction.func1({0x1a09cb0, 0xc000ae8ae0}, 0xc0007f2ea0, 0xc0007f2f00)
	github.com/grafana/xk6-browser@v1.0.2/common/frame.go:1989 +0x169
created by github.com/grafana/xk6-browser/common.call
	github.com/grafana/xk6-browser@v1.0.2/common/helpers.go:102 +0x17b
script returned exit code 2
@lthurr lthurr added the bug Something isn't working label Oct 3, 2023
@olegbespalov olegbespalov transferred this issue from grafana/k6 Oct 3, 2023
@olegbespalov olegbespalov removed their assignment Oct 3, 2023
@ankur22
Copy link
Collaborator

ankur22 commented Oct 3, 2023

@lthurr could you please open a new thread in our community forum?

Does seem to be an issue though. Have you been able to reproduce the issue in a public website that we can work with and reproduce on too?

@inancgumus inancgumus changed the title k6-browser - panic: runtime error: invalid memory address or nil pointer dereference element handle: panic: invalid memory address or nil pointer dereference Nov 10, 2023
@adnanerlansyah403
Copy link

Is this issue still running ?

@ankur22 ankur22 added the user request Requested by the community label Mar 14, 2024
@inancgumus inancgumus changed the title element handle: panic: invalid memory address or nil pointer dereference ElementHandle: nil pointer dereference Mar 18, 2024
@ankur22
Copy link
Collaborator

ankur22 commented Sep 23, 2024

Updated stack trace

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

goroutine 3341089 [running]:
github.com/grafana/xk6-browser/common.(*ElementHandle).clickablePoint(0xc0034557c0)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:168 +0x2b6
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func1({0x1eee958, 0xc0023d8cb0}, 0x0?)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:1613 +0x453
github.com/grafana/xk6-browser/common.retryPointerAction({0x1eee958, 0xc0023d8cb0}, 0xc0077fe860, 0xc009352960)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:1660 +0x3c
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func2({0x1eee958?, 0xc0023d8cb0?}, 0xc001f79aa0, 0xc001f79b00)
github.com/grafana/xk6-browser@v1.7.1/common/element_handle.go:1648 +0x45
github.com/grafana/xk6-browser/common.(*Frame).click.(*Frame).newPointerAction.func2({0x1eee958, 0xc0023d8cb0}, 0xc001f79aa0, 0xc001f79b00)
github.com/grafana/xk6-browser@v1.7.1/common/frame.go:2181 +0x116
created by github.com/grafana/xk6-browser/common.call in goroutine 3341072
github.com/grafana/xk6-browser@v1.7.1/common/helpers.go:103 +0x14c

@ankur22
Copy link
Collaborator

ankur22 commented Sep 23, 2024

The only reason we would get this NPD is if the getLayoutMetrics returned a nil value for layoutViewport.

Looking at Playwright's clickablePoint they don't seem to work with the GetLayoutMetrics CDP API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working user request Requested by the community
Projects
None yet
Development

No branches or pull requests

4 participants