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

K6_BROWSER_TIMEOUT not taken into account #1020

Closed
jeromebrongniart opened this issue Aug 30, 2023 · 1 comment
Closed

K6_BROWSER_TIMEOUT not taken into account #1020

jeromebrongniart opened this issue Aug 30, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jeromebrongniart
Copy link

Brief summary

Hello,

I have troubles changing the timeout of my browser script using the environment variable K6_BROWSER_TIMEOUT as follow:
$env:K6_BROWSER_TIMEOUT='10s'; k6 run '.\unit tests\browser_script_fails.js'
as it always give me the error:
ERRO[0031] Uncaught (in promise) GoError: typing "something" in "input[name=\"not_existing\"]": timed out after 30s

k6 version

k6 v0.46.0

OS

Windows 10

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Executing the following simple script:

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

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

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

  try {
    await page.goto('https://test.k6.io/');
    page.locator('input[name="not_existing"]').type('something');

  } finally {
    page.close();
  }
}

always fails after the default timeout of 30s:

PS C:\tmp\k6> $env:K6_BROWSER_TIMEOUT='10s'; k6 run '.\unit tests\browser_script_fails.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: .\unit tests\browser_script_fails.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * ui: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

ERRO[0031] Uncaught (in promise) GoError: typing "something" in "input[name=\"not_existing\"]": timed out after 30s
running at github.com/grafana/xk6-browser/api.Locator.Type-fm (native)
ui     [at file:///C:/tmp/k6/unit%20tests/browser_script_fails.js:22:50(19)  executor=shared-iterations scenario=ui

     browser_data_received.......: 27 kB  858 B/s
     browser_data_sent...........: 1.1 kB 34 B/s
     browser_http_req_duration...: avg=197.73ms min=97.98ms  med=191.64ms max=303.57ms p(90)=281.18ms p(95)=292.37ms
     browser_http_req_failed.....: 0.00%  ✓ 0        ✗ 3
     browser_web_vital_cls.......: avg=0        min=0        med=0        max=0        p(90)=0        p(95)=0
     browser_web_vital_fcp.......: avg=502.39ms min=502.39ms med=502.39ms max=502.39ms p(90)=502.39ms p(95)=502.39ms
     browser_web_vital_lcp.......: avg=502.39ms min=502.39ms med=502.39ms max=502.39ms p(90)=502.39ms p(95)=502.39ms
     browser_web_vital_ttfb......: avg=301.7ms  min=301.7ms  med=301.7ms  max=301.7ms  p(90)=301.7ms  p(95)=301.7ms
     data_received...............: 0 B    0 B/s
     data_sent...................: 0 B    0 B/s
     iteration_duration..........: avg=30.71s   min=30.71s   med=30.71s   max=30.71s   p(90)=30.71s   p(95)=30.71s
     iterations..................: 1      0.032201/s
     vus.........................: 1      min=1      max=1
     vus_max.....................: 1      min=1      max=1


running (00m31.1s), 0/1 VUs, 1 complete and 0 interrupted iterations
ui   ✓ [======================================] 1 VUs  00m31.1s/10m0s  1/1 shared iters
PS C:\tmp\k6>

Expected behaviour

The script is suppose to fail after 10s, as indicated in the environment variable.

Actual behaviour

The script fails after wating for the default timeout of 30s

@jeromebrongniart jeromebrongniart added the bug Something isn't working label Aug 30, 2023
@codebien codebien transferred this issue from grafana/k6 Aug 31, 2023
@codebien codebien assigned ankur22 and unassigned codebien Aug 31, 2023
@ankur22
Copy link
Collaborator

ankur22 commented Sep 21, 2023

Hi @jeromebrongniart,

Thanks for raising an issue. Could you please search and create a new post in our community forum next time. It's a great place to see if anyone else has asked a similar question, and if not ask a new one and in the future someone else will be able to work with the answer.

K6_BROWSER_TIMEOUT is the timeout that you can use when the default timeout of 30s isn't enough when k6 is performing the initial connection to chrome, and when you perform browser API calls in your script e.g. browser.newPage. So this isn't the timeout you want to be working with in your case.

The timeout you should be working with is the one that you can set on page. The issue is that in the latest release of k6 (v0.46.0) the timeout in page can't be set through page.setDefaultTimeout or page.setDefaultNavigationTimeout due to a bug, but we've recently fixed that and it will be in the next release of k6 (v0.47.0).

For now though you can work with browserContext.setDefaultTimeout or browserContext.setDefaultNavigationTimeout instead. Unfortunately although the timeout does work it suffers from an issue where internally it will mistake a millisecond timeout to a second timeout in v0.46.0 of k6, which has also been fixed and will be in the next release.

To work with the timeout in browserContext you can:

  const context = browser.newContext();
  context.setDefaultTimeout(1000);
  const page = context.newPage();

I'm going to close this issue. If you're still having issues though, please open a new topic in our community forum.

@ankur22 ankur22 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants