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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

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: 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)

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".
@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.

It relies on a react based website.
@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

@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.

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.

3 participants