Skip to content

Commit

Permalink
Add release notes for #3519
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Jan 16, 2024
1 parent 3429402 commit fd71921
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion release notes/v0.49.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,49 @@ The migration is straightforward. Just replace `k6/experimental/grpc` with `k6/n

### k6/html: Extract selection from element [#3519](https://github.com/grafana/k6/pull/3519)

// TODO fill with info
[`k6/html`](https://grafana.com/docs/k6/latest/javascript-api/k6-html/) has for been around for a while and allows you to search within an html document with an jquery-like API called [Selection](https://grafana.com/docs/k6/latest/javascript-api/k6-html/selection/), and also has support for the more standard [Element](https://grafana.com/docs/k6/latest/javascript-api/k6-html/element/) that represents DOM element.

For a long time you get an Element from a Selection using the [`.get(index)`](https://grafana.com/docs/k6/latest/javascript-api/k6-html/selection/selection-get/), but you couldn't get back to a Selection from an Element.

This happens to not be a common case, but one that in some cases requires rewrite of the code quite a lot.

```javascript
let li = http.get("https://test.k6.io").html().find("li");
li.each(function(_, element) {
// here element is an element not a selection
// but what if for each li we want to select something more?
// in jquery that will be:
let container = $(element).closest('ul.header-icons');
// but what should `$` do?
// in a browser there is only 1 html document that you have access to
// in k6 though you can be working with multiple ones, so `$` can't know which one it should
// work against
});
```

In order to support the above you can just use the selection, without going to element as in:

```javascript
let li = http.get("https://test.k6.io").html().find("li");
for (; li.size() > 0; li = li.next()) {
let ul = li.closest('ul.header-icons'); // li here is still a selection and we iterate over it.
}
```

This is not always possible though, and arguably isn't what most users will naturally do.

Because of this we have now added a new [`.selection()`](https://grafana.com/docs/k6/latest/javascript-api/k6-html/element/element-selection/) which returns a selection for it's element.


```javascript
let li = http.get("https://test.k6.io").html().find("li");
li.each(function(_, element) {
let container = element.selection().closest('ul.header-icons');
// .. more code
});
```

Thanks to @Azhovan! :bow: :tada:

### Collect usage data on imported internal modules and outputs [#3525](https://github.com/grafana/k6/pull/3525)

Expand Down

0 comments on commit fd71921

Please sign in to comment.