Skip to content

Fix fill method in injection script #4809

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

Merged
merged 3 commits into from
Jun 9, 2025
Merged

Fix fill method in injection script #4809

merged 3 commits into from
Jun 9, 2025

Conversation

ankur22
Copy link
Contributor

@ankur22 ankur22 commented May 22, 2025

What?

Preventing an early exit in the fill method in the injection script to actually allow the keyboard to enter the value into the input element.

Why?

This fill function was failing to fill the input text field. It would seem that it was returning to early, when it should have continued onto the end of the function and returned "needsinput".

Test script

Without the fix this script was unable to enter the username in the input element. After the fix it does:

import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: "chromium",
        },
      },
    },
  }
}

export default async function() {
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('https://grafana.com/auth/sign-in');
  
  await page.locator('input[name="login"]').fill('my-username');

  await page.waitForTimeout(5000);
}

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

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: 451213a
  • 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)

@ankur22 ankur22 requested a review from a team as a code owner May 22, 2025 22:54
@ankur22 ankur22 requested review from mstoykov and joanlopez and removed request for a team May 22, 2025 22:54
@joanlopez
Copy link
Contributor

Is this something that can be tested? Like, with a unit test, I mean 🤔

@ankur22
Copy link
Contributor Author

ankur22 commented May 23, 2025

Is this something that can be tested? Like, with a unit test, I mean 🤔

I did try, and i wasn't able to get it to not work before the fix! Very strange. I'll give it another go though 👍

@ankur22
Copy link
Contributor Author

ankur22 commented May 23, 2025

@joanlopez I've added an integration test in 9a35675. It fails without the fix and passes with the fix. Turned out to be an issue due how react works.

@ankur22 ankur22 force-pushed the fix/browser-input-fill branch from 9a35675 to 8700afc Compare May 23, 2025 20:23
Comment on lines 7 to 8
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

In general it is not great when our test depends on other services being up and running and we have tried to remove those.

#464 #2302

Copy link
Contributor

@joanlopez joanlopez May 26, 2025

Choose a reason for hiding this comment

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

I guess a "quick-win" could be copy-pasting these files locally, right? 🤔 So, this way we don't rely on an external server, to be available. Reproducing the issue (if React-specific) with a subset of the library might more challenging, tho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. I tried to isolate the changes from the react dependency files, but the work that needs to go into doing that outweighs the benefits IMO. I've just added the files that are needed as static files. The commit is 16a4550

Copy link
Contributor

@inancgumus inancgumus Jun 4, 2025

Choose a reason for hiding this comment

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

Instead of saving these scripts in the repository and bloating it, why don't we download them only once, right before the test starts, if the files don't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would still depend on a network connection, i guess we want to avoid that where possible. We're already vendoring our Go dependency, so i feel like this is good enough for now. Preferably it would be nice to only include the areas of the code that the test actually uses from the react library -- i tried manually (and using AI) to do this but it was taking too long so i abandoned it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't worry much about the network connection for one-time-download assets, especially if we put it onto one of our servers, like S3 or jslib.k6.io. Getting Go modules always involves a network anyway. That said, I'm fine with the current solution as well 🤗

mstoykov
mstoykov previously approved these changes May 25, 2025
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM, but it will be nice if we do not have to import 2 react dependancies from a third party to test this.

inancgumus
inancgumus previously approved these changes Jun 4, 2025
@ankur22 ankur22 requested a review from mstoykov June 5, 2025 08:11
@ankur22 ankur22 added this to the v1.1.0 milestone Jun 5, 2025
joanlopez
joanlopez previously approved these changes Jun 9, 2025
@ankur22 ankur22 dismissed stale reviews from joanlopez and inancgumus via 3c30e1f June 9, 2025 14:28
@ankur22 ankur22 requested review from joanlopez and inancgumus June 9, 2025 14:30
ankur22 added 3 commits June 9, 2025 22:26
This fill function was failing to fill the input text field. It would
seem that it was returning to early, when it should have continued onto
the end of the function and returned "needsinput".
It relies on a react based website.
@ankur22 ankur22 force-pushed the fix/browser-input-fill branch from 3c30e1f to a58835e Compare June 9, 2025 21:27
@ankur22 ankur22 merged commit c5b88f4 into master Jun 9, 2025
31 of 32 checks passed
@ankur22 ankur22 deleted the fix/browser-input-fill branch June 9, 2025 21:42
ankur22 added a commit that referenced this pull request Jun 17, 2025
joanlopez added a commit that referenced this pull request Jun 25, 2025
* Base release notes for v1.1.0

* Add release notes for dependabot PRs

* Add #4809 and #4831 into the v1.1.0 release note

* Add #4845 to the v1.1.0 release notes

* Add example for locator.count

* Remove await on expect in count example

* Add section for nth, first and count in v1.1.0...

... release notes.

* Update examples to work with latest test library

This also updates the nth, first and last example.

* Add some PRs from the beginning of the cycle into release notes

* Add external PRs, among others, to release notes

* Clean up stuff from release notes template

* Add remaining PRs into release notes

* Add #4862 to the v1.1.0 release note

* Apply suggestions from code review

Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com>

* Add #4864 to v1.1.0 release notes

* Remove #4862 from v1.1.0

* Apply suggestions from code review

Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>

* web/crypto updates

* Update release notes/v1.1.0.md

Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com>

* docs: document v1.1.0 forward roadmap

* Refine experimental modules notes

---------

Co-authored-by: ankur22 <ankur.agarwal@grafana.com>
Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com>
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Co-authored-by: oleiade <theo@crevon.me>
Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants