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

Update JS examples (add catch) #814

Open
inancgumus opened this issue Mar 7, 2023 · 0 comments
Open

Update JS examples (add catch) #814

inancgumus opened this issue Mar 7, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation ux

Comments

@inancgumus
Copy link
Member

inancgumus commented Mar 7, 2023

We want to add catch blocks to our examples to introduce better examples for our users.

There is also another problem.

  • In the following script, p.$ fails (I've changed the extension code to do so).
  • However, we never catch that panic since it's in a try block—it swallows the panic.
  • Then page.close panics since "p.$ panicked and shut down the browser already".
  • So we receive only the page.close's panic even if p.$ says something like "I could not find the selector something."
import { check } from 'k6';
import { chromium } from 'k6/x/browser';

export const options = {
  thresholds: {
    checks: ["rate==1.0"]
  }
}

export default async function() {
  const browser = chromium.launch({
    headless: __ENV.XK6_HEADLESS ? true : false,
  });
  const context = browser.newContext();
  const page = context.newPage();

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

    check(page, {
      'Title with CSS selector':
        p => {
          console.log('checking page textcontext');
          return p.$('header h1.titlex').textContent() == 'test.k6.io'
        },
    });
  } finally {
    page.close();
    browser.close();
  }
}

Related: #590, #697

@inancgumus inancgumus added documentation Improvements or additions to documentation ux labels Mar 7, 2023
@inancgumus inancgumus added this to the v0.9.0 milestone Mar 7, 2023
@inancgumus inancgumus self-assigned this Mar 7, 2023
@inancgumus inancgumus removed their assignment Mar 31, 2023
@inancgumus inancgumus removed this from the v0.9.0 milestone Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation ux
Projects
None yet
Development

No branches or pull requests

1 participant