k6 icon indicating copy to clipboard operation
k6 copied to clipboard

feat(browser): add ElementHandle.isInViewport method

Open Ashish050488 opened this issue 6 months ago • 5 comments

Implements the isInViewport method and adds a corresponding test case. Resolves #4423

What?

This PR adds the ElementHandle.isInViewport() method. This new method allows users to check if an element is currently visible within the browser's viewport by executing a script on the element.

A new test, TestFrameElementIsInViewport, has also been added to frame_test.go to validate this functionality.

Why?

This feature was requested in issue #4423 to enable more robust testing for in-page navigations, specifically to confirm that an element has been scrolled into view. This adds functionality similar to what is available in other browser automation libraries.

Checklist

  • [x] I have performed a self-review of my code.
  • [x] I have commented on my code, particularly in hard-to-understand areas.
  • [x] I have added tests for my changes.
  • [] I have run linter and tests locally (make check) and all pass.
    • Note: I was unable to run the full test suite on my Windows machine due to an existing issue (TestTmpDirCleanup failure). However, I successfully ran my new test (TestFrameElementIsInViewport) in isolation before discovering the test suite issue on Windows.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • [ ] I have added the correct milestone and labels to the PR.
  • [ ] I have updated the release notes: link
  • [ ] I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • [ ] I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Ashish050488 avatar Oct 13 '25 11:10 Ashish050488

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 13 '25 11:10 CLAassistant

@Ashish050488 We'll release k6 1.4.0 in two weeks. Please continue working on this PR if you want it merged into k6 1.4.0. Otherwise, we'll have to postpone merging your PR until k6 1.5.0.

inancgumus avatar Oct 28 '25 16:10 inancgumus

sorry for the delay i was stuck with something now i am active i did the changes asked for do provide feedback if changes required

Ashish050488 avatar Oct 31 '25 05:10 Ashish050488

i am trying but i dont know why those test fail can you give me help a little like where am i going wrong i would really appreaciate if you teach me

Ashish050488 avatar Nov 03 '25 11:11 Ashish050488

Hi @Ashish050488, you can run goimports to fix the "imported but not used" issue: Error: internal/js/modules/k6/browser/common/locator.go:9:2: "github.com/grafana/sobek" imported and not used.

inancgumus avatar Nov 03 '25 19:11 inancgumus