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

First element (0) of pages from BrowserContext is undefined but the second element (1) is correctly defined #444

Open
ankur22 opened this issue Jul 7, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ankur22
Copy link
Collaborator

ankur22 commented Jul 7, 2022

Tested against: dbede12

It seems that the array does not start at index 0, and instead starts at index 1. In PW it correctly starts at 0. I think there's an underlying issue which is causing that should be fixed.

NOTE: In the code below it works against localhost:8080, which is a test server. It can be found in the following link along with Instructions on how to run it locally: https://github.com/ankur22/testserver.

Script:

import { sleep } from 'k6';
import launcher from 'k6/x/browser';

export default function () {
  const browser = launcher.launch('chromium', {
      headless: false,
  });
  const context = browser.newContext();
  context.newPage();
  const pages = context.pages();
  const res = pages[0].goto('http://localhost:8080/unprotected');

  sleep(10);
  browser.close();
}

PW script:

// @ts-check
const { test, chromium } = require('@playwright/test');

test.describe('Editing', () => {
  test('Type login creds', async () => {
    const browser = await chromium.launch({ headless: false, slowMo: 500 });
    const ctx = await browser.newContext();
    await ctx.newPage();
    const pages = ctx.pages();
    await pages[0].goto('http://localhost:8080/unprotected');

    await new Promise(resolve => setTimeout(resolve, 10000));

    await browser.close();
  });
});
@ankur22
Copy link
Collaborator Author

ankur22 commented May 15, 2024

I found another issue when working on a fix for #827. It seems that pages on browserContext will not guarantee that the 0th page will be the first page the test opened. In the test i'm writing in #1334 i've had to account for this unexpected behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant