Skip to content
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

k6/browser does not able to handle multiple navigations when script click on a link or button #4048

Closed
jsaujla opened this issue Nov 11, 2024 · 1 comment · Fixed by grafana/xk6-browser#1534
Assignees

Comments

@jsaujla
Copy link

jsaujla commented Nov 11, 2024

Brief summary

k6/browser does not able to handle multiple navigations when script click on a link or button

k6 version

k6.exe v0.54.0

OS

Windows

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Below is an example of use case:

GIVEN I launched 'www.abc.com' (suppose there is a link (About Us) on the page)
WHEN I click on 'About Us' link (the application navigates to 'www.abc.com/callback', then navigates to 'www.abc.com/aboutus')
WHEN I tried to click on an element on 'aboutus' page OR I tried to verify element visibility on aboutus page

Expected behaviour

THEN script should waitForSelector visible state, regardless of any change/redirect happen in application under test URLs.

Actual behaviour

THEN The test failed with below error(s)
ERRO[0018] Uncaught (in promise) clicking on "#locator-id": Inspected target navigated or closed executor=shared-iterations scenario=ui
ERRO[0019] Uncaught (in promise) waiting for selector "#locator-id": Cannot find context with specified id executor=shared-iterations scenario=ui

Example of script is as below

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();

  try {
    await page.goto('app-url'); //please find/create a website which would change the url at least 2 times when nevigation (from one to another page) happen
    await page.locator('#login').type('username');
    await page.locator('#password').type("password");
    await page.locator('#button').click(),
    await page.waitForSelector('#username', { state: 'visible' });
  } finally {
    await page.close();
  }
}
@jsaujla jsaujla added the bug label Nov 11, 2024
@jsaujla jsaujla changed the title k6/browser does not able to handle multiple navigations with a single action k6/browser does not able to handle multiple navigations when I click on a link or button Nov 11, 2024
@jsaujla jsaujla changed the title k6/browser does not able to handle multiple navigations when I click on a link or button k6/browser does not able to handle multiple navigations when script click on a link or button Nov 11, 2024
@ankur22
Copy link
Contributor

ankur22 commented Nov 11, 2024

@jsaujla, thanks for filing this issue. I can replicate this issue.

We are about to release v0.55.0 of k6 (hopefully sometime this week), which contains a fix for locator.waitFor. With that you should have better luck at waiting for elements during a navigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants