Skip to content

Conversation

@AgnesToulet
Copy link
Contributor

What?

This PR adds the following functions in the locator API documentation:

  • evaluate(pageFunction, arg)
  • evaluateHandle(pageFunction, arg)

Checklist

  • I have used a meaningful title for the PR.
  • I have described the changes I've made in the "What?" section above.
  • I have performed a self-review of my changes.
  • I have run the npm start command locally and verified that the changes look good.

Related PR(s)/Issue(s)

Implementation PR: grafana/k6#5306

@AgnesToulet AgnesToulet requested review from a team and heitortsergent as code owners October 17, 2025 08:43
@AgnesToulet AgnesToulet requested review from mstoykov and oleiade and removed request for a team October 17, 2025 08:43
@github-actions
Copy link
Contributor

Copy link
Contributor

@oleiade oleiade left a comment

Choose a reason for hiding this comment

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

Left a couple of non-blocking comment. Feel free to dismiss them if I missed an important context piece 🙇🏻


# evaluate(pageFunction[, arg])

Returns the value of the `pageFunction` invocation. It passes the matching element of the locator as the first argument to the `pageFunction` and arg as a second argument.
Copy link
Contributor

Choose a reason for hiding this comment

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

This information is super valuable, but felt really dry as I read it first. I suggest starting it with a high level overview of what this API will do for the user.

I see Playwright describes their evaluate method as "Execute JavaScript code in the page, taking the matching element as an argument.", which, from a user perspective answers the first question I had immediately: what is this API gonna do for me.

They only mention the pageFunction, what it does and how to use it later in a "details" section.

What do you think of:

Suggested change
Returns the value of the `pageFunction` invocation. It passes the matching element of the locator as the first argument to the `pageFunction` and arg as a second argument.
Execute JavaScript code in the page, taking the matching element as an argument.
Returns the value of the `pageFunction` invocation. It passes the matching element of the locator as the first argument to the `pageFunction` and arg as a second argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must admit I mostly copy/pasted the existing doc from other classes (as this function was already implemented in several places).
But it makes sense, I would rather suggest something like:

Suggested change
Returns the value of the `pageFunction` invocation. It passes the matching element of the locator as the first argument to the `pageFunction` and arg as a second argument.
Executes JavaScript code in the page, passing the matching element of the locator as the first argument to the `pageFunction` and arg as a second argument. It returns the value of the `pageFunction` invocation.

WDYT @ankur22? If we agree on a function description, I'll update it in all pages and not only here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, thanks for this! the updated wording LGTM 🚀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the update to all pages 👍

@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2025

💻 Deploy preview available (browser: add locator.evaluate and evaluateHandle):

Copy link
Contributor

@ankur22 ankur22 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
Collaborator

@heitortsergent heitortsergent left a comment

Choose a reason for hiding this comment

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

Left some minor nit suggestions, overall it looks great! 🙇

@heitortsergent heitortsergent self-assigned this Oct 30, 2025
@heitortsergent heitortsergent added the Area: browser The browser module label Oct 30, 2025
@heitortsergent
Copy link
Collaborator

heitortsergent commented Oct 30, 2025

This is unrelated to the changes in the PR, but seems like the Run code blocks workflow is failing on page/evaluate.md due to a wrong import.

Looks like we need to change the line 2:

import { check } from 'k6/http';

To:

import { check } from 'k6';

AgnesToulet and others added 2 commits November 3, 2025 09:50
Co-authored-by: Heitor Tashiro Sergent <heitortsergent@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: browser The browser module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants