question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Intermittent Issue where fixture is not returning unique data

See original GitHub issue

Context:

  • Playwright Version: 1.26.1
  • Operating System: Mac
  • Node.js version: v16.15.0
  • Browser: N/A
  • Extra: MacBook Pro M1 Pro

System:

  • OS: macOS 13.0
  • Memory: 576.33 MB / 32.00 GB

Binaries:

  • Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
  • Yarn: 1.22.19 - /opt/homebrew/bin/yarn
  • npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm

Languages:

  • Bash: 3.2.57 - /bin/bash

Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:

FIXTURE

import { test as base } from '@playwright/test';
import { faker } from '@faker-js/faker';

type Email = {
  email: string;
};

export const test = base.extend<{}, { email: Email }>({
  email: [async ({ browser }, use, workerInfo) => {
    const email = faker.internet.exampleEmail();
    await use({ email });
  }, { scope: 'worker' }],

});

export default test;
export const expect = test.expect;

TEST

import test, { expect } from '../../fixtures/testFixture';

test.describe.configure({ mode: 'parallel' });

test('Test One', async ({email}) => {
  console.log(email.email);
});

test('Test Two', async ({email}) => {
  console.log(email.email);
});

OUTPUT

Running 2 tests using 2 workers
Mitchel_Senger89@example.org
·Mitchel_Senger89@example.org
·

  2 passed (1s)
➜  play-on-e2e npm run test

> play-on-e2e@1.0.0 test
> npx playwright test


Running 2 tests using 2 workers
Keeley_Veum68@example.org
Lois15@example.com
··

Describe the bug This example is a simplified version of the real issue I am facing in my actual e2e test project. I am using faker to generate fake data and passing this through to the test. The tests are running in parallel when this issue occurs. As you can see from the output where I print the fake email address on the first run the emails are the same but on the 2nd run the emails are unique.

I believe that the desired behaviour is the emails being unique. I would expect this because they run on separate workers. At the very least I would expect the results to be consistent.

Please can you look into it for me?

Add any other details about the problem here.

The reason this is an issue in my real tests is firebase is returning a 400 for 1 of the 2 requests when creating a user as they have to have unique email addresses.

It passes on some occasions which explains the intermittent behaviour.

fixture_test_ts_—_play-on-e2e

Hope this helps. Thanks

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
costag1982commented, Oct 11, 2022

I have found a solution where I generate a random number to pass into the faker seed

import { test as base } from '@playwright/test';
import { faker } from '@faker-js/faker';

const randomIntFromInterval = (min: number, max: number): number => {
  return Math.floor(Math.random() * (max - min + 1) + min)
}

type Email = {
  email: string;
};

export const test = base.extend<{}, { email: Email }>({
  email: [async ({ browser }, use, workerInfo) => {
    const randomNum = randomIntFromInterval(0, 10000);
    faker.seed(randomNum);
    const email = faker.internet.exampleEmail();
    await use({ email });
  }, { scope: 'worker' }],

});

export default test;
export const expect = test.expect;

This seems to return unique emails now every time

> npx playwright test


Running 2 tests using 2 workers
{ email: 'Ray.Lind30@example.net' }
·{ email: 'Ashleigh79@example.com' }
·

  2 passed (3s)
➜  play-on-e2e 

Once again thanks for your help

0reactions
pavelfeldmancommented, Oct 12, 2022

Closing as per above, please feel free to open a new issue if this does not cover your use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intermittent unit test failures in sqlAlchemy due to database not ...
I have a collection of unit tests that run in a gitlab pipeline. The following code is meant to rebuild the database between...
Read more >
Why does Postgres generate an already used PK value?
It can be either a sequence feeding the values to the PK set to the wrong position and the table already containing the...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
This is the browser trying to be robust and retrying a failed network request. The browser sees a network error coming back from...
Read more >
87598: SELECT DISTINCT doesn't return result with "Using ...
Bug #87598, SELECT DISTINCT doesn't return result with "Using index ... Test data: mysql> use test; mysql> create table t1(a int not null ......
Read more >
6 Common Wire Connection Problems and Their Solutions
Electrical connection problems may be prevalent around your home. Here are some of the most common ones and how to fix them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found