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

Fix reload & setContent to use navigation timeout #1034

Merged
merged 2 commits into from
Sep 18, 2023

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Sep 14, 2023

What?

The following page APIs were not using the correct timeout:

page.reload()
page.setContent()

Why?

These methods should work with the default navigation instead of the default timeout to match the behaviour in Playwright.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

inancgumus
inancgumus previously approved these changes Sep 18, 2023
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this with the following script, and it worked 🥳 Nice catch!

I've also checked the other methods we have by exploring the link you shared, and they all seem fine and use the correct timeout 👍

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

export const options = {
  scenarios: {
    ui: {
      executor: 'per-vu-iterations',
      vus: 1,
      iterations: '1',
      options: {
        browser: {
            type: 'chromium',
        },
      },
    },
  }
};

export default async function() {
  const context = browser.newContext();
  const page = context.newPage();
  try {
    await page.goto('https://test.k6.io', { waitUntil: 'networkidle' });
    context.setDefaultNavigationTimeout(0.1); // <---
    page.reload();
  } finally {
    page.close();
  }
}

I wish we had a better error message (concise and without the first execution context changed error) when the navigation timeout happens :) Current one:

WARN[0002] failed to hide page: evaluating JS: execution context changed; most likely because of a navigation  category="Page:Close" elapsed="0 ms" source=browser
ERRO[0002] Uncaught (in promise) GoError: reloading page: timed out
        at github.com/grafana/xk6-browser/browser.mapPage.func9 (native)
        at file:///Users/inanc/grafana/k6browser/tests/pr1034.js:24:4(27)  executor=per-vu-iterations scenario=ui

common/page.go Outdated Show resolved Hide resolved
Base automatically changed from fix/940-propagate-timeout to main September 18, 2023 10:19
@ankur22 ankur22 dismissed inancgumus’s stale review September 18, 2023 10:19

The base branch was changed.

These methods should work with the default navigation instead of the
default timeout to match the behaviour in Playwright.
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Remember to squash as there is a fix-up commit :)

@ankur22 ankur22 merged commit e3cda41 into main Sep 18, 2023
13 checks passed
@ankur22 ankur22 deleted the fix/use-navigation-timeout branch September 18, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants