Skip to content

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

@ankur22

Description

@ankur22

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions