grafana / xk6-browser

k6 extension that adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol
https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/browser/
GNU Affero General Public License v3.0
337 stars 42 forks source link

Support custom tags in page.goto() and other relevant methods #504

Open mdcruz opened 2 years ago

mdcruz commented 2 years ago

Currently, we have the ability to support custom tags in k6 core when using http.get() or http.post(). This allows us to customise reports, thresholds or other use cases. See the below code snippet for reference.

http.get('https://test.k6.io/contacts.php', {
    tags: { my_custom_tag: 'contacts' },
  });

This is currently not supported in xk6-browser specific methods such as page.goto(). I have a use case where I want to specify different thresholds per pages and the easiest way is to use tags like the one below:

export const options = {
  ...
  thresholds: {
    'browser_dom_content_loaded{customTag:messages}': ['p(90) < 1000'],
    'browser_dom_content_loaded{customTag:news}': ['p(90) < 800'],
    browser_first_contentful_paint: ['max < 1000']
  }
};

export function messages() {
 /// some other code

  page.goto('https://test.k6.io/my_messages.php', {
    // This custom tag doesn't work as expected
    tags: { customTag: 'messages' },
    waitUntil: 'networkidle'
  })
} 

There are other ways of course to specify different thresholds such as filtering it by default tags such as url or the name metric but it would still be nice to support custom tags going forward.

Resources

### Tasks
- [ ] Support [user defined](https://grafana.com/docs/k6/latest/using-k6/tags-and-groups/#user-defined-tags) tags in browser APIs as a new option field.
- [ ] Ensure [test-wide](https://grafana.com/docs/k6/latest/using-k6/tags-and-groups/#test-wide-tags) tags is supported by the browser module.
- [ ] Ensure [code defined](https://grafana.com/docs/k6/latest/using-k6/tags-and-groups/#code-defined-tags) tags is supported by the browser module.
- [ ] Ensure [tagged stages](https://grafana.com/docs/k6/latest/using-k6/tags-and-groups/#tagging-stages) works with the browser module.
- [ ] Define and support [system tags](https://grafana.com/docs/k6/latest/using-k6/tags-and-groups/#system-tags).
fatmaozcelik commented 10 months ago

Hi @imiric, it would be really nice to have such improvement. I also saw that it is confusing and difficult to deal with name metrics etc. Is there any decision made or progress on this issue? Thanks for your answer.